Sunday, January 26, 2014

Matlab Program for Finite Impulse Response(FIR) Filter Design

with 0 Comment
Matlab Program for Finite Impulse Response(FIR) Filter Design:

clc;
close all;
clear all;
n = input('enter the order of filter :');
wc = input('enter the cut off frequency:');
ws=input('enter the sampling frequency:');
disp('1 for low pass');disp('2 for high pass');disp('3 for bandpass');disp('4 for bandstop');
disp('enter the filter type');
filtertype=input('filter type');
switch (filtertype)
    case 1
        ft ='low';
    case 2
        ft='high';
    case 3
        ft='pass';
    case 4
        ft='stop';
    otherwise
        disp('error');
end
disp('1 for rectwin');disp('2 for hamming');disp('3 for hanning');disp('4 for blackman');
disp('enter the window type');
windowtype=input('window type');
switch (windowtype)
    case 1
        wt=rectwin(n+1);
    case 2
        wt=hamming(n+1);
    case 3
        wt=hanning(n+1);
    case 4
        wt=blackman(n+1);
  
 otherwise
        disp('error');
end
figure(1)
b = fir1(n,wc/ws,ft,wt);
freqz(b,1,ws);
n=linspace(0,1,ws);
f1=input('enter the passband frequency:');
f2=input('enter the stopband frenquency:');
x=sin(2*pi*f1*n)+sin(2*pi*f2*n);
xk=fft(x);
figure(2)
subplot(2,2,1);stem(abs(xk));title('spectrum of input signal');xlabel('k');yalabel('X(K)');
y=filter(b,1,x);
yk=fft(y);
subplot(2,2,2);stem(abs(yk));title('spectrum of filtered output signal');xlabel('k');yalabel('y(K) ');
  
OUTPUT:

LOW PASS FILTER:

enter the order of filter :50
enter the cut off frequency:2000
enter the sampling frequency:8000
1 for low pass
2 for high pass
3 for bandpass
4 for bandstop
enter the filter type
filter type1
1 for rectwin
2 for hamming
3 for hanning
4 for blackman
enter the window type
window type1
enter the passband frequency:1200
enter the stopband frenquency:2400 
    
HIGH PASS FILTER:

enter the order of filter :50
enter the cut off frequency:2000
enter the sampling frequency:8000
1 for low pass
2 for high pass
3 for bandpass
4 for bandstop
enter the filter type
filter type2
1 for rectwin
2 for hamming
3 for hanning
4 for blackman
enter the window type
window type2
enter the passband frequency:1300
enter the stopband frenquency:2500
                                                                           
BAND PASS FILTER:

 enter the order of filter :50
enter the cut off frequency:[1500 3000]
enter the sampling frequency:8000
1 for low pass
2 for high pass
3 for bandpass
4 for bandstop
enter the filter type
filter type3
1 for rectwin
2 for hamming
3 for hanning
4 for blackman
enter the window type
window type3
enter the passband frequency:2000
enter the stopband frenquency:3500

BAND STOP FILTER:

enter the order of filter :50
enter the cut off frequency:[1500 3000]
enter the sampling frequency:8000
1 for low pass
2 for high pass
3 for bandpass
4 for bandstop
enter the filter type
filter type4
1 for rectwin
2 for hamming
3 for hanning
4 for blackman
enter the window type
window type4
enter the passband frequency:2000
enter the stopband frenquency:3500
              

0 comments:

Post a Comment

Powered by Blogger.

Blog Archive