Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

MATLAB Lab: Designing FIR Filters using the Parks-McClellan Algorithm - Prof. William H. B, Lab Reports of Microprocessors

A laboratory exercise for designing a 33-coefficient fir bandpass filter using matlab. The use of the remez algorithm and chebyshev's approximation theory to create a filter with a center frequency of 1 khz and desired frequency bands. The document also includes instructions for saving the filter coefficients and verifying the filter's magnitude response.

Typology: Lab Reports

2009/2010

Uploaded on 02/24/2010

koofers-user-ab9-1
koofers-user-ab9-1 🇺🇸

10 documents

1 / 6

Toggle sidebar

Related documents


Partial preview of the text

Download MATLAB Lab: Designing FIR Filters using the Parks-McClellan Algorithm - Prof. William H. B and more Lab Reports Microprocessors in PDF only on Docsity! LABORATORY 8 ENTC 4337 MATLAB FOR FIR FILTER DESIGN AND FFT FIR and IIR filters can be designed using the MATLAB software package. FFT and IFFT functions are also available with MATLAB. The following MATLAB program, MAT33.m is used to design a 33-coefficient FIR bandpass filter. %MAT33.M FIR BANDPASS WITH 33 COEFFICIENTS USING MATLAB Fs10 kHz nu[0 0.1 0.15 0.25 0.3 1); %normalized frequencies mag=[0 0 1 1 0 0]; %magnitude at normalized frequencies c=remez(32,nu,mag); %invoke remez algorithm for 33 coeff bp33=c’; % coeff values transposed save matbp33.cof bp33 -ascii; %save in ASCII file with coefficients [h,w]=freqz(c,l,256); %frequency response with 256 points plot(5000*nu,mag,W/pi,abS(h)) %plot ideal magnitude response The function remez uses the Parks-McClellan algorithm based on the Remez exchange algorithm and Chebyshev’s approximation theory. The desired filter has a center frequency of 1 kHz with a sampling frequency of 10 kHz. The frequency v represents the normalized frequency variable, defined as v =f/FN, where FN is the Nyquist frequency. The bandpass filter is represented with 3 bands: 1. The first band (stopband) has normalized frequencies between 0 and 0.1 (0-500 Hz), with corresponding magnitude of 0. 2. The second band (passband) has normalized frequencies between 0.15 and 0.25 (750-1,250 Hz), with corresponding magnitude of 1. 3. The third band (stopband) has normalized frequencies between 0.3 and the Nyquist frequency of 1 (1500-5000 Hz), with corresponding magnitude of 0. Run this program from MATLAB and verify the magnitude response of the ideal desired filter. Figure 1. Note that the frequencies 750 and 1250 Hz represent the passband frequencies with normalized frequencies of 0.15 and 0.25, respectively, and associated magnitudes of 1. The frequencies 500 and 1500 Hz represent the stopband frequencies with normalized frequencies of 0.1 and 0.3, respectively, and associated magnitudes of 0. The instructions, c=remez(32,nu,mag); and save a:\matbp33.cof bp33 -ascii; , create a file of coefficients for the FIR filter. Note for the FIR filter, the coefficients repeat themselves. That is, the first 16 coefficients match the last 16 coefficients. Thus, if you folded, the coefficients in the middle the coefficients would fold onto their corresponding coefficient. -4.2666814e-003 5.8252982e-002 -9.8920159e-003 -6.7800242e-003 8.8990874e-003 3.1131024e-002 4.9931687e-002 5.0913841e-002 2.3821990e-002 -2.8167695e-002 -8.5205826e-002 -1.1853161e-001 -1.0533615e-001 -4.3253615e-002 4.5460388e-002 1.2266339e-001 1.5317503e-001 1.2266339e-001 4.5460388e-002 -4.3253615e-002 -1.0533615e-001 -1.1853161e-001 -8.5205826e-002 -2.8167695e-002 2.3821990e-002 5.0913841e-002 4.9931687e-002 3.1131024e-002 8.8990874e-003 -6.7800242e-003 -9.8920159e-003 5.8252982e-002 -4.2666814e-003 Obviously, MATLAB or other filter design packages can be used to obtain the coefficients for a desired FIR filter. To have a more realistic simulation, a composite signal may be created and filtered in MATLAB. Consider a composite signal consisting of three sinusoids created by the following MATLAB code and shown in figure below: Fs=10e3; Ts=1/Fs; Ns=512; t= [0:Ts:Ts*(Ns-1)]; f1=1000; f2=2500; f3=3000; x1=sin(2*pi*f1*t); x2=sin(2*pi*f2*t); x3=sin(2*pi*f3*t); x=x1+x2+x3; plot(t,x), grid; The signal frequency content can be plotted by using the MATLAB fft function. Three spikes should be observed at 1000 Hz, 2500 Hz, and 3000 Hz. The frequency leakage observed on the plot is due to windowing caused by the finite observation period. The following MATLAB code allows one to visually inspect the filtering. n=128; subplot(2,1,1); plot(t(1:n),x(1:n)); grid on; xlabel('time(s)'); ylabel('Amplitude'); title('Original and Filtered Signal'); subplot(2,1,2); grid on; plot(t(1:n),y(1:n)); grid on; xlabel('times(s)'); ylabel('Amplitude'); Figure 5. Looking at the plots, we see that the filter is able to remove the desired frequency components of the composite signal. Observe that the time response has an initial setup time causing a few data samples to be inaccurate. Questions. 1. What do the subplot functions do? 2. In the three subplots containing the frequency components of the composite signal, the 0 0.002 0.004 0.006 0.008 0.01 0.012 0.014 -4 -2 0 2 4 time(s) A m pl itu de Original and Filtered Signal 0 0.002 0.004 0.006 0.008 0.01 0.012 0.014 -2 -1 0 1 2 times(s) A m pl itu de filter characteristics, and the frequency components of the filtered signal; the filter characteristics are normalized. What are they normalized to, and why is the highest normalized frequency on 0.5. 3. How would you change the procedure to develop a low-pass filter? a high-pass filter?
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved