Low-Pass Digital Filtering From RapidSTM32
-
Upload
jackabraham -
Category
Documents
-
view
228 -
download
0
Transcript of Low-Pass Digital Filtering From RapidSTM32
-
8/13/2019 Low-Pass Digital Filtering From RapidSTM32
1/23
Low-Pass Digital Filtering
From RapidSTM32
Digital filter is performed by the mathematical operations that can be determined easily its characteristics,especially the sharpness of filter. Even though, infinite impulse response (IIR) digital filter have a sharper
transition region and low passband ripple. There is no requirement to use a high-order of IIR digital filters.
Therefore, IIR filters require much lower speed processor in practical implementation than another filters.
Furthermore, a common method is to design a high-order digital filter as a cascade series of second-order
subsystem, which is making them more stable.
RapidSTM32 lowpass digital filter block is the Simulink block which provides the same filter implementation as
a lowpass digital filter.
The usage is as follows:
To determine the coefficient values.1.To calculate automatically the coefficient of specific type of lowpass digital filter as
Butterworth filter1.
Chebyshev filter Type 12.
Chebyshev filter Type 23.
2.
Moreover, the RapidSTM32 lowpass digital filter block can support double-precision, single-precision and
integer number data types.
Contents1 Filter
2 Digital Filter
2.1 FIR Filter (Finite Impulse Response)
2.2 IIR Filter (Infinite Impulse Response)
3 IIR Filter
4 Types of Lowpass Filter
4.1 Butterworth filter
4.2 Chebyshev filter type 1
4.3 Chebyshev filter type 2
5 RapidSTM32 Lowpass Digital Filter Block5.1 Filter Type
5.2 Biquad Filter Order
5.3 Decibels of peak-to-peak ripple
5.4 Cut-off Frequency fc
5.5 Filter coefficients b0
5.6 Filter coefficients A (denominator)
5.7 Filter coefficients B (numerator)
5.8 Sampling time in [sec] (-1 for inherited)
5.9 Scale factor for coefficients [b0 A B]
Pass Digital Filtering - RapidSTM32 http://www.aimagin.com/learn/index.php/Low-Pass_Digital
3 2/12/2014
-
8/13/2019 Low-Pass Digital Filtering From RapidSTM32
2/23
5.10 Data type
5.11 View filter response and save coefficients [b A B] to .mat file
6 Experiments
6.1 Experiment based on Simulink
6.1.1 Experiment1: Lowpass filtering corrupted by a fixed frequency modulating noise
signal
6.1.2 Experiment2: Lowpass filtering corrupted by an adjustable frequency modulating
noise signal6.1.2.1 Spectrum analysis
6.1.2.2 Variable frequency
6.1.2.3 Simulation results
6.2 Experiment applied using RapidSTM32 Blockset
6.2.1 Filtering by RapidSTM32 Blockset
6.3 References
Filter
Filter is an important electronic device, which can change the amplitude and phase of signal in order to
attenuate and eliminate some unwanted signals, including to recover from the destroyed signals through filtering
In general, filters can be classified by frequency-domain characteristics
Figure 1.1 shows the frequency response John G. Proakis and Dimitris K. Manolakis, Digital Signal
Processing: Principle, Algorithms, and Applications, 3rd ed., Prentice Hall, New Jersey, 1996. and
transfer Function Richard G. Lyons, Understanding Digital Signal Processing, 2nd ed., Prentice Hall, New
Jersey, 2004. of lowpass filter, highpass filter, bandpass filter and stopband filter.
Figure 1.1: Frequency response of lowpass filter (LPF), highpass filter (HPF), bandpass filter
(BPF) and bandstop filter (BSF).
as follows:
Lowpass Filter (LPF)allows low frequency signal passed through.
Pass Digital Filtering - RapidSTM32 http://www.aimagin.com/learn/index.php/Low-Pass_Digital
3 2/12/2014
-
8/13/2019 Low-Pass Digital Filtering From RapidSTM32
3/23
Highpass Filter (HPF)allows high frequency signal passed through.
Bandpass Filter (BPF)allows frequency range signal passed through.
Bandstop Filter (BSF)does not allow frequency range signal passed through.
Some applications of filters are as follows: an analog to digital convertor (ADC) is using a lowpass filter to
eliminate signal contamination and to limit bandwidth range of signal. For example, in radio broadcast system,
bandpass filters are used to select the desirable frequency. In amplifier system, many types of filters are used to
separate the specific frequency signal sent through the speaker.
Furthermore, there are two major types of filters as:
Analog Filterthat is an electronic RLC-circuit operating on the continuous-time signal.
Digital Filteris performed either by an electronic RLC-circuit or functions in mathematics while
operating on the discrete-time signal.
Digital Filter
In comparison with analog filters, digital filters also tend to be more limited in cost, bandwidth and significant
implementation than analog filters. However, on the other hand, a digital filter performing by mathematical
operations that is characterised easily in requirement, especially sharpness, without changing the electroniccircuit. In the recent years, the limitation on hardware development has been reduced rapidly. Therefore, the
digital filters are useful in variety applications.
There are two categories of digital filters as follows.
FIR Filter (Finite Impulse Response)
A finite impulse response (FIR) filter whose impulse response is of finite duration. The operation is described by
the following equation.
Template:EquationRef1.1
where
is the output signal.
is the input signal.
is the period of sampling.
and are integer number. is the filter order.
are the filter coefficients.
The advantages are that FIR filters can be designed to have linear phase and inherently stable, because there is
no feedback. Furthermore, FIR filters have a tolerance to the coefficient quantisation errors and the quantisation
errors of the finite-precision arithmetic operations.
IIR Filter (Infinite Impulse Response)
An infinite impulse response (IIR) filters have infinite duration of impulse response, which is described by the
following equation below.
Pass Digital Filtering - RapidSTM32 http://www.aimagin.com/learn/index.php/Low-Pass_Digital
3 2/12/2014
-
8/13/2019 Low-Pass Digital Filtering From RapidSTM32
4/23
The advantages of IIR filters as compared with the same order of FIR filters are that IIR filters have more
sharpness with faster transition and lower passband ripple in frequency response than FIR filters. So, the lower
order IIR filters are used and required the lower speed processor in practical. In addition to, IIR filters can be
designed by a prototype analog filter.
IIR Filter
From Equation (1.2), the frequency response or system function of IIR filters are demonstrated in terms of thecomplex-valued z of z-transformation as follows.
On expanding Equation (1.3), we have
where
are zeros of system.
are pole of system.
We note that the zeros and poles are either real number or complex number.
is the filter order.
From Equation (1.3), we can group zeros and poles in forming the second-order subsystem as
Template:EquationRef1.5
Template:EquationRef1.6
Template:EquationRef1.7
where
, is the filter order and is even.
and is equal to , as shown in Equation (1.7).
A high-order IIR system can be factored into a cascade of second-order subsystem, called Cascade of
Second-order Subsystem. For example, the 6th-order lowpass filter consists of 3-cascade of second-order
subsystems as shown in Equation (1.8) below.
Template:EquationRef1.8
In case of the complex-valued coefficients, we can group together a pair of complex-conjugate zeros or poles toform a cascade of second-order subsystem. This implies that the coefficients are real.
It is possible to implement in practical. Consequently, the low-order digital filters can be designed easily due to
the tolerance in quantisation errors of its coefficients and the effects of finite-precision arithmetic that make
them more stable in the system.
Figure 1.2 (above) shows the cascade structure for each of second-order subsystems.
Pass Digital Filtering - RapidSTM32 http://www.aimagin.com/learn/index.php/Low-Pass_Digital
3 2/12/2014
-
8/13/2019 Low-Pass Digital Filtering From RapidSTM32
5/23
Figure 1.2: (above)Cascade structure of second-order subsystems and (below)
Block Diagram of each second-order subsystem.
Block diagram of second-order subsystem is shown in Figure 1.2 (below). The general form of each subsystem is
described by the following set of equations below.
Template:EquationRef1.9
Template:EquationRef1.10
Template:EquationRef1.11
Template:EquationRef1.12
Types of Lowpass Filter
According to digital filters described above, IIR filters may be designed based on a prototype analog filter with
many concerning theories. We introduce to modify the coefficients of a lowpass IIR filter using the block of
RapidSTM32 lowpass digital filter, including the Butterworth filter, Chebyshev filter Type 1 and Chebyshev
filter Type 2.
Butterworth filter
Buterworth filter is designed to have a flat frequency response and a linear phase response. Furthermore, a
maximally flat in the passband and roll-off towards zero in the stopband will require a high-order filter to
implement a particular stopband specification.
Pass Digital Filtering - RapidSTM32 http://www.aimagin.com/learn/index.php/Low-Pass_Digital
3 2/12/2014
-
8/13/2019 Low-Pass Digital Filtering From RapidSTM32
6/23
-
8/13/2019 Low-Pass Digital Filtering From RapidSTM32
7/23
Chebyshev filter type 2
Chebyshev filter type 2 is having a steeper roll-off and more stopband ripple than Butterworth filter.
Figure 1.5: Frequency response of 8th-order Chebyshev type 2 lowpass filter
RapidSTM32 Lowpass Digital Filter Block
Pass Digital Filtering - RapidSTM32 http://www.aimagin.com/learn/index.php/Low-Pass_Digital
3 2/12/2014
-
8/13/2019 Low-Pass Digital Filtering From RapidSTM32
8/23
Figure 2.1: shows the following parameters of the RapidSTM32 Lowpass Digital
Filter
RapidSTM32 lowpass digital filter block is developed as a digital lowpass filter shown in Figure 2.1 by the
following parameters.
Filter Type
To specify the type of filter. Choose one of the following option as.
butterworth: Butterworth Low-Pass Filter.
cheby1: Chebyshev type 1 Low-Pass Filter.
cheby2: Chebyshev type 2 Low-Pass Filter.
custom: To enter the number of specified coefficients.
Biquad Filter Order
To select the th-order of biquad filter, where .
Note: You can select N when the specified filter type is as 'butterworth','cheby1', or 'cheby2'.
Decibels of peak-to-peak ripple
To determine the peak-to-peak ripple in dB in the passband when selecting 'cheby1'.
Pass Digital Filtering - RapidSTM32 http://www.aimagin.com/learn/index.php/Low-Pass_Digital
3 2/12/2014
-
8/13/2019 Low-Pass Digital Filtering From RapidSTM32
9/23
To determine the peak-to-peak ripple in dB in the stopband when selecting 'cheby2'.
Note: The option is enabled if Filter typewas selected for 'cheby1'and 'cheby2'.
Cut-off Frequency fc
To specify the cut-off frequency of lowpass filter.
ExampleIf , that means the sampling frequency is multiplied by , where .
Note: This option is enabled if Filter typewas selected for 'butterworth','cheby1', or 'cheby2'.
Filter coefficients b0
To specify the only one coefficient of , as shown in Equation (1.8). Note: This option is enabled if Filter type
was selected for 'custom'.
Filter coefficients A (denominator)
To specify the coefficient of , which is identical to selecting order multiplied by .
ExampleThe filter order is determined by . You use the necessary -cascade of second-order subsystems.
Therefore, you must enter the -set of each coefficients as the first set of -coefficient is for the first of
second-order subsystem, then the second set and third set are for the second and third of second-order
subsystems, respectively, as given in Equation (1.8). The number of all coefficients is entered between space
with no comma.
Note: This option is enabled if Filter typewas selected for 'custom'.
Filter coefficients B (numerator)
To specify the coefficient of , which is identical to selecting order multiplied by .
ExampleThe filter order is determined by . You use the necessary -cascade of second-order subsystems.
Therefore, you must enter the -set of each coefficients as the first set of -coefficient is for the first of
second-order subsystem, then the second set and third set are for the second and third of second-order
subsystems, respectively, as given in Equation (1.8). The number of all coefficients is entered between space
with no comma.
Note: This option is enabled if Filter typewas selected for 'custom'.
Sampling time in [sec] (-1 for inherited)
To determine the sampling period.
In case of -1, the sampling period is set to the specified value of previous block.
Scale factor for coefficients [b0 A B]
This option is enabled if Data typewas selected for 'int32'.
Because the coefficients of , and are less than , when calculation due to overflow using the integer number of
Pass Digital Filtering - RapidSTM32 http://www.aimagin.com/learn/index.php/Low-Pass_Digital
3 2/12/2014
-
8/13/2019 Low-Pass Digital Filtering From RapidSTM32
10/23
data type. It causes easily the quantisation errors. In order to increase the precision in the filter coefficients, it is
important to multiply by a constant. After that the result will be divided by a constant, when the calculation is
done.
Note: This option is enabled if Data typewas selected for 'int32'.
Data type
There are three choices as follows.
int32: To calculate using Integer Number.
single: To calculate using Float Number.
double: To calculate using Double Number, which is double-precision.
View filter response and save coefficients [b A B] to .mat file
To select one of the following options as.
no: Neither display nor save the coefficients.
yes: Either display the frequency response and transfer function or save the coefficients into
COEFFICIENTS.mat file.
Experiments
There are two experiments. The first experiment is based on Simulink, whose purpose is to understand the
concept and basic properties of lowpass digital filter. The second experiment is applied using RapidSTM32
Blockset.
Experiment based on Simulink
Experiment of lowpass filter based on Simulink consists of two experiments as: Experiment1 is a simple
experiment that generates a noise signal with one frequency and Experiment2 shows how to adjust the
frequency of noise signal and to display the signal in the frequency-domain using another more functions.
Experiment1: Lowpass filtering corrupted by a fixed frequency modulating noise signal
Pass Digital Filtering - RapidSTM32 http://www.aimagin.com/learn/index.php/Low-Pass_Digital
23 2/12/2014
-
8/13/2019 Low-Pass Digital Filtering From RapidSTM32
11/23
Figure 3.1: Block Diagram of Simulink Model
Experiment1 is a simple example to understand first how to filter the high-frequency signal using lowpass filter
by Simulink model, as shown in Figure (3.1).
Using the 2-set of Sine Wave block, we assume that
The first Sine Wave block [Block: Sine Wave 01]that generates a sinusoidal message signal. (This
signal can be generated using function sin) as given by:
1.
Meanwhile, the second Sine Wave block [Block: Sine Wave 02]which generates a sinusoidal noise
signal as follows:
2.
1.
A signal composed of a sum [Block: Add]of previous specified sinusoidal signals is sampled at a
frequency of mHz [Block: Zero-Order Hold].
2.
Because of round-off effect from calculation with integer number, it is necessary to multiply by a
constant; such as [: Gain1].
3.
A output signal is converted in form of integer number [: Data Conversion1].4.
All parameters in lpdf block as shown in Figure 2.1[Block: RapidSTM32 Lowpass Digital Filter]arespecified.
5.
The filtered signal is converted to double-precision data type [Block: Data Conversion2and then to
multiply by a constant given above; such as[Gain2].
6.
Comparison the input and output of lpdf block is simulated using Scope block [Block: Scope02].7.
Note: If selecting Data Typewith 'double'and 'single', there is no need to do Step 3, 4 and 6.
Pass Digital Filtering - RapidSTM32 http://www.aimagin.com/learn/index.php/Low-Pass_Digital
23 2/12/2014
-
8/13/2019 Low-Pass Digital Filtering From RapidSTM32
12/23
Figure 3.2: Simulation result of Simulink Model
Simulation result shows in Figure 3.2, where Figure 3.2 (above) depicts the input signal consists of the message
signal and noise signal. Figure 3.2 (below) illustrates the output signal from lowpass digital filter similar to the
input sinusoidal signal. It is noted that the noise signal can be eliminated compared with the input signal.
However, the lowpass filtering does not work properly during the initial time.
Next experiments, it can adjust the parameters of lpdf block in requirement.
Experiment2: Lowpass filtering corrupted by an adjustable frequency modulating noise
signal
Figure 3.3: Block Diagram of Simulink Model
Pass Digital Filtering - RapidSTM32 http://www.aimagin.com/learn/index.php/Low-Pass_Digital
23 2/12/2014
-
8/13/2019 Low-Pass Digital Filtering From RapidSTM32
13/23
(The red dotted frames inside show the necessary functions of Simulink Model and Matlab added as illustrated
in Figure 3.3.
Spectrum analysis
Spectrum analysis is to compute and display the spectral density of signal that is a Spectrum Scope block in
Toolbox Signal Processing. It is necessary to create the new block using the function 'spectrumscop.m'; by Scott
Hirsch, that can download from
http://www.mathworks.com/matlabcentral/fileexchange/4539-spectrum-scope
Spectrum analysis consists of two main parts as follows.
1. The Function:bufferin Block:Embedded MATLAB Function 01is used to shape the group of magnitude
of signal in form of vector in order to convert by Fourier transform using the function 'fft.m', as shown below.
function w = buffer(u,v)
buffer_size = 256;
w = zeros(buffer_size,1);
w(1,1) = v;
for i = [2:buffer_size]w(i,1) = u(i-1,1);
end
2. The Function:SpectrumScopein Block:Embedded MATLAB Function 02that refers the function
'spectrumscop.m', which is in the same folder with Simulink Model, as shown below.
function y = SpectrumScope(u)
eml.extrinsic('spectrumscope');
Fs = 1000;
nFFT = 256;
spectrumscope(Fs,nFFT);
spectrumscope(u);
y = 0;
end
Variable frequency
Figure 3.4 shows how to adjust the frequency using the slider and function 'slider.m'. These files are in the same
folder with Simulink Model.
Pass Digital Filtering - RapidSTM32 http://www.aimagin.com/learn/index.php/Low-Pass_Digital
23 2/12/2014
-
8/13/2019 Low-Pass Digital Filtering From RapidSTM32
14/23
Figure 3.4: The window of slider
Using the function 'slider.m', it is determined which block is controlled by the slider. For this experiment, the
block Block:Sine Wave 02is adjusted by the slider. To specify below
'Test_lpdf_Simulink_02/Sine Wave 02','Frequency'
in the subfunction of 'slider.m ' as follows.
function sld_Callback(hObject, eventdata, handles)% hObject handle to sld (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.edtCurrent,'String',num2str(get(hObject,'Value')));
set_param('Test_lpdf_Simulink_02/Sine Wave 02','Frequency',get(handles.edtCurrent,'String'))
.
.
.
function edtCurrent_Callback(hObject, eventdata, handles)
% hObject handle to edtCurrent (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edtCurrent as text
% str2double(get(hObject,'String')) returns contents of edtCurrent as a double
set(handles.sld,'Value',str2double(get(hObject,'String')));
set_param('Test_lpdf_Simulink_02/Sine Wave 02','Frequency',get(handles.edtCurrent,'String'))
.
.
.
In addition to click at 'Launch Model Explorer', as shown in Figure 3.5. To click at 'Callbacks' in 'Model
Properties' and to select at 'InitFcn'. After that, to type 'slider' in the frame 'Model initialization function' which
determines to recall either 'Start Simulation' or 'slider.m'.
Pass Digital Filtering - RapidSTM32 http://www.aimagin.com/learn/index.php/Low-Pass_Digital
23 2/12/2014
-
8/13/2019 Low-Pass Digital Filtering From RapidSTM32
15/23
-
8/13/2019 Low-Pass Digital Filtering From RapidSTM32
16/23
Figure 3.6: Simulation results of Simulink Model, the windows of adjustable slider and the plot of s
The window of slider in the left-hand side shows that can adjust the frequency of Block:Sine Wave 02. The
window of Figure 1 in the right-hand side shows the spectrum of input signal which composed of a sum of two
sinusoidal signals at two different frequency (See the detail in Figure 1 at the peak of spectrum of signal.)
Furthermore, the signal from the adjustable waveform generator is similar to the noise signal. If it consists of the
high frequency, it will be eliminated.
And the spectrum of the output signal can be displayed by adjusting at 'Manual Switch'.
Experiment applied using RapidSTM32 Blockset
Filtering by RapidSTM32 Blockset
Pass Digital Filtering - RapidSTM32 http://www.aimagin.com/learn/index.php/Low-Pass_Digital
23 2/12/2014
-
8/13/2019 Low-Pass Digital Filtering From RapidSTM32
17/23
Figure 3.7: Block Diagram of Simulink Model applied using RapidS
The second experiment is applied using RapidSTM32 Blockset. First, to create 'Simulink Block' shown in Figure
3.7 as follows.
Block: Setup System Clocks & SysTick, to choose the parameter 'SYSCLK setting' with Defaultas
shown in Figure 3.8.
1.
Pass Digital Filtering - RapidSTM32 http://www.aimagin.com/learn/index.php/Low-Pass_Digital
23 2/12/2014
-
8/13/2019 Low-Pass Digital Filtering From RapidSTM32
18/23
Figure 3.8: All parameters determined in 'Setup System Clocks &Systick'
Block: Compile and Download Control, to set parameters as given in Figure 3.9.2.
Pass Digital Filtering - RapidSTM32 http://www.aimagin.com/learn/index.php/Low-Pass_Digital
23 2/12/2014
-
8/13/2019 Low-Pass Digital Filtering From RapidSTM32
19/23
Figure 3.9: All parameters specified in 'Compile and DownloadControl'
Block: ADC Configuration, to set parameters for converting the analog signal to digital signal and to
select the -th input channel, as shown in Figure 3.10.
3.
Pass Digital Filtering - RapidSTM32 http://www.aimagin.com/learn/index.php/Low-Pass_Digital
23 2/12/2014
-
8/13/2019 Low-Pass Digital Filtering From RapidSTM32
20/23
Figure 3.10: All parameters given in 'ADC Configuration'
Because of computation by integer number data type, Block: Data Conversion1, Gain1, DataConversion2 and Gain2are used the same condition with the experiment in Section 3.1. And if selecting
'Data Type' with doubleand single, it is not necessary to use these blocks.
4.
To specify all parameters in 'Block: lpdf Block, as given in Figure 2.1.5.
Block: DAC Configuration, to set the parameters for converting the digital signal to analog signal and to
select the -th output channel as shown in Figure 3.11.
6.
Pass Digital Filtering - RapidSTM32 http://www.aimagin.com/learn/index.php/Low-Pass_Digital
23 2/12/2014
-
8/13/2019 Low-Pass Digital Filtering From RapidSTM32
21/23
Figure 3.11: All parameters determined in 'DAC Configuration'
Next step is to update diagram twice and to build model for transforming the Simulink Model to
C-Language program and then download into 'RapidSTM32 Blockset'.
7.
To install all measurements that consist of the Function Generator, Oscilloscope and 'RapidSTM32
Blockset' as shown in Figure 3.1 and to connect all pins of 'RapidSTM32 Blockset', as shown in Figure
3.12 and 3.13.
8.
Pass Digital Filtering - RapidSTM32 http://www.aimagin.com/learn/index.php/Low-Pass_Digital
23 2/12/2014
-
8/13/2019 Low-Pass Digital Filtering From RapidSTM32
22/23
Figure 3.12: RapidSTM32 Blockset shown the position of input and output signals
Figure 3.13: Measurement installation for experiment
Pass Digital Filtering - RapidSTM32 http://www.aimagin.com/learn/index.php/Low-Pass_Digital
23 2/12/2014
-
8/13/2019 Low-Pass Digital Filtering From RapidSTM32
23/23
Figure 3.14 shows the simulation result that input signal composed of message signal and noise signal as shown
in 'CH1' (channel1) of Oscilloscope and in 'CH2' (channel2) of Oscilloscope, it is illustrated the output signal of
filter that is similar to the message sinusoidal signal without noise in the experiment based on Simulink, as shown
in Figure 3.2. It is noted that noise signal can be eliminated.
Figure 3.14: Simulation result from Oscilloscope
References
This page was last modified on 22 September 2011, at 07:00.
This page has been accessed 50,381 times.
Privacy policy
About RapidSTM32
Disclaimers
Pass Digital Filtering - RapidSTM32 http://www.aimagin.com/learn/index.php/Low-Pass_Digital