LowPass Digital Filtering  RapidSTM32
http://www.aimagin.com/learn/index.php/LowPass_Digital_Filtering
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 highorde r 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 highorder digital filter as a cascade se ries of secondorder 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:
1. To determine the coefficient values.
2. To calculate automatically the coefficient of specific type of lowpass digital filter as
1. Butterworth filter
2. Chebyshev filter Type 1
3. Chebyshev filter Type 2
Moreover, the RapidSTM32 lowpass digital filter block can support doubleprecision, singleprecision and integer number data types.
Contents 

1 

2 


2.1 
FIR Filter (Finite Impulse Response) 

2.2 
IIR Filter (Infinite Impulse Response) 
3 

4 



4.1 
Butterworth filter 

4.2 
Chebyshev filter type 1 

4.3 
Chebyshev filter type 2 
5 


5.1 
Filter Type 

5.2 
Biquad Filter Order 

5.3 
Decibels of peaktopeak ripple 

5.4 
Cutoff 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] 
1 of 23
2/12/2014 7:33 AM
LowPass Digital Filtering  RapidSTM32
http://www.aimagin.com/learn/index.php/LowPass_Digital_Filtering






6 Experiments 




6.1.1 

signal 

6.1.2 

noise signal 


6.1.2.1 
Spectrum analysis 


6.1.2.2 
Variable frequency 


6.1.2.3 
Simulation results 




