Sie sind auf Seite 1von 18

Source code :1

%windows technique of Rectangular window using low pass filter


clc;
clear all;
close all;
N=input('Size of window:');
wc=input('Cut off frequency:');
h=fir1(N-1,wc/pi,boxcar(N));
tf(h,1,1,'variable','z^-1');
freqz(h);
xlabel('Frequency');
ylabel('Magnitude');
title('FIR Filter');

Source code :2
%windows technique of Triangular(Bartlet Window) using High pass filter
clc;
clear all;
close all;
N=input('Size of window:');
wc=input('Cut off frequency:');
h=fir1(N-1,wc/pi,'high',triang(N));
tf(h,1,1,'variable','z^-1');
freqz(h);
xlabel('Frequency');
ylabel('Magnitude');
title('FIR Filter');

Source code :3
%windows technique of Hamming using Band pass filter
clc;
clear all;
close all;
N=input('Size of window:');
wc1=input('Lower Cut off frequency:');
wc2=input('Upper Cut off frequency:');
wc=[wc1 wc2];
h=fir1(N-1,wc/pi,'bandpass',hamming(N));
tf(h,1,1,'variable','z^-1');
freqz(h);
xlabel('Frequency');
ylabel('Magnitude');
title('FIR Filter');

Source code :4
%windows technique of Hanning using Band stop filter
clc;
clear all;
close all;
N=input('Size of window:');
wc1=input('Lower Cut off frequency:');
wc2=input('Upper Cut off frequency:');
wc=[wc1 wc2];
h=fir1(N-1,wc/pi,'stop',hanning(N));
tf(h,1,1,'variable','z^-1');
freqz(h);
xlabel('Frequency');

ylabel('Magnitude');
title('FIR Filter');
Command Window :1

Output:1

Command Window :2

OUTPUT: 2
Command Window :3

Output:3
Command Window :4

Output:4

Command Window :5
Output:

Butterworth Filters
SOURCE CODE:1
clc;
clear all;
close all;
%% Butterworth low pass Filter
% Filter Specifications

k1=input('Enter the passband gain in db:');


k2=input('Enter the stopband gain in db:');
w1=input('Enter the passband edge frequency in rad/Sec:');
w2=input('Enter the stopband edge frequency in rad/Sec:');

%Find the order and Cutofrf frequency using the given specification of
%filter
[n,Wc]=buttord(w1,w2,k1,k2,'s');
disp('The order is:');
disp(n);
disp('The cutoff frequency is:');
disp(Wc);

% Low pass filtering


[b,a]=butter(n,Wc,'low','s');

%Plotting magnitude & phase response

f=linspace(1,512,1000);
h=freqs(b,a,f);

m=20*log(abs(h));
subplot(2,1,1);
semilogx(f,m);
xlabel('Frequency');
ylabel('Magnitude');
title('Magnitude response of Butterworth LPF');

% Phase response
p=angle(h);
subplot(2,1,2);
semilogx(f,p);
xlabel('Frequency');
ylabel('Phase');
title('Phase response of Butterworth LPF');

SOURCE CODE:2
clc;
clear all;
close all;
%% Butterworth high pass Filter
% Filter Specifications
k1=input('Enter the passband gain in db:');
k2=input('Enter the stopband gain in db:');
w1=input('Enter the passband edge frequency in rad/Sec:');
w2=input('Enter the stopband edge frequency in rad/Sec:');

%Find the order and Cutofrf frequency using the given specification of
%filter
[n,Wc]=buttord(w1,w2,k1,k2,'s');
disp('The order is:');
disp(n);
disp('The cutoff frequency is:');
disp(Wc);

% Low pass filtering


[b,a]=butter(n,Wc,'high','s');

%Plotting magnitude & phase response

f=linspace(1,512,1000);
h=freqs(b,a,f);

m=20*log(abs(h));
subplot(2,1,1);
semilogx(f,m);
xlabel('Frequency');
ylabel('Magnitude');
title('Magnitude response of Butterworth HPF');

% Phase response
p=angle(h);
subplot(2,1,2);
semilogx(f,p);
xlabel('Frequency');
ylabel('Phase');
title('Phase response of Butterworth HPF');

