fir filters in matlab

3
clc; clear all; close all; w=input('Select ur choice 1.Low pass''/n''2.High Pass''/n''3.Bandpass''/n''.Band stop''/n'!; switch(w! case 1 s=input('enter the window 1."ectangular 2.Hanning 3.Ha##ing .Blac$#an %.Bartlett'!; switch(s! case 1 &= ir1( )*.2%) 'low')rectwin( %!!; case 2 &= ir1( )*.2%) 'low')hann( %!!; case 3 &= ir1( )*.2%) 'low')ha##ing( %!!; case &= ir1( )*.2%) 'low')&lac$#an( %!!; case % &= ir1( )*.2%) 'low')&artlett( %!!; end s=+***; t=*,1/ s,1; re- (&)1) s!; igure; c1=input(' nter the re-uenc0 1 ' !; c2=input(' nter the re-uenc0 2' !; =sin(2 pi c1 t! cos(2 pi c2 t!; n=length( !; d = s/n; =4 s/2,d , s/24d ; 5= tshi t( t( !!; plot( )a&s(5!/(n/2!!; igure; 0= ilter(&)1) !; n1=length(0!; d 1= s/n1; 1=4 s/2,d 1, s/24d 1; 6= tshi t( t(0!!; plot( 1)a&s(6!/(n1/2!!; case 2 s=input('enter the window 1."ectangular 2.Hanning 3.Ha##ing .Blac$#ann %.Bartlett'!; switch(s! case 1 &= ir1( )*.2%) 'high')rectwin( %!!; case 2 &= ir1( )*.2%) 'high')hann( %!!; case 3 &= ir1( )*.2%) 'high')ha##ing( %!!; case &= ir1( )*.2%) 'high')&lac$#an( !!; case % &= ir1( )*.2%) 'high')&artlett( %!!; end s=+***; t=*,1/ s,1;

Upload: monicaedu

Post on 04-Nov-2015

247 views

Category:

Documents


3 download

TRANSCRIPT

clc;clear all;close all; w=input('Select ur choice 1.Low pass''/n''2.High Pass''/n''3.Bandpass''/n''4.Band stop''/n'); switch(w) case 1 s=input('enter the window 1.Rectangular 2.Hanning 3.Hamming 4.Blackman 5.Bartlett'); switch(s) case 1 b=fir1(74,0.25,'low',rectwin(75)); case 2 b=fir1(74,0.25,'low',hann(75)); case 3 b=fir1(74,0.25,'low',hamming(75)); case 4 b=fir1(74,0.25,'low',blackman(75)); case 5 b=fir1(74,0.25,'low',bartlett(75)); end fs=8000; t=0:1/fs:1; freqz(b,1,fs); figure; fc1=input('Enter the frequency 1 '); fc2=input('Enter the frequency 2'); x=sin(2*pi*fc1*t)+cos(2*pi*fc2*t); n=length(x); df=fs/n; f=-fs/2:df:fs/2-df; X=fftshift(fft(x)); plot(f,abs(X)/(n/2)); figure; y=filter(b,1,x); n1=length(y); df1=fs/n1; f1=-fs/2:df1:fs/2-df1; Y=fftshift(fft(y)); plot(f1,abs(Y)/(n1/2)); case 2 s=input('enter the window 1.Rectangular 2.Hanning 3.Hamming 4.Blackmann 5.Bartlett'); switch(s) case 1 b=fir1(74,0.25,'high',rectwin(75)); case 2 b=fir1(74,0.25,'high',hann(75)); case 3 b=fir1(74,0.25,'high',hamming(75)); case 4 b=fir1(74,0.25,'high',blackman(74)); case 5 b=fir1(74,0.25,'high',bartlett(75)); end fs=8000; t=0:1/fs:1; freqz(b,1,fs); figure; fc1=input('Enter the frequency 1 '); fc2=input('Enter the frequency 2'); x=sin(2*pi*fc1*t)+cos(2*pi*fc2*t); n=length(x); df=fs/n; f=-fs/2:df:fs/2-df; X=fftshift(fft(x)); plot(f,abs(X)/(n/2)); figure; y=filter(b,1,x); n1=length(y); df1=fs/n1; f1=-fs/2:df1:fs/2-df1; Y=fftshift(fft(y)); plot(f1,abs(Y)/(n1/2)); case 3 wp=[0.4 0.6]; s=input('enter the window 1.Rectangular 2.Hanning 3.Hamming 4.Blackmann 5.Bartlett'); switch(s) case 1 b=fir1(98,wp,rectwin(99)); case 2 b=fir1(98,wp,hann(99)); case 3 b=fir1(98,wp,hamming(99)); case 4 b=fir1(98,wp,blackman(99)); case 5 b=fir1(98,wp,bartlett(99)); end fs=20000; t=0:1/fs:1; freqz(b,1,fs); figure; fc1=input('Enter the frequency 1 '); fc2=input('Enter the frequency 2'); x=sin(2*pi*fc1*t)+cos(2*pi*fc2*t); n=length(x); df=fs/n; f=-fs/2:df:fs/2-df; X=fftshift(fft(x)); plot(f,abs(X)/(n/2)); figure; y=filter(b,1,x); n1=length(y); df1=fs/n1; f1=-fs/2:df1:fs/2-df1; Y=fftshift(fft(y)); plot(f1,abs(Y)/(n1/2)); case 4 wp=[0.4 0.6]; s=input('enter the window 1.Rectangular 2.Hanning 3.Hamming 4.Blackmann 5.Bartlett'); switch(s) case 1 b=fir1(98,wp,'stop',rectwin(99)); case 2 b=fir1(98,wp,'stop',hann(99)); case 3 b=fir1(98,wp,'stop',hamming(99)); case 4 b=fir1(98,wp,'stop',blackman(99)); case 5 b=fir1(98,wp,'stop',bartlett(99)); end fs=20000; t=0:1/fs:1; freqz(b,1,fs); fc1=input('Enter the frequency 1 '); fc2=input('Enter the frequency 2'); x=sin(2*pi*fc1*t)+cos(2*pi*fc2*t); n=length(x); df=fs/n; f=-fs/2:df:fs/2-df; X=fftshift(fft(x)); figure; plot(f,abs(X)/(n/2)); figure; y=filter(b,1,x); n1=length(y); df1=fs/n1; f1=-fs/2:df1:fs/2-df1; Y=fftshift(fft(y)); plot(f1,abs(Y)/(n1/2)); end