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


Top Related