SOURCE CODE:3
clc;
clear all;
close all;
%% Bandpass Filter Specifications
Wp=input('Enter the pass band edge frequency : ');
Ws=input('Enter the stop band edge frequency : ');
Rp=input('Enter the Pass band ripple: ');
Rs=input('Enter the stop band gain: ');

%To find order of the filter


[N]=buttord(Wp,Ws,Rp,Rs,'s')

%To find cut off frequency


Wc=[Wp Ws];

%Band pass Filtering


[b,a]=butter(N,Wc,'bandpass','s');

%plotting magnitude and phase response


figure(1);freqs(b,a);

SOURCE CODE:4
clc;
clear all;
close all;
%% Bandstop Filter Specifications
Wp=input('Enter the pass band edge frequency : ');
Ws=input('Enter the stop band edge frequency : ');
Rp=input('Enter the Pass band ripple: ');
Rs=input('Enter the stop band gain: ');

%To find order of the filter


[N]=buttord(Wp,Ws,Rp,Rs,'s')

%To find cut off frequency


Wc=[Wp Ws];

%Band stop Filtering


[b,a]=butter(N,Wc,'stop','s');

%plotting magnitude and phase response


figure(1);freqs(b,a);

Command Windows :

Using Low pass filter

Using High pass filter

Using Band pass filter

Using Band stop filter


OUTPUTS:

Using Low pass filter

Using High pass filter


Using Band pass filter
Using Band stop filter

CHEBYSHEV FILTERS :
Source code:1
clc;
clear all;
close all;
%% Chebyshev low pass Filter
% Filter Specifications

k1=input('Enter the passband ripple in db:');


k2=input('Enter the stopband attenuation in db:');
w1=input('Enter the passband edge frequency in rad/Sec:');
w2=input('Enter the stopband edge frequency in rad/Sec:');

%Find the order and Cutofrf frequency using the given specification of
%filter
[n,Wc]=cheb1ord(w1,w2,k1,k2,'s');
disp('The order is:');
disp(n);
disp('The cutoff frequency is:');
disp(Wc);

% Low pass filtering


[b,a]=cheby1(n,k1,w1,'low','s');
figure(1);freqs(b,a);

Source code:2
clc;
clear all;
close all;
%% Chebyshev High pass Filter
% Filter Specifications

k1=input('Enter the passband ripple in db:');


k2=input('Enter the stopband attenuation in db:');
w1=input('Enter the passband edge frequency in rad/Sec:');
w2=input('Enter the stopband edge frequency in rad/Sec:');

%Find the order and Cutofrf frequency using the given specification of
%filter
[n,Wc]=cheb1ord(w1,w2,k1,k2,'s');
disp('The order is:');
disp(n);
disp('The cutoff frequency is:');
disp(Wc);

% High pass filtering


[b,a]=cheby1(n,k1,w1,'high','s');
figure(1);freqs(b,a);

Source code: 3
clc;
clear all;
close all;
%% Bandpass Filter Specifications
Wp=input('Enter the pass band edge frequency : ');
Ws=input('Enter the stop band edge frequency : ');
Rp=input('Enter the Pass band ripple: ');
Rs=input('Enter the stop band gain: ');
%To find order of the filter
[N]=cheb1ord(Wp,Ws,Rp,Rs,'s')

%To find cut off frequency


Wc=[Wp Ws];

%Band pass Filtering


[b,a]=cheby1(N,Rp,Wc,'bandpass','s');

%plotting magnitude and phase response


figure(1);freqs(b,a);

Source code: 4
clc;
clear all;
close all;
%% Bandstop Filter Specifications
Wp=input('Enter the pass band edge frequency : ');
Ws=input('Enter the stop band edge frequency : ');
Rp=input('Enter the Pass band ripple: ');
Rs=input('Enter the stop band gain: ');

%To find order of the filter


[N]=cheb1ord(Wp,Ws,Rp,Rs,'s')

%To find cut off frequency


Wc=[Wp Ws];

%Bandstop Filtering
[b,a]=cheby1(N,Rp,Wc,'stop','s');

%plotting magnitude and phase response


figure(1);freqs(b,a);

Command Window :1(LPF)


Output:

Command Window :2(HPF)


Output:

Command Window :3(BPF)

Output:
Command Window :4(BSF)

Output:

Das könnte Ihnen auch gefallen