Fir Low Pass Filter
Fir Low Pass Filter
%Butterworth HPF
clear all; clc; clc;
wc=0.5*pi clear all; clear all;
N=25; wc1=0.25*pi close all;
alpha=(N-1)/2 wc2=0.75*pi rp=input('Enter the paasband attenuation
eps=0.001; N=25; :');
n=0:1:N-1; alpha=(N-1)/2 rs=input('Enter the stopband attenuation :'
hd=sin(wc*(n-alpha+eps))./(pi*(n- eps=0.001; );
alpha+eps)) n=0:1:N-1; fp=input('Enter the pass band frequency :');
wr=boxcar(N) hd=(sin(wc1*(n-alpha+eps))-sin(wc2*(n- fs=input('Enter the stopband frequency :');
hn=hd.*wr' alpha+eps))+ sin(pi*(n- f=input('Enter the sampling frequency :');
w=0:0.01:pi; alpha+eps)))./(pi*(nalpha+eps)) wp=(2*pi/f)*fp
h=freqz(hn,1,w) wr=boxcar(N); ws=(2*pi/f)*fs
plot(w/pi,abs(h)); hn=hd.*wr'; % Converting to radians/sec using Bilinear
xlabel('Normalized frequency\omega/\pi'); w=0:0.01:pi; Transformation
ylabel('magnitude'); h=freqz(hn,1,w); Omegap=2*f*tan(wp/2)
grid on; plot(w/pi,abs(h)); Omegas=2*f*tan(ws/2)
xlabel('Normalized frequency\omega/\pi'); %DESIRED ANALOG FILTER DESIGN
FIR High Pass Filter ylabel('magnitude'); [N,Omegac]=buttord(Omegap,Omegas,rp,r
clear all; grid on; s,'s')
wc=0.5*pi disp('Poles and zeros of Desired high pass
N=25; %butterwoth LPF analog filter')
alpha=(N-1)/2 clc; [z,p,k]=butter(N,Omegap,'high','s')
eps=0.001; clear all; disp('Desired Analog high pass filter
n=0:1:N-1; close all; Transfer function')
hd=(sin(pi*(n-alpha+eps))-sin(wc*(n- rp=input('enter the paasband attenuation :'); [num,den]=zp2tf(z,p,k)
alpha+eps)))./(pi*(n-alpha+eps)) rs=input('enter the stopband attenuation :'); %DIGITAL FILTER DESIGN USING
wr=boxcar(N); fp=input('enter the pass band frequency :'); BILINEAR
hn=hd.*wr'; fs=input('enter the stopband frequency :'); disp('Poles and zeros of digital filter')
w=0:0.01:pi; f=input('enter the sampling frequency :'); [zd,pd,kd]=bilinear(z,p,k,f)
h=freqz(hn,1,w); %Converting to radians disp('Digital filter Transfer function')
plot(w/pi,abs(h)); wp=(2*pi/f)*fp [numd,dend]=zp2tf(zd,pd,kd)
xlabel('Normalized frequency\omega/\pi'); ws=(2*pi/f)*fs freqz(numd,dend,512,f)
ylabel('magnitude'); % Converting to radians/sec using Bilinear
grid on; Transformation %Chebyschev LPF
Omegap=2*f*tan(wp/2) clc;
FIR BAND PASS FILTER Omegas=2*f*tan(ws/2) clear all;
clc; %ANALOG FILTER DESIGN close all;
clear all; [N,Omegac]=buttord(Omegap,Omegas,rp,r rp=input('Enter the paasband attenuation
wc1=0.25*pi s,'s') :');
wc2=0.75*pi disp('Poles and zeros of analog filter') rs=input('Enter the stopband attenuation :'
N=25; [z,p,k]=butter(N,Omegac,'s') );
alpha=(N-1)/2 disp('Analog filter Transfer function') fp=input('Enter the pass band frequency :');
eps=0.001; [num,den]=zp2tf(z,p,k) fs=input('Enter the stopband frequency :');
n=0:1:N-1; figure; f=input('Enter the sampling frequency :');
hd=(sin(wc2*(n-alpha+eps))-sin(wc1*(n- freqs(num,den) wp=(2*pi/f)*fp
alpha+eps)))./(pi*(n-alpha+eps)) title('ANALOG FREQUENCY ws=(2*pi/f)*fs
wr=boxcar(N); RESPONSE'); % Converting to radians/sec using Bilinear
hn=hd.*wr'; %DIGITAL FILTER DESIGN USING Transformation
w=0:0.01:pi; BILINEAR TRANSFORMATION Omegap=2*f*tan(wp/2)
h=freqz(hn,1,w); disp('Poles and zeros of digital filter') Omegas=2*f*tan(ws/2)
plot(w/pi,abs(h)); [zd,pd,kd]=bilinear(z,p,k,f) %ANALOG FILTER DESIGN
xlabel('Normalized frequency\omega/\pi'); disp('Digital filter Transfer function') [N,Omegac]=cheb1ord(Omegap,Omegas,r
ylabel('magnitude'); [numd,dend]=zp2tf(zd,pd,kd) p,rs,'s')
grid on; figure disp('Poles and zeros of analog filter')
freqz(numd,dend,512,f) [z,p,k]=cheby1(N,rp,Omegac,'s')
title('DIGITAL FREQUENCY disp('Analog filter Transfer function')
RESPONSE'); [num,den]=zp2tf(z,p,k)
figure
freqs(num,den)
title('ANALOG FREQUENCY
RESPONSE')
%DIGITAL FILTER DESIGN USING
BILINEAR TRANSFORMATION VERIFICATION OF SAMPLING COMPUTATION OF N POINT DFT OF
disp('Poles and zeros of digital filter') THEOREM USING SINE FUNCTION A GIVEN SEQUENCE
[zd,pd,kd]=bilinear(z,p,k,f) close all; clc;
disp('Digital filter Transfer function') clear all; x=input('Enter the sequence: ');
[numd,dend]=zp2tf(zd,pd,kd) t=-10:0.01:10; N=input('Enter N: ');
figure T=8; x1=[x,zeros(1,N-length(x))]
freqz(numd,dend,512,f) fm=1/T; % Find DFT
title('DIGITAL FREQUENCY % GENERATION OF SINE WAVE K=0:1:N-1; n=0:1:N-1;
RESPONSE') x=sin(2*pi*fm*t); wN=exp(-j*2*pi/N);
fs1=1.2*fm; nK=n'*K;
%Chebyschev HPF fs2=2*fm; wNnK=wN.^nK;
clc; fs3=8*fm; XK=x1*wNnK
clear all; n1=-4:1:4; abs_XK=abs(XK)
close all; % UNDERSAMPLING angle_XK=angle(XK)
rp=input('Enter the paasband attenuation xn1=sin(2*pi*n1*fm/fs1); n=0:1:N-1;
:'); subplot(221) subplot(3,1,1)
rs=input('Enter the stopband attenuation :' plot(t,x); stem(n,abs_XK)
); xlabel('time in seconds'); grid on
fp=input('Enter the pass band frequency :'); ylabel('x(t)'); title('Real Value of DFT')
fs=input('Enter the stopband frequency :'); title('continous time signal'); xlabel('n')
f=input('Enter the sampling frequency :'); subplot(222) ylabel('amplitude')
% Converting to radians stem(n1,xn1); n=0:1:N-1;
wp=(2*pi/f)*fp hold on; subplot(3,1,2)
ws=(2*pi/f)*fs plot(n1,xn1); stem(n,angle_XK)
% Converting to radians/sec using Bilinear xlabel('n'); grid on
Transformation ylabel('x(n)'); title('Angle of DFT Signal')
Omegap=2*f*tan(wp/2) title('discrete time signal with fs<2fm'); xlabel('n')
Omegas=2*f*tan(ws/2) % NYQUIST RATE SAMPLING ylabel('amplitude')
%ANALOG FILTER DESIGN n2=-5:1:5; % Find IDFT
[N,Omegac]=cheb1ord(Omegap,Omegas,r xn2=sin(2*pi*n2*fm/fs2); K=0:1:N-1;
p,rs,'s') subplot(223) n=0:1:N-1;
disp('Poles and zeros of analog filter') stem(n2,xn2); wN=exp(j*2*pi/N);
[z,p,k]=cheby1(N,rp,Omegap,'high','s') hold on; nK=n'*K;
disp('Analog filter Transfer function') plot(n2,xn2); wNnK=wN.^nK;
[num,den]=zp2tf(z,p,k) xlabel('n'); x=real(XK*wNnK);
figure ylabel('x(n)'); x=abs((x./N))
freqs(num,den) title('discrete time signal with fs=2fm'); n=0:1:N-1;
title('ANALOG FREQUENCY % OVERSAMPLING subplot(3,1,3)
RESPONSE') n3=-20:1:20; stem(n,x)
%DIGITAL FILTER DESIGN USING xn3=sin(2*pi*n3*fm/fs3); grid on
BILINEAR TRANSFORMATION subplot(224) title('idft signal')
disp('Poles and zeros of digital filter') stem(n3,xn3); xlabel('n')
[zd,pd,kd]=bilinear(z,p,k,f) hold on; ylabel('amplitude')
disp('Digital filter Transfer function') plot(n3,xn3); LINEAR CONVOLUTION OF TWO
[numd,dend]=zp2tf(zd,pd,kd) xlabel('n'); SEQUENCES USING DFT AND IDFT
figure ylabel('x(n)'); clc;
freqz(numd,dend,512,f) title('discrete time signal with fs>2fm'); x1=input('Enter sequence x1');
title('DIGITAL FREQUENCY x2=input('Enter sequence x2');
RESPONSE') N1=length(x1);
N2=length(x2);
% define N
N=N1+N2-1
x1 =[x1,zeros(1,N-N1)]
x2=[x2,zeros(1,N-N2)]
%Find DFT of x1
X1=fft(x1); %Find DFT of x2
X2=fft(x2)
%Find Linear Convolution
X3=X1.*X2; x3=ifft(X3); n=0:1:N-1;
stem(n,x3); title('Linear Convolution')
xlabel('time'); ylabel('amplitude')