6.2.1 
Filtering by RapidSTM32 Blockset 



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 destroye d signals through filtering. In general, filters can be classified by frequencydomain characteristics
Figure 1.1 shows the frequency response <ref> John G. Proakis and Dimitris K. Manolakis, Digital Signal Processing: Principle, Algorithms, and Applications, 3rd ed., Prentice Hall, New Jersey, 1996. </ref> and transfer Function <ref> Richard G. Lyons, Understanding Digital Signal Processing, 2nd ed., Prentice Hall, New Jersey, 2004. </ref> of lowpass filter, highpass filter, bandpass filter and stopband filter.
as follows:
Lowpass Filter (LPF) allows low frequency signal passed through.
2 of 23
2/12/2014 7:33 AM
LowPass Digital Filtering  RapidSTM32
http://www.aimagin.com/learn/index.php/LowPass_Digital_Filtering
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 Filter that is an electronic RLCcircuit operating on the continuoustime signal.
Digital Filter is performed either by an electronic RLCcircuit or functions in mathematics while operating on the discretetime signal.
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 electronic circuit. 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.
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 inherent ly stable, because there is no feedback. Furthermore, FIR filters have a tolerance to the coefficient quantisation errors and the quantisation errors of the finiteprecision arithmetic operations.
An infinite impulse response (IIR) filters have infinite duration of impulse response , which is described by the following equation below.
3 of 23
2/12/2014 7:33 AM
LowPass Digital Filtering 
RapidSTM32
http://www.aimagin.com/learn/index.php/LowPass_Digital_Filtering
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.
From Equation (1.2), the frequency response or system function of IIR filters are demonstrated in terms of the complexvalued z of ztransformation 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 secondorder subsyst em 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 highorder IIR system can be factored into a cascade of secondorder subsystem, called “Cascade of Secondorder Subsystem”. For example, the 6thorder lowpass filter consists of 3casc ade of secondorder subsystems as shown in Equation (1.8) below.
Template:EquationRef1.8
In case of the complexvalued coefficients, we can group together a pair of complexc onjugate zeros or poles to form a cascade of secondorder subsystem. This implies that the coefficients are real. It is possible to implement in practical. Consequently, the loworder digital filters can be designed easily due to the tolerance in quantisation errors of its coefficients and the effects of finiteprecision arithmetic that make them more stable in the system.
Figure 1.2 (above) shows the cascade structure for each of secondorder subsystems.
4 of 23
2/12/2014 7:33 AM
LowPass Digital Filtering  RapidSTM32
http://www.aimagin.com/learn/index.php/LowPass_Digital_Filtering
Block diagram of secondorder 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
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.
Buterworth filter is designed to have a flat frequency response and a linear phase re sponse. Furthermore, a maximally flat in the passband and rolloff towards zero in the stopband will require a highorder filter to implement a particular stopband specification.
5 of 23
2/12/2014 7:33 AM
LowPass Digital Filtering  RapidSTM32
http://www.aimagin.com/learn/index.php/LowPass_Digital_Filtering
The frequency response of Chebyshev filter type 1 have a steeper rolloff and more passband ripple than Butterworth filter.
6 of 23
2/12/2014 7:33 AM
LowPass Digital Filtering  RapidSTM32
http://www.aimagin.com/learn/index.php/LowPass_Digital_Filtering
Chebyshev filter type 2 is having a steeper rolloff and more stopband ripple than Butterworth filter.
7 of 23
2/12/2014 7:33 AM
LowPass Digital Filtering  RapidSTM32
http://www.aimagin.com/learn/index.php/LowPass_Digital_Filtering
RapidSTM32 lowpass digital filter block is developed as a digital lowpass filter shown in Figure 2.1 by the following parameters.
To specify the type of filter. Choose one of the following option as.
butterworth: Butterworth LowPass Filter.
cheby1: Chebyshev type 1 LowPass Filter.
cheby2: Chebyshev type 2 LowPass Filter.
custom: To enter the number of specified coefficients.
To select the thorder of biquad filter, where . Note : You can select N when the specified filter type is as 'butterworth' ,'cheby1' , or 'cheby2' .
To determine the peaktopeak ripple in dB in the passband when selecting 'cheby1' .
8 of 23
2/12/2014 7:33 AM
LowPass Digital Filtering  RapidSTM32
http://www.aimagin.com/learn/index.php/LowPass_Digital_Filtering
To determine the peaktopeak ripple in dB in the stopband when selecting 'cheby2' . Note : The option is enabled if Filter type was selected for 'cheby1' and 'cheby2' .
To specify the cutoff frequency of lowpass filter.
Example If , that means the sampling frequency is multiplied by , where .
Note : This option is enabled if Filter type was selected for 'butterworth' ,'cheby1' , or 'cheby2' .
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' .
To specify the coefficient of , which is identical to selecting order multiplied by .
Example The filter order is determined by . You use the necessary cascade of secondorder subsystems. Therefore, you must enter the set of each coefficients as the first set of coefficient is for the first of secondorder subsystem, then the second set and third set are for the second and third of secondorder 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 type was selected for 'custom' .
To specify the coefficient of , which is identical to selecting order multiplied by .
Example The filter order is determined by . You use the necessary cascade of secondorder subsystems. Therefore, you must enter the set of each coefficients as the first set of coefficient is for the first of secondorder subsystem, then the second set and third set are for the second and third of secondorder 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 type was selected for 'custom' .
To determine the sampling period. In case of 1, the sampling period is set to the specified value of previous block.
This option is enabled if Data type was selected for 'int32'.
Because the coefficients of , and are less than , when calculation due to overflow using the integer number of
9 of 23
2/12/2014 7:33 AM
LowPass Digital Filtering  RapidSTM32
http://www.aimagin.com/learn/index.php/LowPass_Digital_Filtering
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 const ant, when the calculation is done.
Note : This option is enabled if Data type was selected for 'int32'.
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 doubleprecision.
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.
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 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 frequencydomain using another more functions.
10 of 23
2/12/2014 7:33 AM
LowPass Digital Filtering  RapidSTM32
http://www.aimagin.com/learn/index.php/LowPass_Digital_Filtering
Experiment1 is a simple example to understand first how to filter the highfrequency signal using lowpass filter by Simulink model, as shown in Figure (3.1).
1. Using the 2set of Sine Wave block, we assume that
1. 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:
2. Meanwhile, the second Sine Wave block [Block: Sine Wave 02] which generates a sinusoidal noise signal as follows:
2. A signal composed of a sum [Block: Add] of previous specified sinusoidal signals is sampled at a frequency of mHz [Block: ZeroOrder Hold].
3. Because of roundoff effect from calculation with integer number, it is necessary to multiply by a constant; such as [บล็อก: Gain1].
4. A output signal is converted in form of integer number [บล็อก: Data Conversion1].
5. All parameters in lpdf block as shown in Figure 2.1[Block: RapidSTM32 Lowpass Digital Filter] are specified.
6. The filtered signal is converted to doubleprecision data type [Block: Data Conversion2 and then to multiply by a constant given above; such as[Gain2].
7. Comparison the input and output of lpdf block is simulated using Scope block [Block: Scope02].
Note : If selecting Data Type with 'double' and 'single' , there is no need to do Step 3, 4 and 6.
11 of 23
2/12/2014 7:33 AM
LowPass Digital Filtering  RapidSTM32
http://www.aimagin.com/learn/index.php/LowPass_Digital_Filtering
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.
12 of 23
2/12/2014 7:33 AM
LowPass Digital Filtering  RapidSTM32
http://www.aimagin.com/learn/index.php/LowPass_Digital_Filtering
(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/4539spectrumscope
Spectrum analysis consists of two main parts as follows.
1. The Function:buffer in Block:Embedded MATLAB Function 01 is 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(i1,1); end
2. The Function:SpectrumScope in Block:Embedded MATLAB Function 02 that 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.
13 of 23
2/12/2014 7:33 AM
LowPass Digital Filtering  RapidSTM32
http://www.aimagin.com/learn/index.php/LowPass_Digital_Filtering
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 02 is 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,'St ring')) . . .
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,'St ring')) . . .
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'.
14 of 23
2/12/2014 7:33 AM
LowPass Digital Filtering  RapidSTM32
http://www.aimagin.com/learn/index.php/LowPass_Digital_Filtering
Figure 3.5: Setting parameters for the slider.
Simulation results
The simulation is starting when click 'Start Simulation' and all setting parameters a re correct, the result is shown in Figure 3.6.
15 of 23
2/12/2014 7:33 AM
LowPass Digital Filtering  RapidSTM32
http://www.aimagin.com/learn/index.php/LowPass_Digital_Filtering
The window of slider in the lefthand side shows that can adjust the frequency of Block:Sine Wave 02. The window of Figure 1 in the righthand 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'.
16 of 23
2/12/2014 7:33 AM
LowPass Digital Filtering  RapidSTM32
http://www.aimagin.com/learn/index.php/LowPass_Digital_Filtering
The second experiment is applied using RapidSTM32 Blockset. First, to create 'Simulink Block' shown in Figure 3.7 as follows.
1. Block: Setup System Clocks & SysTick, to choose the parameter 'SYSCLK setting' with Default as shown in Figure 3.8.
17 of 23
2/12/2014 7:33 AM
LowPass Digital Filtering  RapidSTM32
http://www.aimagin.com/learn/index.php/LowPass_Digital_Filtering
2. Block: Compile and Download Control , to set parameters as given in Figure 3.9.
18 of 23
2/12/2014 7:33 AM
LowPass Digital Filtering  RapidSTM32
http://www.aimagin.com/learn/index.php/LowPass_Digital_Filtering
3. 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.
19 of 23
2/12/2014 7:33 AM
LowPass Digital Filtering  RapidSTM32
http://www.aimagin.com/learn/index.php/LowPass_Digital_Filtering
4. Because of computation by integer number data type, Block: Data Conversion1, Gain1, Data Conversion2 and Gain2 are used the same condition with the experiment in Section 3.1. And if selecting 'Data Type' with double and single , it is not necessary to use these blocks.
5. To specify all parameters in 'Block: lpdf Block, as given in Figure 2.1.
6. 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.
20 of 23
2/12/2014 7:33 AM
LowPass Digital Filtering  RapidSTM32
http://www.aimagin.com/learn/index.php/LowPass_Digital_Filtering
7. Next step is to update diagram twice and to build model for transforming the Simulink Model to CLanguage program and then download into 'RapidSTM32 Blockset'.
8. 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.
21 of 23
2/12/2014 7:33 AM
LowPass Digital Filtering  RapidSTM32
http://www.aimagin.com/learn/index.php/LowPass_Digital_Filtering
22 of 23
2/12/2014 7:33 AM
LowPass Digital Filtering  RapidSTM32
http://www.aimagin.com/learn/index.php/LowPass_Digital_Filtering
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 experime nt based on Simulink, as shown in Figure 3.2. It is noted that noise signal can be eliminated.
<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
23 of 23
2/12/2014 7:33 AM
Viel mehr als nur Dokumente.
Entdecken, was Scribd alles zu bieten hat, inklusive Bücher und Hörbücher von großen Verlagen.
Jederzeit kündbar.