



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




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:
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:
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);
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 ');
Show pertinent results!