digital filter design using matlab · digital filter design using matlab dr. tony jacob department...
TRANSCRIPT
Digital Filter Design using MATLAB
Dr. Tony Jacob
Department of Electronics and Electrical EngineeringIndian Institute of Technology Guwahati
April 11, 2015
Dr. Tony Jacob IIT Guwahati April 11, 2015 1 / 30
Outline of the Talk
Review of LTI Systems
Filter Specifications
Linear Phase FIR Filters
FIR Filter Design
Hands on MATLAB Session
Dr. Tony Jacob IIT Guwahati April 11, 2015 2 / 30
What is an LTI System?
Dr. Tony Jacob IIT Guwahati April 11, 2015 3 / 30
Impulse Response Description: Convolution
Dr. Tony Jacob IIT Guwahati April 11, 2015 4 / 30
Transform Domain Description: Fourier Transform
Dr. Tony Jacob IIT Guwahati April 11, 2015 5 / 30
Transform Domain Description: Fourier Transform
Dr. Tony Jacob IIT Guwahati April 11, 2015 6 / 30
Transform Domain Description: z Transform
Dr. Tony Jacob IIT Guwahati April 11, 2015 7 / 30
Difference Equation Description
Dr. Tony Jacob IIT Guwahati April 11, 2015 8 / 30
Conversion between Descriptions
Dr. Tony Jacob IIT Guwahati April 11, 2015 9 / 30
Properties of LTI Systems
Dr. Tony Jacob IIT Guwahati April 11, 2015 10 / 30
What is a Filter?
An LTI system processes a signal x [n] by amplifying or attenuatingthe sinusoids in its Fourier representation (DTFT) X (e jω) by thecomplex factor H(e jω).
This inspires the terminology that X (e jω) is filtered by H(e jω) toproduce Y (e jω).
Dr. Tony Jacob IIT Guwahati April 11, 2015 11 / 30
Ideal Filters
Categories of Ideal Filters
Ideal Low Pass Filters
Ideal High Pass Filters
Ideal Band Pass Filters
Ideal Band Stop Filters
Dr. Tony Jacob IIT Guwahati April 11, 2015 12 / 30
Low Pass Filter Specifications
Dr. Tony Jacob IIT Guwahati April 11, 2015 13 / 30
Low Pass Filter Specifications
Dr. Tony Jacob IIT Guwahati April 11, 2015 14 / 30
Low Pass Filter Specifications
Dr. Tony Jacob IIT Guwahati April 11, 2015 15 / 30
FIR Filters: Linear Phase
Dr. Tony Jacob IIT Guwahati April 11, 2015 16 / 30
FIR Filters: Linear Phase
Dr. Tony Jacob IIT Guwahati April 11, 2015 17 / 30
Design Method 1: Windowing
Dr. Tony Jacob IIT Guwahati April 11, 2015 18 / 30
Design Method 1: Windowing
Dr. Tony Jacob IIT Guwahati April 11, 2015 19 / 30
Design Method 1: Windowing
Dr. Tony Jacob IIT Guwahati April 11, 2015 20 / 30
Design Method 1: Windowing
Dr. Tony Jacob IIT Guwahati April 11, 2015 21 / 30
Design Method 1: Windowing
Dr. Tony Jacob IIT Guwahati April 11, 2015 22 / 30
Design Method 1: Windowing
Dr. Tony Jacob IIT Guwahati April 11, 2015 23 / 30
Design Method 1: Windowing
Dr. Tony Jacob IIT Guwahati April 11, 2015 24 / 30
Design Method 1: Windowing
Dr. Tony Jacob IIT Guwahati April 11, 2015 25 / 30
Design Method 1: Windowing
Dr. Tony Jacob IIT Guwahati April 11, 2015 26 / 30
Other Design Methods
Frequency Sampling
Optimal Equiripple Filters
Dr. Tony Jacob IIT Guwahati April 11, 2015 27 / 30
Exercises
Familiarize yourselves with the commands: boxcar, bartlett, hann,hamming, blackman, kaiser.
Design a digital FIR low pass filter with the following specifications:ωp = 0.2π, ωs = 0.3π, Rp = 0.25dB and As = 50dB. Try variouswindow functions for this pupose. Determine the impulse responseand provide a plot of the frequency response of the designed filter.
Familiarize yourselves with designfilt command.
Launch FDATool and FVTool and familiarize yourselves with theirfeatures.
Dr. Tony Jacob IIT Guwahati April 11, 2015 28 / 30
References
1 Vinay K. Ingle and John G. Proakis, “Digital Signal Processing UsingMATLAB”, 3rd Ed., Cengage Learning, 2012.
2 Alan V. Oppenheim and Ronald W. Schafer, “Discrete-Time SignalProcessing”, 3rd Ed., Pearson Education, 2010.
3 John G. Proakis and Dmitris K. Manolakis, “Digital SignalProcessing: Principles, Algorithms, and Applications”, 4th Ed.,Prentice Hall, 2006.
4 Dmitris K. Manolakis and Vinay K. Ingle, “Applied Digital SignalProcessing”, Cambridge University Press, 2011.
Dr. Tony Jacob IIT Guwahati April 11, 2015 29 / 30
Online Courses
1 Alan V. Oppenheim, 6.007 Signals and Systems, MIT OCW.
2 Alan V. Oppenheim, 6.008 Digital Signal Processing, MIT OCW.
3 Alan V. Oppenheim and Thomas A. Baran, 6.341x Discrete-TimeSignal Processing, edX.
4 Paolo Prandoni and Martin Vetterli, Digital Signal Processing,Coursera.
Dr. Tony Jacob IIT Guwahati April 11, 2015 30 / 30
Questions?
Dr. Tony Jacob IIT Guwahati April 11, 2015 31 / 30
Discrete Fourier transform (DFT).
>> ts = 0.0001 ; >> fs = 1/ts ; >> N = 30001 ; >> T = (N-1)*ts ; >> t = 0:ts:T; >> x = 2*sind(360* 2000* t); >> noise = 1*sind(360* 4000* t); >> SIG = x + noise + 1; >> FFT = fftshift(fft(SIG)); % fft finds DFT using FFT algorithm. % fftshift shifts the DTF to the scale –pi to pi >> f = (-fs/2) : (fs/ (N-1)) : (fs/2); >> figure;plot (f, (abs(FFT)).^2) >> PSD = FFT.*conj(FFT); >> figure;plot (f, PSD) TRY >> psd(SIG)
Discrete Fourier transform (DFT).
>> ts = 0.0001 ; >> fs = 1/ts ; >> N = 30001 ; >> T = (N-1)*ts ; >> t = 0:ts:T; >> x = 2*sind(360* 2000* t); >> noise = 1*sind(360* 4000* t); >> SIG = x + noise + 1; >> FFT = fftshift(fft(SIG)); % fft finds DFT using FFT algorithm. % fftshift shifts the DTF to the scale –pi to pi >> f = (-fs/2) : (fs/ (N-1)) : (fs/2); >> figure;plot (f, (abs(FFT)).^2) >> PSD = FFT.*conj(FFT); >> figure;plot (f, PSD) TRY >> psd(SIG)
Filters
• IIR Filters >> [ b, a ] = butter( N , fc , 'low') % N = Order , fc = filter cutoff frequency Note: fc is the normalised frequency in the range 0 – 1. If sampling frequency is
Fs, 1 is mapped to Fs/2. Choose ‘low’ ‘high’ ‘stop’ ‘pass’ accordingly. For ‘stop’ or ‘pass’ , fc = [ fc1 , fc2 ] upper & lower cutoff frequencies. Eg; >> [b , a] = butter (10 , 0.5 ,'low'); % for a lowpass filter >> [b, a] = butter ( 16, [ 0.5 , 0.8] ,‘stop’ ) % for a band stop filter. >> [N, fc] = buttord( fp, fs, Rp, Rs) % For finding optimal filter order. Note: Rp, Rs are the pass & stop band ripples in dB and for LPF: fp = .1, fs = .2 HPF: fp = .2, fs = .1 BPF: fp = [.2 .7], fs = [.1 .8] BSF: fp = [.1 .8], fs = [.2 .7] The above written format must be followed for your design
Filters
• IIR Filters Use cheby1, cheby2, ellip functions instead of ‘butter’ to meet your various
design requirements. >> Y = filter ( b, a, X); % to filter the data X ; Y receives the filtered data. a and b are digital filter coeffs generated by any of the
previously discussed filter functions. >> freqz ( b , a ) % plots Z domain frequency response >> [ H,W ] = freqz (b, a, N) % gives response in H and N point freq scale in W. >> freqs (b , a ) % plots S domain frequency response >> [ H,W ] = freqs (b, a, N) % gives response in H and N freq point scale in W. TRY >> fvtool ( b, a )
Filters
• FIR Filters • In FIR, it is possible to design filters of linear phase . That is group delay is a
constant. • Types of FIR filters.
Filters
• FIR Filters • How to find b0 , b1, b2 ,….. bN using Matlab ? >> b = fir1( N , Wn , ‘low’) % for an FIR lowpass filter Note: use ‘high’ , ‘stop’ , ‘bandpass’ as per requirement. N must be even for fir1( . ) . Matlab will show an error otherwise. Wn is the normalised frequency in range 0 – 1; 1 maps to Fs/2. Wn must be of the form [ W1 W2] for stop and pass filters. >>Y = filter ( b, 1, X); % to filter the data X ; Y receives the filtered data. ‘b’ is the digital filter coeffs generated by fir1 (.)
since there are no poles, ‘a’ is taken as 1.
Filters
• FIR Filters Choosing Windows in the design of FIR filters >> b = fir1( N , Wn , ‘low’, window) % specify the required window . Matlab uses hamming as the default window Note: Window along with its parameters need to be specified. Matlab provides the following windows bartlett - Bartlett window. barthannwin- Modified Bartlett-Hanning window. blackman- Blackman window. blackmanharris- Min 4-term Blackman-Harris bohmanwin- Bohman window. chebwin - Chebyshev window. flattopwin - Flat Top window. gausswin- Gaussian window. hamming - Hamming window. hann - Hann window. kaiser - Kaiser window. triang- Triangular window. parzenwin - Parzen window. rectwin - Rectangular window. taylorwin- Taylor window. tukeywin - Tukey window. nuttallwin- Nuttall defined min 4-term Blackman-Harris
Filters
• FIR Filters Choosing Windows in the design of FIR filters >> b = fir1( N , Wn , ‘low’, kaiser ( N+1, 4) ) % here beta of kaiser = 4. How to specify a window of your design ? How to caliberate one ? >> wintool % allows you to design your own windows. % also you can tune the available matlab windows. Note: The length of the window must be chosen carefully to match the length of
the filter ; other wise Matlab will give an error. >> b = fir1( N , Wn , ‘low’, yourWindow) % ‘yourWindow’ must be available
in the Workspace.
Filters
• FIR Filters Design FIR filters with desired frequency response >> b = fir2( N , F, A ) % F is the frequency sample points. % A is the corresponding amplitude at those freqs Note: vector in F must be normalised; first and last samples of the vector must be
0 and 1 respectively. For example : >> F = [0 : 1: 21] ; >> F = F ./ 21; % this is done for normalizing the vector F >> A = [0 : 1 : 10 ] ; >> A = [A, fliplr ( A ) ] ; >> b = fir2 (100 , F, A) ; >> fvtool ( b, 1 )
Filters
• Filters design tool for instant designing >> fdatool % allows user to quickly design or analyse a filter Note: Options are available for choosing all types of filters in both IIR and FIR categories. The designed filters can be exported to the workspace in various forms. For easy usage , the design can be ported as filter objects.
Let’s filter some real time data using the filters designed in Matlab.