You are on page 1of 6

University of Qatar, College of Engineering, Electrical Eng. Dept.

503456 Digital Signal Processing Lab (3) Spring 2008 Name -----------------------------------------------------------------------------------

Digital FIR filter Design


A. Windows Method
In this method the student will follow the necessary steps in order to come out with the complete FIR-window filter: 1. Selection of the desired frequency response. 2. Selection of a window function then estimate N. 3. Obtain hD(n) truncated to N. 4. Obtain N coefficients of window function w(n) 5. Obtain FIR filter coefficient h(n) = hD(n) * w(n) The types of filter supported by this method are: Low-pass, High-pass, Band-pass, and Band-stop filters. The key high level command in toolbox is the fir1 command. The syntax for the basic fir command is: b = fir1(N-1, Fc); The basic command computes and returns N-point impulse response coefficients of an FIR filter with a cutoff frequency of Fc, the command returns the N-points coefficients in the vector b arranged in ascending negative power of z. b(z) = b(0) + b(1)z-1 + b(2)z-2 + .. The parameter N-1 specifies the order of the filter. The cutoff frequency Fc is normalized to the Nyquist frequency. By default the basic fir1 command applies a Hamming Window and assumes a Low-pass filter type (or Band-pass filter if Fc is specified in vector format). The general command is: b = fir1(N-1, Fc, filter type, window);

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:

7. Create 1000 point 1000 Hz and 2000 Hz Sinusoidal waveforms:

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:

You might also like