Digital FIR Filter Design: A. Windows Method
Digital FIR Filter Design: A. Windows Method
Digital FIR Filter Design: A. Windows Method
503456 Digital Signal Processing Lab (3) Spring 2008 Name -----------------------------------------------------------------------------------
where filter type low high stop pass And where Window type w= w= w= w= w= boxcor(N); blackman(N); hamming(N); hanning(N); kaiser(N, beta); for rectangular windows for balckman windows for hamming windows for hanning windows for Kaiser windows for for for for Low-pass filters High-pass filters band-Stop filters Band-pass filters
In practice, the window command is often embedded into the fir1 command.
Problem
Design LPF with fP = 1 kHz. fs = 1.5 kHz. Fs = 10 kHz. w = Hamming.
Analytical calculation
From fP and fs the transition width will be Df = (1.5 - 1) / 10 = 0.05 (normalized to Fs). When we lookup the windows table, we will find out that for hamming window N = 3.3 / Df So, the filter length N will be 66. Now the cutoff frequency is changed because of the smearing effect of the window, to be at the half of the transition width. So, fc = fc + 0.5/2 = 1.75 kHz. Then fc (normalized to fN) = 1.75 /5.0 = 0.35.
MATLAB solution
1. Write down the next MATLAB commands
Fs = 10000 fc = 0.35; N = 66; wn = hamming(N); hn = fir1(N-1, fc, wn); [H, f] = freqz(hn, 1, 512, Fs); mag = 20 * log10(abs(H)); plot(f, mag), grid ON xlabel(Frequency (Hz)) ylabel(Magnitude (dB)) 2. Goto Simulink and open a new model. From Simulink Blockset, open Discrete, then select discrete filter. 3. From DSP Blockset, open Source, then select Sin waveform. Setup the sine wave to generate discrete signal with sampling time of 1/10000. 4. From Simulink Blockset, open Sinks, then select Scope. 5. Link the 3 block together. In the Digital Filter block, change the Numerator to hn and Denominator to 1. The sampling time should be 1/10000 as well.
6. Test the model by running it for 3 different signals: 500 Hz(pass band), 1250 Hz(transition band), and 3000 Hz(stop band). Now comment on the results. Comments:
Explanation: 200*pi will take 1000 point each point of 10,000 of sampling rate. This means that 2*pi, which is 1 cycle, will take 10 samples. The 10 samples will give a time of 1 ms. The 1 ms time is 1000 Hz sinusoidal signal. The same principle applies for the t2 and x2 vector which give a 2000 Hz sinusoidal signal t1 = linspace(0, 200*pi, 1000); t2 = linspace(0, 400*pi, 1000) x1 = sin(t1); x2 = sin(t2) 8. Test the filter by those input sequences and get y1 and y2: y1 = filter(hn, 1, x1); y2 = filter(hn, 1, x2); 9. Now plot the 2 output waveforms: plot(y1(1:200)); plot(y2(1:200)); 10. Look at the steady state output and answer this? Did the LPF worked well? How? Give comments Comments:
Problem
Design BPF using Hanning window Passband Transition width Passband ripple Fs Stopband Att. = = = = = 1500 - 2500 Hz. 50 Hz. 0.0546. 10 kHz. 44 dB.
Solution
Remember that, the new cutoff frequencies related the smearing effect will be:
fc1 = fc1 Df/2 and fc2 = fc2 + Df/2. Question What are the analytical calculations needed to get fc1 and fc2? Answer:
Question: What are the MATLAB commands needed to design and plot that filter? Answer:
Question Test your filter by creating 3 sinusoidal signals at 1000 Hz, at 2000 Hz, and 3000Hz using only Simulink. Does it work fine? Give Reasons and Comments? Answer: