Docsity

FIR Filter Design - Digital Signal Processing - Lab Manual, Study notes of Computer Fundamentals

Toggle sidebar
bg1
FIR Filter Design
Introduction:
In this laboratory, we will use MATLAB to design a FIR (finite impulse response) filter. The
MATLAB program will generate a set of coefficients that mathematically describe the transfer
characteristics of the filter. This set of coefficients may be tested in MATLAB by generating a
set of test frequencies, applying the frequencies to a simulation of the filter, and verifying that
the desired test frequencies are filtered out. The filter coefficients generated by MATLAB can be
stored in an ASCII file and used by a DSP (digital signal processor) board to generate the desired
FIR filter.
Procedure:
1. The following MATLAB code uses the remez function to produce 33 coefficients that are
placed in Coff. file, a:\matbp33.cofbp33 -ascii. (Note you must decide the file where you
store the data.) These coefficients define a low pass filter.
%MAT33.M FIR BANDPASS WITH 33 COEFFICIENTS USING MATLAB
%
%
nu=[0 0.5 0.55 1]; %normalized frequencies
mag=[1 1 0 0]; %magnitude @ normalized freqs
c=remez(32,nu, mag); %invoke remez algorithm for 33 coefficients
bp33=c’; %coefficient vector transposed
save a:\matbp33.cofbp33 -ascii; %save coefficients in ascii file (dest,source)
[h,w]=freqz(c, 1, 256); %frequency plot with 256 points
plot(5000*nu,mag,w/pi,abs(h)) %plot ideal magnitude response
Coefficient
You will need
to change this
to match your
file.
Docsity.com
pf3
pf4
pf5

Partial preview of the text

Download FIR Filter Design - Digital Signal Processing - Lab Manual and more Study notes Computer Fundamentals in PDF only on Docsity!

FIR Filter Design

Introduction:

In this laboratory, we will use MATLAB to design a FIR (finite impulse response) filter. The MATLAB program will generate a set of coefficients that mathematically describe the transfer characteristics of the filter. This set of coefficients may be tested in MATLAB by generating a set of test frequencies, applying the frequencies to a simulation of the filter, and verifying that the desired test frequencies are filtered out. The filter coefficients generated by MATLAB can be stored in an ASCII file and used by a DSP (digital signal processor) board to generate the desired FIR filter.

Procedure:

  1. The following MATLAB code uses the remez function to produce 33 coefficients that are placed in Coff. file, a:\matbp33.cofbp33 -ascii. (Note you must decide the file where you store the data.) These coefficients define a low pass filter.

%MAT33.M FIR BANDPASS WITH 33 COEFFICIENTS USING MATLAB

nu=[0 0.5 0.55 1]; %normalized frequencies mag=[1 1 0 0]; %magnitude @ normalized freqs c=remez(32,nu, mag); %invoke remez algorithm for 33 coefficients bp33=c’; %coefficient vector transposed save a:\matbp33.cofbp33 -ascii; %save coefficients in ascii file (dest,source) [h,w]=freqz(c, 1, 256); %frequency plot with 256 points plot(5000*nu,mag,w/pi,abs(h)) %plot ideal magnitude response

Coefficient

You will need to change this to match your file.

3.6406389e- -2.6231408e- -3.0603887e- 6.5090395e- 1.1311239e- -2.1606658e- -2.3917629e- 2.2122339e- 2.0002062e- -3.8139676e- -2.4148287e- 5.6624944e- 2.3685121e- -1.0258764e- -2.5123018e- 3.1675284e- 5.2477602e- 3.1675284e- -2.5123018e- -1.0258764e- 2.3685121e- 5.6624944e- -2.4148287e- -3.8139676e- 2.0002062e- 2.2122339e- -2.3917629e- -2.1606658e- 1.1311239e- 6.5090395e- -3.0603887e- -2.6231408e- 3.6406389e-

Testing the coefficients:

  1. The following MATLAB commands generate three test frequencies that will be used later to test the filter that the coefficients describe in MATLAB.

Fs=10e3; Ts=1/Fs; Ns=512; t=[0:Ts:Ts(Ns-1)]; f1=1000; f2=2500; f3=4000; xl=sin(2pif1t); x2=sin(2pif2t); x3=sin(2pif3t); x=xl+x2+x3; plot(t,x), grid; axis([0 4e-3 -3 3])

function va_fft(x,Ns,Fs) X=fft(x,Ns); XX=(abs(X)); XXX=XX(1:length(XX)/2; y=XXX; f=[1:1:length(y)]; plot(f*Fs/Ns,y); grid on;

nu=[0 0.5 0.55 1]; mag=[1 1 0 0]; c=remez(32,nu, mag); a=1; freqz(c,a);grid on subplot(3,1,1) va_fft(x,1024,10000); subplot(3,1,2),grid on [h,w]=freqz(c,1,256); plot(w/(2pi),10log(abs(h))); subplot(3,1,3);grid on y=filter(c,a,x); va_fft(y,1024,10000);

  1. Finally, we can compare the original waveform with the filtered waveform.

n= 128; subplot(2,1,1); plot(t(1:n),x( 1:n)); grid on; axis([0 8e-3 -3 3]); xlabel('time(s)'); ylabel('Amplitude '); title('Original and Filtered Signal '); subplot(2,1,2); plot(t(1:n),y(1:n)); grid on; axis([0 8e-3 -3 3]); xlabel('times(s)'); ylabel('Amplitude ');

  1. Using the preceding example, develop FIR filters that a. Eliminates all the frequencies except the 1000 Hz signal b. Eliminates all the frequencies except the 2000 Hz signal c. Eliminates all the frequencies except the 3000 Hz signal d. Eliminates only the 2000 Hz signal.

Show pertinent results!