# What is IFR filter?

32 views (last 30 days)
Crocodile Fever on 5 Dec 2021
Answered: JIM HAWKINSON on 10 Dec 2021
Infinite Filter Reponse
Star Strider on 6 Dec 2021
@William Rose — Thank you!

William Rose on 5 Dec 2021
I have never heard of an IFR filter. But I have heard of, and I have used, FIR and IIR filters. I assume you meant one of those. They are varieties of digital filters. A finite impulse response filter has non-zero outputs for only a finite time, in response to an impulse. An infinite impuse response filter has non-zero outputs (in a mathematical sense) forever, in response to an impulse.

markoni chapra on 7 Dec 2021
%% Generation of signals
%%Unit impluse
clc; clear all; close all;
n=-10:1:10;
y = [zeros(1,10), ones(1,1), zeros(1,10)];
subplot(221); stem(n,y);
ylabel('Amplitude'); xlabel('n');
% % Unit step
%N = input('enter value of N');
N=10;
n = 0:1:N-1;
y1 = ones(1,N);
subplot(222); plot(n,y1);
ylabel('Amplitude'); xlabel('n');
% % Generation of ramp signal
%n1 = input('enter value of n1');
n1=10;
n = 0:n1;
subplot(223); stem(n,n);
ylabel('Amplitude'); xlabel('n');
% % Generation of Expoential Signal
%n2 = input('enter value of n2');
n2=10;
n = 0:n2;
%a = input('enter value of a');
a=0.5;
y2 = exp(-a*n);
subplot(224); stem(n,y2);
ylabel('Amplitude'); xlabel('n');
% % Generation of sine wave
n = 0:0.01:pi;
y = sin (2*pi*n);
y1= cos(2*pi*n);
figure;
subplot(411); stem(n,y,'b');
ylabel('Amplitude'); xlabel('n');
%hold on;
subplot(412); stem(n,y1,'k');
ylabel('Amplitude'); xlabel('n');
z=y+y1; %hold on;
subplot(413); stem(n,z,'r');
ylabel('Amplitude'); xlabel('n');
% % Generation of sine wave
n = 0:0.01:pi;
y = cos (2*pi*n);
subplot(414); stem(n,y);
ylabel('Amplitude'); xlabel('n');
% % Problems-1: Generation of signum signal
%N = input('enter value of N');
N=10; n = -(N-1):1:N-1;
y1 = [-1*ones(1,N-1), ones(1,N)];
figure, %subplot(221);
stem(n,y1); ylabel('Amplitude'); xlabel('n');
% % Problems-2: Generation two sided expoential signal
n = 10; a = 0.1;
n1 = 0:n; n2 =-n:0;
y1 = exp(a*n1); y2 = exp((-a)*n2);
figure, subplot(221); stem(n1,y1); subplot(222); stem(n2,y2);
ylabel('Amplitude'); xlabel('n');
n3 = [-n:1:n];
y3 = [y2, zeros(1,n)];
subplot(223); stem(n3,y3);
n4 = [-n:1:n];
y4 = [zeros(1,n),y1];
subplot(224); stem(n4,y4);
n5 = n4;
y5 = y3 + y4;
figure, stem(n5,y5);
%%
%% program 1.1::generation of elementary signals in discrete-time
clc;close all;clear all;
% % unit impulse sequence
n=-10:1:10;
impulse =[zeros(1,10),ones(1,1),zeros(1,10)];
subplot(2,2,1);stem(n,impulse);
xlabel('discrete time n-->');ylabel('amplitude-->');
title('unit impulse sequence');
axis([-10,10,0,1.2]);
% %unit step sequence
n = -10:1:10;
step = [zeros(1,10),ones(1,11)];
subplot(2,2,2); stem(n,step);
xlabel('discrete time n-->');ylabel('amplitude-->');
title('unit step sequence');
%axis([-10,10,0,1.2]);
% %unit ramp sequence
n=0:1:10;
ramp=n;
subplot(2,2,3);stem(n,ramp);
xlabel('discrete time n-->');ylabel('amplitude-->');
title('unit ramp sequence');
% %unit parabolic sequence
n=0:1:10;
parabola=0.5*(n.^2);
subplot(2,2,4);stem(n,parabola);
xlabel('discrete time n-->');ylabel('amplitude-->');
title('unit parabolic sequence');
%%
%% Program 1.2::generation of a discrete-time exponential sequence
clc;close all;clear all;
n=-10:1:10;
% % for 0<a<1
a=0.8;
x1=a.^n;
subplot(2,2,1);stem(n,x1);
title('x1(n)for 0<a<1');
%for a>1
a=1.5;
x2=a.^n;
subplot(2,2,2);stem(n,x2);
title('x2(n)for a>1');
%for -1<s<0
a=-0.8;
x3=a.^n;
subplot(2,2,3);stem(n,x3);
title('x3(n)for -1<a<0');
%for a<-1
a=-1.2;
x4=a.^n;
subplot(2,2,4);stem(n,x4);
title('x4(n)for a<-1');
xlabel('samples n');ylabel('sample amplitude')
%%
%% program 1.3::multiplication of discrete-time signals
clc;close all;clear all;
% % x1(n)=6*a^n;
n=0:0.1:5;
a=2;
x1=6*(a.^n);
subplot(3,1,1);stem(n,x1);
title('x1(n)');
% % x2(n)=2*cos(wn)
f=1.2;
x2=2*cos(2*pi*f*n);
subplot(3,1,2); stem(n,x2);
title('x2(n)');
%multiplicatin of two sequences
y=x1.*x2;
subplot(3,1,3); stem(n,y);
xlabel('time n');ylabel('amplitude');
title('y(n)');
%%
%% program 1.4:: even and odd components of the sequence y(n)=u(n)-u(n-10)
n=-15:1:15;
y1=[zeros(1,15),ones(1,10),zeros(1,6)];
y2=fliplr(y1);
ye=0.5*(y1+y2);
yo=0.5*(y1-y2);
subplot(2,2,1);stem(n,y1);
xlabel('time-->');ylabel('amplitude-->');
title('y(n)');
subplot(2,2,2);stem(n,y2);
xlabel('time-->');ylabel('amplitude-->');
title('y(-n)');
subplot(2,2,3);stem(n,ye);
xlabel('time-->');ylabel('amplitude-->');
title('ye(n)');
subplot(2,2,4);stem(n,yo);
xlabel('time-->');ylabel('amplitude-->');
title('yo(n)');
%%
%% program 1.5::generation of the composite sequence x(n)=u(n+3)+5u(n-15)+4u(n+10)
clc;close all;clear all;
n=-20:1:20;
u=[zeros(1,20),ones(1,21)];
u1=[zeros(1,17),ones(1,24)];
u2=[zeros(1,35),ones(1,6)];u2=5*u2;
u3=[zeros(1,10),ones(1,31)];u3=4*u3;
x=u1+u2+u3;
subplot(4,1,1);stem(n,u1);
title('u(n+3)');
subplot(4,1,2);stem(n,u2);
title('5u(n-15)');
subplot(4,1,3);stem(n,u3);
title('4u(n+10)');
subplot(4,1,4);stem(n,x);
title('x(n)');
%%
%% program 1.6 ::generation of swept frequency sinusoidal signal
clc;clear all;close all;
n=0:100;
a=pi/2/100;
b=0;
arg=a*n.*n+b*n;
x=cos(arg);
stem(n,x)
xlabel('discrete time')
ylabel('amplitude')
title('swept-frequency sinusoidal signal')
%%
%% program 1.7::checking the Time-invariance property
clc;clear all;close all;
n=0:40;D=10;
x=3*cos(2*pi*0.1*n)-2*cos(2*pi*0.4*n);
xd=[zeros(1,D) x];
num=[2.2403,2.4908,2.2403];
den=[1,-0.4,0.75];
ic=[0,0];
y=filter(num,den,x,ic);
yd=filter(num,den,xd,ic);
d=y-yd(1+D:41+D);
subplot(3,1,1),stem(n,y);
xlabel('discrete time')
ylabel('amplitude')
title('output y[n]')
subplot(3,1,2),stem(n,yd(1:41));
xlabel('discrete time')
ylabel('amplitude')
title('output due to delayed input')
subplot(3,1,3),stem(n,d);
xlabel('discrete time);ylabel(amplitude')
title('difference signal')
%%
%% program 1.8::computation of impulse response
clc;clear all;close all;
N=40;
num=[2.2403,2.4908,2.2403];
den=[1,-0.4,0.75];
y=impz(num,den,N);
stem(y);
xlabel('discrete time')
ylabel('amplitude')
title('impulse response of the filter')
%%
%% program 1.9::checking the linearity of a system
clc;clear all;close all;
n=0:50;a=2;b=-3;
x1=cos(2*pi*0.1*n);
x2=cos(2*pi*0.4*n);
x=a*x1+b*x2;
num=[2.2403,2.4908,2.2403];
den=[1,-0.4,0.75];
ic=[0,0];
y1=filter(num,den,x1,ic);
y2=filter(num,den,x2,ic);
y=filter(num,den,x,ic);
yt=a*y1+b*y2;
d=y-yt;
subplot(3,1,1);stem(n,y);
xlabel('discrete time')
ylabel('amplitude')
title('output due to weighted input')
subplot(3,1,2);stem(n,yt);
xlabel('discrete time')
ylabel('amplitude')
title('weighted output')
subplot(3,1,3);stem(n,d);
xlabel('discrete time')
ylabel('amplitude')
title('difference signal')
%%
%% program 1.10 :: testing the stability of a system
clc;clear all;close all;
num=[1,-0.8];
den=[1,1.5,0.9];
N=200;
h=impz(num,den,N+1);
parsum=0;
for k=N+1
parsum=parsum+abs(h(k));
if abs(h(k))<10^(-6)
break
end
end
stem(h);
xlabel('discrete time')
ylabel('amplitude')
disp('value=')
disp(abs(h(k)
Experiment 2
STUDY OF LINEAR AND CIRCULAR CONVOLUTION
% % Experiment 2
% % Convolution and Correlation
Markoni Chapara
% % Date: 24/09/2021
%% Program 2.1::Convolution of two sequences
clc;clear all;close all;
x1=[1 2 0 1];
x2=[2 2 1 1];
y=conv(x1,x2);
disp('The convolution output is')
disp(y)
subplot(3,1,1),stem(x1);
xlabel('Discrete Time')
ylabel('Amplitude')
title('First input Sequence')
subplot(3,1,2),stem(x2);
xlabel('Discrete Time')
ylabel('Amplitude')
title('Second input Sequence')
subplot(3,1,3),stem(y);
xlabel('Discrete Time')
ylabel('Amplitude')
title('Convolution output')
%% Program 2.2::Linear Convolution via Circular Convolution
clc;clear all;close all;
x1=[1 2 3 4 5];
x2=[2 2 0 1 1];
x1e=[x1 zeros(1,length(x2)-1)];
x2e=[x2 zeros(1,length(x1)-1)];
ylin=cconv(x1e,x2e,length(x1e));
disp('Linear convolution via Circular Convolution')
disp(ylin)
y=conv(x1,x2);
disp('Direct convolution')
disp(y)
%% Program 2.3::Linear Convolution using DFT
clc;clear all;close all;
x=[1 2];
h=[2 1];
x1=[x zeros(1,length(h)-1)];
h1=[h zeros(1,length(x)-1)];
X=fft(x1);
H=fft(h1);
y=X.*H;
y1=ifft(y);
disp('Linear convolution of given sequence')
disp(y1)
%% Program 2.4::Circular Convolution using DFT based approach
clc;clear all;close all;
x1=[1 2 0 1];
x2=[2 2 1 1];
d4=[1 1 1 1;1 -j -1 j;1 -1 1 -1;1 j -1 -j];
x11=d4*x1';
x21=d4*x2';
X=x11.*x21;
x=conj((d4)*X/4);
disp('Circular convolution by using DFT method')
disp(x)
x3=cconv(x1,x2,4);
disp('Circular convolution by using time domain method')
disp(x3)
EXPERIMENT – 3: study of auto and cross correlation
%% Program 2.5::Computation of Correlation
clc;clear all;close all;
x1=[1 3 0 4];
y=xcorr(x1,x1);
subplot(2,1,1),stem(x1);
xlabel('Discrete Time')
ylabel('Amplitude')
title('input sequence')
subplot(2,1,2),stem(y);
title('Autocorrelation of input sequence')
xlabel('Discrete Time')
ylabel('Amplitude')
%% Program 2.6::Computation of Cross Correlation
Experiment 4
Study of fourier series
% % Experiment 3
% % 3A-FOURIER TRANSFORM
% % 3B-PROPERTIES OF DTFT
% % 3C-DFT
Markoni Chapara
% % Date: 24/09/2021
%generation of square wave
clc;
clear all;
close all;
x2=0:pi/64:25*pi;
f1=0;
for n=1:1:2000;
f1=f1+((2/(pi*n))*(-((-1)^n)+1)*sin(n*x2));
end
plot(x2,f1);
%generation of full wave rectifier output
clc;
clear all;
close all;
x=0:pi/64:5*pi;
f1=0;
for n=2:2:1000;
f1=f1+((-4/(pi*((n^2)-1)))*cos(n*x));
end
f=f1+(2/pi);
plot(x,f)
xlabel('x-->')
ylabel('Amplitude-->')
title('Full wave rectified signal')
%generation of Sawtooth wave
clc;
clear all;
close all;
x2=0:pi/64:25*pi;
f1=0;
for n=1:1:2000;
f1=f1+(-2/(pi*n))*((-1)^n)*(sin(n*x2));
end
plot(x2,f1);
Experiment 5
study of DTFT and its Properties
%Evaluation and plotting of DTFT of transfer function of the form a=e^(-jw)
%h(e)=[1+2*a^(-1)]/[1-0.2*a^(-1)]
clc;clear all;close all;
w=-2*pi:8*pi/511:2*pi;
num=[1 2];den=[1 -0.2];
h=freqz(num,den,w);
subplot(2,1,1);plot(w/pi,real(h));
xlabel('Normalized frequency')
ylabel('Amplitude')
title('Real part of transfer function')
subplot(2,1,2);plot(w/pi,imag(h));
xlabel('Normalized frequency')
ylabel('Amplitude')
title('Imaginary part of transfer function')
figure;
subplot(2,1,1);plot(w/pi,abs(h));
xlabel('Normalized frequency')
ylabel('Amplitude')
title('Magnitude spectrum of transfer function')
subplot(2,1,2);plot(w/pi,angle(h));
xlabel('Normalized frequency')
ylabel('phase')
title('phase of transfer function')
%Time shifting property of DTFT
clc;clear all;close all;
w=-pi:2*pi/255:pi;
d=10;num=1:15;
h1=freqz(num,1,w);
a=[zeros(1,d) num];
h2=freqz(a,1,w);
subplot(2,1,1);plot(w/pi,abs(h1));
xlabel('Normalized frequency')
ylabel('Amplitude')
title('Magnitude spectrum of the original sequence')
subplot(2,1,2);plot(w/pi,abs(h2));
xlabel('Normalized frequency')
ylabel('Amplitude')
title('Magnitude spectrum of the time shifted sequence')
figure;
subplot(2,1,1);plot(w/pi,angle(h1));
xlabel('Normalized frequency')
ylabel('phase')
title('Phase spectrum of the original sequence')
subplot(2,1,2);plot(w/pi,angle(h2));
xlabel('Normalized frequency')
ylabel('phase')
title('phase spectrum of the time shifted sequence')
%Frequency shifting property of DTFT
clc;clear all;close all;
w=-pi:2*pi/255:pi;
wo=0.2*pi;
num1=[1 3 5 7 5 11 13 17 18 21 12];
l=length(num1);
h1=freqz(num1,1,w);
n=0:l-1;
num2=exp(wo*i*n).*num1;
h2=freqz(num2,1,w);
subplot(2,1,1);plot(w/pi,abs(h1));
xlabel('Normalized frequency')
ylabel('Amplitude')
title('Magnitude spectrum of the original sequence')
subplot(2,1,2);plot(w/pi,abs(h2));
xlabel('Normalized frequency')
ylabel('Amplitude')
title('Magnitude spectrum of the frequency shifted sequence')
figure;
subplot(2,1,1);plot(w/pi,angle(h1));
xlabel('Normalized frequency')
ylabel('phase')
title('Phase spectrum of the original sequence')
subplot(2,1,2);plot(w/pi,angle(h2));
xlabel('Normalized frequency')
ylabel('phase')
title('phase spectrum of the frequency shifted sequence')
%Time Convolution property of DTFT
clc;clear all;close all;
w=-2*pi:2*pi/255:2*pi;
x1=[1 3 5 7 5 11 13 17 18 21 12];
x2=[1 -2 3 -2 1];
y=conv(x1,x2);
h1=freqz(x1,1,w);
h2=freqz(x2,1,w);
h=h1.*h2;
h3=freqz(y,1,w);
subplot(2,1,1);plot(w/pi,abs(h));
xlabel('Normalized frequency')
ylabel('Amplitude')
title('Magnitude spectrum of the product sequence')
subplot(2,1,2);plot(w/pi,abs(h3));
xlabel('Normalized frequency')
ylabel('Amplitude')
title('Magnitude spectrum of the time convolved sequence')
figure;
subplot(2,1,1);plot(w/pi,angle(h));
xlabel('Normalized frequency')
ylabel('phase')
title('Phase spectrum of the product sequence')
subplot(2,1,2);plot(w/pi,angle(h3));
xlabel('Normalized frequency')
ylabel('phase')
title('phase spectrum of the time convolved sequence')
%Time reversal property of DTFT
clc;clear all;close all;
w=-2*pi:2*pi/255:2*pi;
num=[1 2 3 4 5 6];
l=length(num)-1;
h1=freqz(num,1,w);
h2=freqz(fliplr(num),1,w);
h3=exp(w*l*i).*h2;
subplot(2,1,1);plot(w/pi,abs(h1));
xlabel('Normalized frequency')
ylabel('Amplitude')
title('Magnitude spectrum of the original sequence')
subplot(2,1,2);plot(w/pi,abs(h3));
xlabel('Normalized frequency')
ylabel('Amplitude')
title('Magnitude spectrum of the time reversed sequence')
figure;
subplot(2,1,1);plot(w/pi,angle(h1));
xlabel('Normalized frequency')
ylabel('phase')
title('Phase spectrum of the original sequence')
subplot(2,1,2);plot(w/pi,angle(h3));
xlabel('Normalized frequency')
ylabel('phase')
title('phase spectrum of the time reversed sequence')
Experiment 6
study of DFT and its Properties
%%3c-1 Direct computation of dft
clc;
clear all;
close all;
x=input('Enter the values of x\n')
l=length(x);
for k=0:1:l-1;
Y(k+1)=0;
for n=0:1:l-1;
Y(k+1)=Y(k+1)+(x(n+1)*exp(-(i*2*pi*n*k)/l));
end
fprintf('X(%i)=%g+%gj\n',k,real(Y(k+1)),imag(Y(k+1)))
end
subplot(3,1,1);
stem(x,'fill');
xlabel('Sampling instants(n)');
ylabel('Amplitude');
title('Computation of DFT');
subplot(3,1,2);
stem(abs(Y),'fill');
xlabel('Sampling instants(n)');
ylabel('magnitude');
title('Magnitude');
subplot(3,1,3);
stem(angle(Y),'fill');
xlabel('Sampling instants(n)');
ylabel('angle');
title('Angle');
%%3c-2 Linearity of a DFT signal
clc;
clear all;
close all;
f1=0.1;
f2=0.4;
n=-15:0.25:15;
x1=cos(2*pi*f1*n);
x2=cos(2*pi*f2*n);
y1=fft(x1);
y2=fft(x2);
y3=y1+y2;
x3=x1+x2;
y4=fft(x3);
subplot(6,1,1);
stem(n,x1,'fill');
xlabel('Sampling instants');
ylabel('Amplitude');
title('x1');
subplot(6,1,2);
stem(n,x2,'fill');
xlabel('Sampling instants');
ylabel('Amplitude');
title('x2');
subplot(6,1,3);
stem(n,y1,'fill');
xlabel('Sampling instants');
ylabel('Amplitude');
title('fft(x1)');
subplot(6,1,4);
stem(n,y2,'fill');
xlabel('Sampling instants');
ylabel('Amplitude');
title('fft(x2)');
subplot(6,1,5);
stem(n,y3,'fill');
xlabel('Sampling instants');
ylabel('Amplitude');
title('y3=fft(x1)+fft(x2)');
subplot(6,1,6);
stem(n,y4,'fill');
xlabel('Sampling instants');
ylabel('Amplitude');
title('y4=fft(x1+x2)');
%%3c-3 Circular convolution using FFT
x1=[1 2 1 2]
x2=[4 3 2 1]
z1=fft(x1).*fft(x2)
x3=ifft(z1)
subplot(221)
stem(x1,'fill')
xlabel('Sampling instants(n)-->')
ylabel('Amplitude-->')
title('x1')
subplot(222)
stem(x2,'fill')
xlabel('Sampling instants(n)-->')
ylabel('Amplitude-->')
title('x2')
subplot(223)
stem(x3,'fill')
xlabel('Sampling instants(n)-->')
ylabel('Amplitude-->')
title('Using DFT')
z2=cconv(x1,x2,4)
subplot(224)
stem(z2,'fill')
xlabel('Sampling instants(n)-->')
ylabel('Amplitude-->')
title('Circular convolution')
%%3c-4 Parseval%s theorem
clc
clear all
close all
x=input('Enter the values of x\n');
l=length(x);
Y=0;
for n=0:1:l-1
c=abs(x(n+1));
Y=Y+(c)^2;
end
fprintf('Energy in time domain=%i\n',Y)
f=fft(x);
Z1=0;
for k=0:1:l-1
d=abs(f(k+1));
Z1=Z1+(d)^2;
end
Z=Z1/l;
fprintf('Energy in frequency domain=%i\n',Z)
%%3c-5 Circular time shifting of DFT
clc
clear all
close all
N = input('Enter the value of N for circular shift: ');
m = input('Enter the shift count: ');
x1 = input('Enter the signal\n');
x = [x1 zeros(1,N-length(x1))];
n = (0:N-1);
k = (0:N-1);
n1 = mod(n-m,N);
y = x(n1+1);
w = exp(-1i*2*pi*m/N);
g = w.^(k);
subplot(321);
stem(n,x,'fill');
title('Input sequence');
subplot(322);
stem(n,y,'fill');
title('Circular shifted sequence');
subplot(323);
stem(fft(x),'fill');
title('FFT of input sequence');
subplot(324);
stem(fft(y),'fill');
title('FFT of circular shifted sequence');
subplot(325);
stem(g.*fft(x),'fill');
title('X(k)*exp(-2*pi*m*k/N)');
subplot(326);
stem(n,ifft(g.*fft(x)),'fill');
title('IFFT to verify sequence');
Experiment 7
IIR FILTERS
% % EXPERIMENT 4
% % DESIGN OF BUTTERWORTH AND CHEBYSHEV FLITERS
Markoni Chapara
% % Date: 22/10/2020
%Program-1 Butterworth low-pass filter
clc; clear all; close all;
alphas = 30;% pass band attenuation in dB
alphap = 0.5; % stop band attenuation in dB
fpass=1000; % pass band frequen cy in Hz
fstop=1500; % stop band frequency in Hz
fsam=5000; % sampling frequency in Hz
wp=2*fpass/fsam;
ws=2*fstop/fsam; % pass band and stop band frequencies
[n,wn] = buttord(wp,ws,alphap,alphas); % minimal order, half-power frequency
[b,a] = butter(n,wn); % coefficients of designed filter
[h,w] = freqz(b,a);
subplot(2,1,1);
plot(w/pi,20*log10(abs(h)));
xlabel('Normalized Frequency')
ylabel('gain in db')
title('magnitude response')
subplot(2,1,2);
plot(w/pi,angle(h));
xlabel('Normalized Frequency')
title('phase response')
%%Program-2 Butterworth high-pass filter
clc; clear all; close all;
alphas = 50; % pass band attenuation in dB
alphap= 1; % stop band attenuation in dB
fp=1050; % pass band frequency in Hz
fs=600; % stop band frequency in Hz
fsam=3500; % sampling frequency in Hz
wp=2*fp/fsam;
ws=2*fs/fsam;
[n,wn] = buttord(wp,ws,alphap,alphas); % minimal order, half-power frequency
[b,a] = butter(n,wn,'high'); % coefficients of the designed filter
[h,w] = freqz(b,a)
subplot(2,1,1), plot(w/pi,20*log10(abs(h)));
xlabel('Normalized Frequency')
ylabel('gain in db')
title('magnitude response')
subplot(2,1,2),plot(w/pi,angle(h));
xlabel('Normalized Frequency')
title('phase response')
%%Program-3 Butterworth band stop filter
clc; clear all; close all;
ws=[0.4 0.6]; % stop band frequency in radians
wp=[0.3 0.7]; % pass band frequency in radians
alphap=0.4; % pass band attenuation in dB
alphas=50; % stop band attenuation in dB
[n,wn] = buttord(wp,ws,alphap,alphas);
[b,a]=butter(n,wn,'stop');
[h,w] = freqz(b,a);
subplot(2,1,1);
plot(w/pi,20*log10(abs(h)));
xlabel('Normalized Frequency')
ylabel('gain in db')
title('magnitude response')
subplot(2,1,2);
plot(w/pi,angle(h));
xlabel('Normalized Frequency')
title('phase response')
%%Program-4 Chebyshev filter low-pass type-1
clc; clear all; close all;
alphap=0.15; % pass band attenuation in dB
alphas=0.9; % stop band attenuation in dB
wp=0.3*pi; % pass band frequency in radians
ws=0.5*pi; % stop band frequency in radians
[n,wn]=cheb1ord(wp/pi,ws/pi,alphap,alphas);
[b,a] = cheby1(n,alphap,wn); % coefficients of designed filter
[h,w] = freqz(b,a);
subplot(2,1,1);
plot(w/pi,20*log10(abs(h)));
xlabel('Normalized Frequency')
ylabel('gain in db')
title('magnitude response')
subplot(2,1,2);
plot(w/pi,angle(h));
xlabel('Normalized Frequency')
title('phase response')
%%Program-5 Chebyshev filter high-pass type-1
clc; clear all; close all;
alphap=1; % pass band attenuation in dB
alphas=15; % stop band attenuation in dB
wp=0.3*pi; % pass band frequency in radians
ws=0.2*pi; % stop band frequency in radians
[n,wn]=cheb1ord(wp/pi,ws/pi,alphap,alphas);
[b,a] = cheby1(n,alphap,wn,'high'); % coefficients of designed filter
[h,w] = freqz(b,a);
subplot(2,1,1);
plot(w/pi,20*log10(abs(h)));
xlabel('Normalized Frequency');
ylabel('gain in db');
title('magnitude response');
subplot(2,1,2);
plot(w/pi,angle(h));
xlabel('Normalized Frequency')
title('phase response')
%%Program-6 Chebyshev band pass filter type-1
clc; clear all; close all;
Wp = [60 200]/500;
Ws = [50 250]/500;
alphap = 3; % pass band attenuation in dB
alphas = 40; % stop band attenuation in dB
[n,Wp] = cheb1ord(Wp,Ws,alphap,alphas);
[b,a] = cheby1(n,alphap,Wp);
[h,w] = freqz(b,a);
subplot(2,1,1);
plot(w/pi,20*log10(abs(h)));
xlabel('Normalized Frequency')
ylabel('gain in db')
title('magnitude response')
subplot(2,1,2);
plot(w/pi,angle(h));
xlabel('Normalized Frequency')
title('phase response')
%%Program-7 Chebyshev low-pass filter type-2
clc; clear all; close all;
Wp = 40 /500; % pass band frequency in radians
Ws = 150/500; % stop band frequency in radians
alphap = 3; % pass band attenuation in dB
alphas = 60; % stop band attenuation in dB
[n,Ws] = cheb2ord(Wp,Ws,alphap,alphas);
[b,a] = cheby2(n,alphas,Ws);
[h,w]=freqz(b,a);
subplot(2,1,1)
plot(w/pi,20*log10(abs(h)));
xlabel('Normalized Frequency')
ylabel('gain in db')
title('magnitude response')
subplot(2,1,2),plot(w/pi,angle(h));
xlabel('Normalized Frequency')
title('phase response')
%%Program-8 Chebyshev band pass filter type-2
clc; clear all; close all;
Wp = [60 200]/500; % pass band frequency in radians
Ws = [50 250]/500; % stop band frequency in radians
alphap = 3; % pass band attenuation in dB
alphas = 40; % stop band attenuation in dB
[n,Ws] = cheb2ord(Wp,Ws,alphap,alphas);
[b,a] = cheby2(n,alphas,Ws);
[h,w]=freqz(b,a);
subplot(2,1,1);
plot(w/pi,20*log10(abs(h)));
xlabel('Normalized Frequency');
ylabel('gain in db');
title('magnitude response');
subplot(2,1,2);
plot(w/pi,angle(h));
xlabel('Normalized Frequency')
title('phase response')
Experiment 8
FIR FILTERS
% % EXPERIMENT -5
% % FIR FILTER
Markoni Chapara
% % Date: 12/11/2021
% Program-1:Response of high pass filter using rectangular window
clc;close all;clear all;
n=20;
fp=100;
fq=300;
fs=1000;
fn=2*fp/fs;
window=rectwin(n+1);
b=fir1(n,fn,'high',window);
w=0:0.001:pi;
[h,om]=freqz(b,1,w);
a=20*log10(abs(h));b=angle(h);
subplot(2,1,1);plot(w/pi,a);
xlabel('Normalized frequency');
ylabel('Gain in dB');
title('Magnitude plot');
subplot(2,1,2);plot(w/pi,b);
xlabel('Normalized frequency');
title('Phase response');
% Program-2:Response of low pass filter using rectangular window
clc;close all;clear all;
n=20;
fp=100;
fs=1000;
fn=2*fp/fs;
window=bartlett(n+1);
b=fir1(n,fn,window);
w=0:0.001:pi;
[h,om]=freqz(b,1,w);
a=20*log10(abs(h));b=angle(h);
subplot(2,1,1);plot(w/pi,a);
xlabel('Normalized frequency');
ylabel('Gain in dB');
title('Magnitude plot');
subplot(2,1,2);plot(w/pi,b);
xlabel('Normalized frequency');
title('Phase response');
% Program-3:Response of Band stop FIR filter using hamming window
clc;close all;clear all;
n=20;
fp=200;
fq=300;
fs=1000;
wp=2*fp/fs;
ws=2*fq/fs;
wn=[wp ws];
window=hamming(n+1);
b=fir1(n,wn,'stop',window);
w=0:0.001:pi;
[h,om]=freqz(b,1,w);
a=20*log10(abs(h));b=angle(h);
subplot(2,1,1);plot(w/pi,a);
xlabel('Normalized frequency');
ylabel('Gain in dB');
title('Magnitude plot');
subplot(2,1,2);plot(w/pi,b);
xlabel('Normalized frequency');
title('Phase response');
% Program-4:Response of low pass FIR filter using hamming window
clc;close all;clear all;
n=20;
fp=200;
fs=1000;
fn=2*fp/fs;
window=hamming(n+1);
b=fir1(n,fn,'high',window);
w=0:0.001:pi;
[h,om]=freqz(b,1,w);
a=20*log10(abs(h));b=angle(h);
subplot(2,1,1);plot(w/pi,a);
xlabel('Normalized frequency');
ylabel('Gain in dB');
title('Magnitude plot');
subplot(2,1,2);plot(w/pi,b);
xlabel('Normalized frequency');
title('Phase response');
% Program-5:Response of low pass FIR filter using Blackman window
clc;close all;clear all;
n=20;
fp=200;
fs=1000;
fn=2*fp/fs;
window=blackman(n+1);
b=fir1(n,fn,window);
w=0:0.001:pi;
[h,om]=freqz(b,1,w);
a=20*log10(abs(h));
b=angle(h);
subplot(2,1,1);plot(w/pi,a);
xlabel('Normalized frequency');
ylabel('Gain in dB');
title('Magnitude plot');
subplot(2,1,2);plot(w/pi,b);
xlabel('Normalized frequency');
title('Phase response');
% Program-6.Response of band pass FIR filter using Kaiser window
clc; clear all; close all;
fs = 20000; % sampling rate
F = [3000 4000 6000 8000]; % band limits
A = [0 1 0]; % band type: 0='stop', 1='pass'
dev = [0.0001 0.01 0.0001]; % ripple/attenuation specifications
[M,Wn,beta,typ] = kaiserord(F,A,dev,fs); % window parameters
b = fir1(M,Wn,typ,kaiser(M+1,beta),'noscale'); % filter design
w=0:0.001:pi;
[h,om]=freqz(b,1,w);
a=20*log10(abs(h));
b=angle(h);
subplot(2,1,1),plot(w/pi,a);
xlabel('Normalized frequency')
ylabel('Gain in db')
title('magnitude plot')
subplot(2,1,2),plot(w/pi,b);
xlabel('Normalized frequency')
title('Phase Response')
EXPERIMENT-9
% Program-7.Response of low-pass FIR filter using frequency sampling method
clc; clear all; close all
N=20;
alpha=(N-1)/2;
k=0:N-1;
wk = (2*pi /N)*k;
Hr = [1,1,1,zeros(1,15),1,1]; %Ideal Amp Res sampled
Hd = [1,1,0,0];
wdl = [0,0.25,0.25,1]; %Ideal Amp Res for plott ng
k1 = 0:floor((N-1)/2);
k2 = floor((N-1)/2)+1:N-1;
angH = [-alpha*(2*pi )/N*k1, alpha*(2*pi)/N*(N-k2)];
H = Hr.*exp(j*angH);
h = real(ifft(H,N));
[h1,w] = freqz(h,1);
M = length(h);
L = M/2;
b = 2*[h(L:-1:1)];
n = [1:1:L];
n = n-0.5;
w = [0:1:500]'*pi /500;
Hr1 = cos(w*n)*b';
[h1,w] = freqz(h,1);
subplot(2,2,1),stem(Hr);
title('frequency samples')
subplot(2,2,2),stem(k,h);
title('impulse response')
subplot(2,2,3),plot(Hr1);
title('amplitude response')
subplot(2,2,4),plot(20*log10(abs(h1)));
title('magnitude response')
Experiment 10
STUDY OF UPSAMPLER & DOWN SAMPLER
% % EXPERIMENT -6
% % STUDY OF UPSAMPLER & DOWN SAMPLER
Markoni Chapara
% % Date: 22/11/2021
%%1.Down Sampling by an integer factor
clc; clear all; close all;
n = 0: 49;
m = 0: 50*3 - 1;
x = sin(2*pi*0.042*m);
y = x([1 : 3 : length(x)]);
subplot(2,1,1),stem(n, x(1:50));
axis([0 50 -1.2 1.21]);
xlabel('Time index n');
ylabel('Amplitude');
title('lnput Sequence');
subplot(2,1,2),stem(n, y);
axis([0 50 -1.2 1.21]);
xlabel('Time index n');
ylabel('Amplitude');
title('Downsampled Sequence');
%2.Up-Sampling by an integer factor
clc; clear all; close all;
n = 0:50;
x = sin(2*pi*0.12*n);
y = zeros(1, 3*length(x));
y([1: 3: length(y)]) = x;
subplot(2,1,1),stem(n,x);
xlabel('Time index n');
ylabel('Amplitude');
title('lnput Sequence');
subplot(2,1,2),stem(n,y(1:length(x)));
xlabel('Time index n');
ylabel('Amplitude');
title('Up-sampled sequence ');
%3.Sampling Rate alteration by a ratio of two Integers
clc;
clear all;
close all;
L = 3; %Up-sampling factor
M = 2; %Down-sampling factor
n = 0:29;
x = sin(2*pi*0.43*n) + sin(2*pi*0.31*n);
y = resample(x,L,M);
subplot(2,1,1),stem(n,x(1:30));
xlabel('Time index n');
ylabel('Amplitude');
title('lnput Sequence');
m = 0:(30*L/M)-1;
subplot(2,1,2),stem(m,y(1:30*L/M));
axis([0 (30*L/M)-1 -2.2 2.21]);
xlabel('Time index n');
ylabel('Amplitude');
title('Output Sequence');
%4.Interpolation and Decimation operations on the given signal
clc; clear all; close all; t=0:0.01:0.5;
x=1.5*cos(2*pi*50*t);
y=interp(x,4);
y1=decimate(x,4);
subplot(3,1,1),stem(x);
xlabel('Discrete time')
ylabel('Amplitude')
title('lnput sequence') ;
subplot(3,1,2),stem(y);
xlabel('Discrete time');
ylabel('Amplitude');
title('lnterpolated output of the input sequence') ;
subplot(3,1,3),stem(y1);
xlabel('Discrete time')
ylabel('Amplitude')
title('Decimated output of the input sequence')

My Self on 7 Dec 2021
%% Generation of signals
%%Unit impluse
clc; clear all; close all;
n=-10:1:10;
y = [zeros(1,10), ones(1,1), zeros(1,10)];
subplot(221); stem(n,y);
ylabel('Amplitude'); xlabel('n');
% % Unit step
%N = input('enter value of N');
N=10;
n = 0:1:N-1;
y1 = ones(1,N);
subplot(222); plot(n,y1);
ylabel('Amplitude'); xlabel('n');
% % Generation of ramp signal
%n1 = input('enter value of n1');
n1=10;
n = 0:n1;
subplot(223); stem(n,n);
ylabel('Amplitude'); xlabel('n');
% % Generation of Expoential Signal
%n2 = input('enter value of n2');
n2=10;
n = 0:n2;
%a = input('enter value of a');
a=0.5;
y2 = exp(-a*n);
subplot(224); stem(n,y2);
ylabel('Amplitude'); xlabel('n');
% % Generation of sine wave
n = 0:0.01:pi;
y = sin (2*pi*n);
y1= cos(2*pi*n);
figure;
subplot(411); stem(n,y,'b');
ylabel('Amplitude'); xlabel('n');
%hold on;
subplot(412); stem(n,y1,'k');
ylabel('Amplitude'); xlabel('n');
z=y+y1; %hold on;
subplot(413); stem(n,z,'r');
ylabel('Amplitude'); xlabel('n');
% % Generation of sine wave
n = 0:0.01:pi;
y = cos (2*pi*n);
subplot(414); stem(n,y);
ylabel('Amplitude'); xlabel('n');
% % Problems-1: Generation of signum signal
%N = input('enter value of N');
N=10; n = -(N-1):1:N-1;
y1 = [-1*ones(1,N-1), ones(1,N)];
figure, %subplot(221);
stem(n,y1); ylabel('Amplitude'); xlabel('n');
% % Problems-2: Generation two sided expoential signal
n = 10; a = 0.1;
n1 = 0:n; n2 =-n:0;
y1 = exp(a*n1); y2 = exp((-a)*n2);
figure, subplot(221); stem(n1,y1); subplot(222); stem(n2,y2);
ylabel('Amplitude'); xlabel('n');
n3 = [-n:1:n];
y3 = [y2, zeros(1,n)];
subplot(223); stem(n3,y3);
n4 = [-n:1:n];
y4 = [zeros(1,n),y1];
subplot(224); stem(n4,y4);
n5 = n4;
y5 = y3 + y4;
figure, stem(n5,y5);
%%
%% program 1.1::generation of elementary signals in discrete-time
clc;close all;clear all;
% % unit impulse sequence
n=-10:1:10;
impulse =[zeros(1,10),ones(1,1),zeros(1,10)];
subplot(2,2,1);stem(n,impulse);
xlabel('discrete time n-->');ylabel('amplitude-->');
title('unit impulse sequence');
axis([-10,10,0,1.2]);
% %unit step sequence
n = -10:1:10;
step = [zeros(1,10),ones(1,11)];
subplot(2,2,2); stem(n,step);
xlabel('discrete time n-->');ylabel('amplitude-->');
title('unit step sequence');
%axis([-10,10,0,1.2]);
% %unit ramp sequence
n=0:1:10;
ramp=n;
subplot(2,2,3);stem(n,ramp);
xlabel('discrete time n-->');ylabel('amplitude-->');
title('unit ramp sequence');
% %unit parabolic sequence
n=0:1:10;
parabola=0.5*(n.^2);
subplot(2,2,4);stem(n,parabola);
xlabel('discrete time n-->');ylabel('amplitude-->');
title('unit parabolic sequence');
%%
%% Program 1.2::generation of a discrete-time exponential sequence
clc;close all;clear all;
n=-10:1:10;
% % for 0<a<1
a=0.8;
x1=a.^n;
subplot(2,2,1);stem(n,x1);
title('x1(n)for 0<a<1');
%for a>1
a=1.5;
x2=a.^n;
subplot(2,2,2);stem(n,x2);
title('x2(n)for a>1');
%for -1<s<0
a=-0.8;
x3=a.^n;
subplot(2,2,3);stem(n,x3);
title('x3(n)for -1<a<0');
%for a<-1
a=-1.2;
x4=a.^n;
subplot(2,2,4);stem(n,x4);
title('x4(n)for a<-1');
xlabel('samples n');ylabel('sample amplitude')
%%
%% program 1.3::multiplication of discrete-time signals
clc;close all;clear all;
% % x1(n)=6*a^n;
n=0:0.1:5;
a=2;
x1=6*(a.^n);
subplot(3,1,1);stem(n,x1);
title('x1(n)');
% % x2(n)=2*cos(wn)
f=1.2;
x2=2*cos(2*pi*f*n);
subplot(3,1,2); stem(n,x2);
title('x2(n)');
%multiplicatin of two sequences
y=x1.*x2;
subplot(3,1,3); stem(n,y);
xlabel('time n');ylabel('amplitude');
title('y(n)');
%%
%% program 1.4:: even and odd components of the sequence y(n)=u(n)-u(n-10)
n=-15:1:15;
y1=[zeros(1,15),ones(1,10),zeros(1,6)];
y2=fliplr(y1);
ye=0.5*(y1+y2);
yo=0.5*(y1-y2);
subplot(2,2,1);stem(n,y1);
xlabel('time-->');ylabel('amplitude-->');
title('y(n)');
subplot(2,2,2);stem(n,y2);
xlabel('time-->');ylabel('amplitude-->');
title('y(-n)');
subplot(2,2,3);stem(n,ye);
xlabel('time-->');ylabel('amplitude-->');
title('ye(n)');
subplot(2,2,4);stem(n,yo);
xlabel('time-->');ylabel('amplitude-->');
title('yo(n)');
%%
%% program 1.5::generation of the composite sequence x(n)=u(n+3)+5u(n-15)+4u(n+10)
clc;close all;clear all;
n=-20:1:20;
u=[zeros(1,20),ones(1,21)];
u1=[zeros(1,17),ones(1,24)];
u2=[zeros(1,35),ones(1,6)];u2=5*u2;
u3=[zeros(1,10),ones(1,31)];u3=4*u3;
x=u1+u2+u3;
subplot(4,1,1);stem(n,u1);
title('u(n+3)');
subplot(4,1,2);stem(n,u2);
title('5u(n-15)');
subplot(4,1,3);stem(n,u3);
title('4u(n+10)');
subplot(4,1,4);stem(n,x);
title('x(n)');
%%
%% program 1.6 ::generation of swept frequency sinusoidal signal
clc;clear all;close all;
n=0:100;
a=pi/2/100;
b=0;
arg=a*n.*n+b*n;
x=cos(arg);
stem(n,x)
xlabel('discrete time')
ylabel('amplitude')
title('swept-frequency sinusoidal signal')
%%
%% program 1.7::checking the Time-invariance property
clc;clear all;close all;
n=0:40;D=10;
x=3*cos(2*pi*0.1*n)-2*cos(2*pi*0.4*n);
xd=[zeros(1,D) x];
num=[2.2403,2.4908,2.2403];
den=[1,-0.4,0.75];
ic=[0,0];
y=filter(num,den,x,ic);
yd=filter(num,den,xd,ic);
d=y-yd(1+D:41+D);
subplot(3,1,1),stem(n,y);
xlabel('discrete time')
ylabel('amplitude')
title('output y[n]')
subplot(3,1,2),stem(n,yd(1:41));
xlabel('discrete time')
ylabel('amplitude')
title('output due to delayed input')
subplot(3,1,3),stem(n,d);
xlabel('discrete time);ylabel(amplitude')
title('difference signal')
%%
%% program 1.8::computation of impulse response
clc;clear all;close all;
N=40;
num=[2.2403,2.4908,2.2403];
den=[1,-0.4,0.75];
y=impz(num,den,N);
stem(y);
xlabel('discrete time')
ylabel('amplitude')
title('impulse response of the filter')
%%
%% program 1.9::checking the linearity of a system
clc;clear all;close all;
n=0:50;a=2;b=-3;
x1=cos(2*pi*0.1*n);
x2=cos(2*pi*0.4*n);
x=a*x1+b*x2;
num=[2.2403,2.4908,2.2403];
den=[1,-0.4,0.75];
ic=[0,0];
y1=filter(num,den,x1,ic);
y2=filter(num,den,x2,ic);
y=filter(num,den,x,ic);
yt=a*y1+b*y2;
d=y-yt;
subplot(3,1,1);stem(n,y);
xlabel('discrete time')
ylabel('amplitude')
title('output due to weighted input')
subplot(3,1,2);stem(n,yt);
xlabel('discrete time')
ylabel('amplitude')
title('weighted output')
subplot(3,1,3);stem(n,d);
xlabel('discrete time')
ylabel('amplitude')
title('difference signal')
%%
%% program 1.10 :: testing the stability of a system
clc;clear all;close all;
num=[1,-0.8];
den=[1,1.5,0.9];
N=200;
h=impz(num,den,N+1);
parsum=0;
for k=N+1
parsum=parsum+abs(h(k));
if abs(h(k))<10^(-6)
break
end
end
stem(h);
xlabel('discrete time')
ylabel('amplitude')
disp('value=')
disp(abs(h(k)
Experiment 2
STUDY OF LINEAR AND CIRCULAR CONVOLUTION
ThemeCopy
ThemeCopy
% % Experiment 2
% % Convolution and Correlation
Markoni Chapara
% % Date: 24/09/2021
%% Program 2.1::Convolution of two sequences
clc;clear all;close all;
x1=[1 2 0 1];
x2=[2 2 1 1];
y=conv(x1,x2);
disp('The convolution output is')
disp(y)
subplot(3,1,1),stem(x1);
xlabel('Discrete Time')
ylabel('Amplitude')
title('First input Sequence')
subplot(3,1,2),stem(x2);
xlabel('Discrete Time')
ylabel('Amplitude')
title('Second input Sequence')
subplot(3,1,3),stem(y);
xlabel('Discrete Time')
ylabel('Amplitude')
title('Convolution output')
%% Program 2.2::Linear Convolution via Circular Convolution
clc;clear all;close all;
x1=[1 2 3 4 5];
x2=[2 2 0 1 1];
x1e=[x1 zeros(1,length(x2)-1)];
x2e=[x2 zeros(1,length(x1)-1)];
ylin=cconv(x1e,x2e,length(x1e));
disp('Linear convolution via Circular Convolution')
disp(ylin)
y=conv(x1,x2);
disp('Direct convolution')
disp(y)
%% Program 2.3::Linear Convolution using DFT
clc;clear all;close all;
x=[1 2];
h=[2 1];
x1=[x zeros(1,length(h)-1)];
h1=[h zeros(1,length(x)-1)];
X=fft(x1);
H=fft(h1);
y=X.*H;
y1=ifft(y);
disp('Linear convolution of given sequence')
disp(y1)
%% Program 2.4::Circular Convolution using DFT based approach
clc;clear all;close all;
x1=[1 2 0 1];
x2=[2 2 1 1];
d4=[1 1 1 1;1 -j -1 j;1 -1 1 -1;1 j -1 -j];
x11=d4*x1';
x21=d4*x2';
X=x11.*x21;
x=conj((d4)*X/4);
disp('Circular convolution by using DFT method')
disp(x)
x3=cconv(x1,x2,4);
disp('Circular convolution by using time domain method')
disp(x3)
EXPERIMENT – 3: study of auto and cross correlation
ThemeCopy
ThemeCopy
%% Program 2.5::Computation of Correlation
clc;clear all;close all;
x1=[1 3 0 4];
y=xcorr(x1,x1);
subplot(2,1,1),stem(x1);
xlabel('Discrete Time')
ylabel('Amplitude')
title('input sequence')
subplot(2,1,2),stem(y);
title('Autocorrelation of input sequence')
xlabel('Discrete Time')
ylabel('Amplitude')
%% Program 2.6::Computation of Cross Correlation
Experiment 4
Study of fourier series
ThemeCopy
ThemeCopy
% % Experiment 3
% % 3A-FOURIER TRANSFORM
% % 3B-PROPERTIES OF DTFT
% % 3C-DFT
Markoni Chapara
% % Date: 24/09/2021
%generation of square wave
clc;
clear all;
close all;
x2=0:pi/64:25*pi;
f1=0;
for n=1:1:2000;
f1=f1+((2/(pi*n))*(-((-1)^n)+1)*sin(n*x2));
end
plot(x2,f1);
%generation of full wave rectifier output
clc;
clear all;
close all;
x=0:pi/64:5*pi;
f1=0;
for n=2:2:1000;
f1=f1+((-4/(pi*((n^2)-1)))*cos(n*x));
end
f=f1+(2/pi);
plot(x,f)
xlabel('x-->')
ylabel('Amplitude-->')
title('Full wave rectified signal')
%generation of Sawtooth wave
clc;
clear all;
close all;
x2=0:pi/64:25*pi;
f1=0;
for n=1:1:2000;
f1=f1+(-2/(pi*n))*((-1)^n)*(sin(n*x2));
end
plot(x2,f1);
Experiment 5
study of DTFT and its Properties
ThemeCopy
ThemeCopy
%Evaluation and plotting of DTFT of transfer function of the form a=e^(-jw)
%h(e)=[1+2*a^(-1)]/[1-0.2*a^(-1)]
clc;clear all;close all;
w=-2*pi:8*pi/511:2*pi;
num=[1 2];den=[1 -0.2];
h=freqz(num,den,w);
subplot(2,1,1);plot(w/pi,real(h));
xlabel('Normalized frequency')
ylabel('Amplitude')
title('Real part of transfer function')
subplot(2,1,2);plot(w/pi,imag(h));
xlabel('Normalized frequency')
ylabel('Amplitude')
title('Imaginary part of transfer function')
figure;
subplot(2,1,1);plot(w/pi,abs(h));
xlabel('Normalized frequency')
ylabel('Amplitude')
title('Magnitude spectrum of transfer function')
subplot(2,1,2);plot(w/pi,angle(h));
xlabel('Normalized frequency')
ylabel('phase')
title('phase of transfer function')
%Time shifting property of DTFT
clc;clear all;close all;
w=-pi:2*pi/255:pi;
d=10;num=1:15;
h1=freqz(num,1,w);
a=[zeros(1,d) num];
h2=freqz(a,1,w);
subplot(2,1,1);plot(w/pi,abs(h1));
xlabel('Normalized frequency')
ylabel('Amplitude')
title('Magnitude spectrum of the original sequence')
subplot(2,1,2);plot(w/pi,abs(h2));
xlabel('Normalized frequency')
ylabel('Amplitude')
title('Magnitude spectrum of the time shifted sequence')
figure;
subplot(2,1,1);plot(w/pi,angle(h1));
xlabel('Normalized frequency')
ylabel('phase')
title('Phase spectrum of the original sequence')
subplot(2,1,2);plot(w/pi,angle(h2));
xlabel('Normalized frequency')
ylabel('phase')
title('phase spectrum of the time shifted sequence')
%Frequency shifting property of DTFT
clc;clear all;close all;
w=-pi:2*pi/255:pi;
wo=0.2*pi;
num1=[1 3 5 7 5 11 13 17 18 21 12];
l=length(num1);
h1=freqz(num1,1,w);
n=0:l-1;
num2=exp(wo*i*n).*num1;
h2=freqz(num2,1,w);
subplot(2,1,1);plot(w/pi,abs(h1));
xlabel('Normalized frequency')
ylabel('Amplitude')
title('Magnitude spectrum of the original sequence')
subplot(2,1,2);plot(w/pi,abs(h2));
xlabel('Normalized frequency')
ylabel('Amplitude')
title('Magnitude spectrum of the frequency shifted sequence')
figure;
subplot(2,1,1);plot(w/pi,angle(h1));
xlabel('Normalized frequency')
ylabel('phase')
title('Phase spectrum of the original sequence')
subplot(2,1,2);plot(w/pi,angle(h2));
xlabel('Normalized frequency')
ylabel('phase')
title('phase spectrum of the frequency shifted sequence')
%Time Convolution property of DTFT
clc;clear all;close all;
w=-2*pi:2*pi/255:2*pi;
x1=[1 3 5 7 5 11 13 17 18 21 12];
x2=[1 -2 3 -2 1];
y=conv(x1,x2);
h1=freqz(x1,1,w);
h2=freqz(x2,1,w);
h=h1.*h2;
h3=freqz(y,1,w);
subplot(2,1,1);plot(w/pi,abs(h));
xlabel('Normalized frequency')
ylabel('Amplitude')
title('Magnitude spectrum of the product sequence')
subplot(2,1,2);plot(w/pi,abs(h3));
xlabel('Normalized frequency')
ylabel('Amplitude')
title('Magnitude spectrum of the time convolved sequence')
figure;
subplot(2,1,1);plot(w/pi,angle(h));
xlabel('Normalized frequency')
ylabel('phase')
title('Phase spectrum of the product sequence')
subplot(2,1,2);plot(w/pi,angle(h3));
xlabel('Normalized frequency')
ylabel('phase')
title('phase spectrum of the time convolved sequence')
%Time reversal property of DTFT
clc;clear all;close all;
w=-2*pi:2*pi/255:2*pi;
num=[1 2 3 4 5 6];
l=length(num)-1;
h1=freqz(num,1,w);
h2=freqz(fliplr(num),1,w);
h3=exp(w*l*i).*h2;
subplot(2,1,1);plot(w/pi,abs(h1));
xlabel('Normalized frequency')
ylabel('Amplitude')
title('Magnitude spectrum of the original sequence')
subplot(2,1,2);plot(w/pi,abs(h3));
xlabel('Normalized frequency')
ylabel('Amplitude')
title('Magnitude spectrum of the time reversed sequence')
figure;
subplot(2,1,1);plot(w/pi,angle(h1));
xlabel('Normalized frequency')
ylabel('phase')
title('Phase spectrum of the original sequence')
subplot(2,1,2);plot(w/pi,angle(h3));
xlabel('Normalized frequency')
ylabel('phase')
title('phase spectrum of the time reversed sequence')
Experiment 6
study of DFT and its Properties
%%3c-1 Direct computation of dft
clc;
clear all;
close all;
x=input('Enter the values of x\n')
l=length(x);
for k=0:1:l-1;
Y(k+1)=0;
for n=0:1:l-1;
Y(k+1)=Y(k+1)+(x(n+1)*exp(-(i*2*pi*n*k)/l));
end
fprintf('X(%i)=%g+%gj\n',k,real(Y(k+1)),imag(Y(k+1)))
end
subplot(3,1,1);
stem(x,'fill');
xlabel('Sampling instants(n)');
ylabel('Amplitude');
title('Computation of DFT');
subplot(3,1,2);
stem(abs(Y),'fill');
xlabel('Sampling instants(n)');
ylabel('magnitude');
title('Magnitude');
subplot(3,1,3);
stem(angle(Y),'fill');
xlabel('Sampling instants(n)');
ylabel('angle');
title('Angle');
%%3c-2 Linearity of a DFT signal
clc;
clear all;
close all;
f1=0.1;
f2=0.4;
n=-15:0.25:15;
x1=cos(2*pi*f1*n);
x2=cos(2*pi*f2*n);
y1=fft(x1);
y2=fft(x2);
y3=y1+y2;
x3=x1+x2;
y4=fft(x3);
subplot(6,1,1);
stem(n,x1,'fill');
xlabel('Sampling instants');
ylabel('Amplitude');
title('x1');
subplot(6,1,2);
stem(n,x2,'fill');
xlabel('Sampling instants');
ylabel('Amplitude');
title('x2');
subplot(6,1,3);
stem(n,y1,'fill');
xlabel('Sampling instants');
ylabel('Amplitude');
title('fft(x1)');
subplot(6,1,4);
stem(n,y2,'fill');
xlabel('Sampling instants');
ylabel('Amplitude');
title('fft(x2)');
subplot(6,1,5);
stem(n,y3,'fill');
xlabel('Sampling instants');
ylabel('Amplitude');
title('y3=fft(x1)+fft(x2)');
subplot(6,1,6);
stem(n,y4,'fill');
xlabel('Sampling instants');
ylabel('Amplitude');
title('y4=fft(x1+x2)');
%%3c-3 Circular convolution using FFT
x1=[1 2 1 2]
x2=[4 3 2 1]
z1=fft(x1).*fft(x2)
x3=ifft(z1)
subplot(221)
stem(x1,'fill')
xlabel('Sampling instants(n)-->')
ylabel('Amplitude-->')
title('x1')
subplot(222)
stem(x2,'fill')
xlabel('Sampling instants(n)-->')
ylabel('Amplitude-->')
title('x2')
subplot(223)
stem(x3,'fill')
xlabel('Sampling instants(n)-->')
ylabel('Amplitude-->')
title('Using DFT')
z2=cconv(x1,x2,4)
subplot(224)
stem(z2,'fill')
xlabel('Sampling instants(n)-->')
ylabel('Amplitude-->')
title('Circular convolution')
%%3c-4 Parseval%s theorem
clc
clear all
close all
x=input('Enter the values of x\n');
l=length(x);
Y=0;
for n=0:1:l-1
c=abs(x(n+1));
Y=Y+(c)^2;
end
fprintf('Energy in time domain=%i\n',Y)
f=fft(x);
Z1=0;
for k=0:1:l-1
d=abs(f(k+1));
Z1=Z1+(d)^2;
end
Z=Z1/l;
fprintf('Energy in frequency domain=%i\n',Z)
%%3c-5 Circular time shifting of DFT
clc
clear all
close all
N = input('Enter the value of N for circular shift: ');
m = input('Enter the shift count: ');
x1 = input('Enter the signal\n');
x = [x1 zeros(1,N-length(x1))];
n = (0:N-1);
k = (0:N-1);
n1 = mod(n-m,N);
y = x(n1+1);
w = exp(-1i*2*pi*m/N);
g = w.^(k);
subplot(321);
stem(n,x,'fill');
title('Input sequence');
subplot(322);
stem(n,y,'fill');
title('Circular shifted sequence');
subplot(323);
stem(fft(x),'fill');
title('FFT of input sequence');
subplot(324);
stem(fft(y),'fill');
title('FFT of circular shifted sequence');
subplot(325);
stem(g.*fft(x),'fill');
title('X(k)*exp(-2*pi*m*k/N)');
subplot(326);
stem(n,ifft(g.*fft(x)),'fill');
title('IFFT to verify sequence');
Experiment 7
IIR FILTERS
% % EXPERIMENT 4
% % DESIGN OF BUTTERWORTH AND CHEBYSHEV FLITERS
Markoni Chapara
% % Date: 22/10/2021
%Program-1 Butterworth low-pass filter
clc; clear all; close all;
alphas = 30;% pass band attenuation in dB
alphap = 0.5; % stop band attenuation in dB
fpass=1000; % pass band frequency in Hz
fstop=1500; % stop band frequency in Hz
fsam=5000; % sampling frequency in Hz
wp=2*fpass/fsam;
ws=2*fstop/fsam; % pass band and stop band frequencies
[n,wn] = buttord(wp,ws,alphap,alphas); % minimal order, half-power frequency
[b,a] = butter(n,wn); % coefficients of designed filter
[h,w] = freqz(b,a);
subplot(2,1,1);
plot(w/pi,20*log10(abs(h)));
xlabel('Normalized Frequency')
ylabel('gain in db')
title('magnitude response')
subplot(2,1,2);
plot(w/pi,angle(h));
xlabel('Normalized Frequency')
title('phase response')
%%Program-2 Butterworth high-pass filter
clc; clear all; close all;
alphas = 50; % pass band attenuation in dB
alphap= 1; % stop band attenuation in dB
fp=1050; % pass band frequency in Hz
fs=600; % stop band frequency in Hz
fsam=3500; % sampling frequency in Hz
wp=2*fp/fsam;
ws=2*fs/fsam;
[n,wn] = buttord(wp,ws,alphap,alphas); % minimal order, half-power frequency
[b,a] = butter(n,wn,'high'); % coefficients of the designed filter
[h,w] = freqz(b,a)
subplot(2,1,1), plot(w/pi,20*log10(abs(h)));
xlabel('Normalized Frequency')
ylabel('gain in db')
title('magnitude response')
subplot(2,1,2),plot(w/pi,angle(h));
xlabel('Normalized Frequency')
title('phase response')
%%Program-3 Butterworth band stop filter
clc; clear all; close all;
ws=[0.4 0.6]; % stop band frequency in radians
wp=[0.3 0.7]; % pass band frequency in radians
alphap=0.4; % pass band attenuation in dB
alphas=50; % stop band attenuation in dB
[n,wn] = buttord(wp,ws,alphap,alphas);
[b,a]=butter(n,wn,'stop');
[h,w] = freqz(b,a);
subplot(2,1,1);
plot(w/pi,20*log10(abs(h)));
xlabel('Normalized Frequency')
ylabel('gain in db')
title('magnitude response')
subplot(2,1,2);
plot(w/pi,angle(h));
xlabel('Normalized Frequency')
title('phase response')
%%Program-4 Chebyshev filter low-pass type-1
clc; clear all; close all;
alphap=0.15; % pass band attenuation in dB
alphas=0.9; % stop band attenuation in dB
wp=0.3*pi; % pass band frequency in radians
ws=0.5*pi; % stop band frequency in radians
[n,wn]=cheb1ord(wp/pi,ws/pi,alphap,alphas);
[b,a] = cheby1(n,alphap,wn); % coefficients of designed filter
[h,w] = freqz(b,a);
subplot(2,1,1);
plot(w/pi,20*log10(abs(h)));
xlabel('Normalized Frequency')
ylabel('gain in db')
title('magnitude response')
subplot(2,1,2);
plot(w/pi,angle(h));
xlabel('Normalized Frequency')
title('phase response')
%%Program-5 Chebyshev filter high-pass type-1
clc; clear all; close all;
alphap=1; % pass band attenuation in dB
alphas=15; % stop band attenuation in dB
wp=0.3*pi; % pass band frequency in radians
ws=0.2*pi; % stop band frequency in radians
[n,wn]=cheb1ord(wp/pi,ws/pi,alphap,alphas);
[b,a] = cheby1(n,alphap,wn,'high'); % coefficients of designed filter
[h,w] = freqz(b,a);
subplot(2,1,1);
plot(w/pi,20*log10(abs(h)));
xlabel('Normalized Frequency');
ylabel('gain in db');
title('magnitude response');
subplot(2,1,2);
plot(w/pi,angle(h));
xlabel('Normalized Frequency')
title('phase response')
%%Program-6 Chebyshev band pass filter type-1
clc; clear all; close all;
Wp = [60 200]/500;
Ws = [50 250]/500;
alphap = 3; % pass band attenuation in dB
alphas = 40; % stop band attenuation in dB
[n,Wp] = cheb1ord(Wp,Ws,alphap,alphas);
[b,a] = cheby1(n,alphap,Wp);
[h,w] = freqz(b,a);
subplot(2,1,1);
plot(w/pi,20*log10(abs(h)));
xlabel('Normalized Frequency')
ylabel('gain in db')
title('magnitude response')
subplot(2,1,2);
plot(w/pi,angle(h));
xlabel('Normalized Frequency')
title('phase response')
%%Program-7 Chebyshev low-pass filter type-2
clc; clear all; close all;
Wp = 40 /500; % pass band frequency in radians
Ws = 150/500; % stop band frequency in radians
alphap = 3; % pass band attenuation in dB
alphas = 60; % stop band attenuation in dB
[n,Ws] = cheb2ord(Wp,Ws,alphap,alphas);
[b,a] = cheby2(n,alphas,Ws);
[h,w]=freqz(b,a);
subplot(2,1,1)
plot(w/pi,20*log10(abs(h)));
xlabel('Normalized Frequency')
ylabel('gain in db')
title('magnitude response')
subplot(2,1,2),plot(w/pi,angle(h));
xlabel('Normalized Frequency')
title('phase response')
%%Program-8 Chebyshev band pass filter type-2
clc; clear all; close all;
Wp = [60 200]/500; % pass band frequency in radians
Ws = [50 250]/500; % stop band frequency in radians
alphap = 3; % pass band attenuation in dB
alphas = 40; % stop band attenuation in dB
[n,Ws] = cheb2ord(Wp,Ws,alphap,alphas);
[b,a] = cheby2(n,alphas,Ws);
[h,w]=freqz(b,a);
subplot(2,1,1);
plot(w/pi,20*log10(abs(h)));
xlabel('Normalized Frequency');
ylabel('gain in db');
title('magnitude response');
subplot(2,1,2);
plot(w/pi,angle(h));
xlabel('Normalized Frequency')
title('phase response')
Experiment 8
FIR FILTERS
% % EXPERIMENT -5
% % FIR FILTER
Markoni Chapara
% % Date: 12/11/2021
% Program-1:Response of high pass filter using rectangular window
clc;close all;clear all;
n=20;
fp=100;
fq=300;
fs=1000;
fn=2*fp/fs;
window=rectwin(n+1);
b=fir1(n,fn,'high',window);
w=0:0.001:pi;
[h,om]=freqz(b,1,w);
a=20*log10(abs(h));b=angle(h);
subplot(2,1,1);plot(w/pi,a);
xlabel('Normalized frequency');
ylabel('Gain in dB');
title('Magnitude plot');
subplot(2,1,2);plot(w/pi,b);
xlabel('Normalized frequency');
title('Phase response');
% Program-2:Response of low pass filter using rectangular window
clc;close all;clear all;
n=20;
fp=100;
fs=1000;
fn=2*fp/fs;
window=bartlett(n+1);
b=fir1(n,fn,window);
w=0:0.001:pi;
[h,om]=freqz(b,1,w);
a=20*log10(abs(h));b=angle(h);
subplot(2,1,1);plot(w/pi,a);
xlabel('Normalized frequency');
ylabel('Gain in dB');
title('Magnitude plot');
subplot(2,1,2);plot(w/pi,b);
xlabel('Normalized frequency');
title('Phase response');
% Program-3:Response of Band stop FIR filter using hamming window
clc;close all;clear all;
n=20;
fp=200;
fq=300;
fs=1000;
wp=2*fp/fs;
ws=2*fq/fs;
wn=[wp ws];
window=hamming(n+1);
b=fir1(n,wn,'stop',window);
w=0:0.001:pi;
[h,om]=freqz(b,1,w);
a=20*log10(abs(h));b=angle(h);
subplot(2,1,1);plot(w/pi,a);
xlabel('Normalized frequency');
ylabel('Gain in dB');
title('Magnitude plot');
subplot(2,1,2);plot(w/pi,b);
xlabel('Normalized frequency');
title('Phase response');
% Program-4:Response of low pass FIR filter using hamming window
clc;close all;clear all;
n=20;
fp=200;
fs=1000;
fn=2*fp/fs;
window=hamming(n+1);
b=fir1(n,fn,'high',window);
w=0:0.001:pi;
[h,om]=freqz(b,1,w);
a=20*log10(abs(h));b=angle(h);
subplot(2,1,1);plot(w/pi,a);
xlabel('Normalized frequency');
ylabel('Gain in dB');
title('Magnitude plot');
subplot(2,1,2);plot(w/pi,b);
xlabel('Normalized frequency');
title('Phase response');
% Program-5:Response of low pass FIR filter using Blackman window
clc;close all;clear all;
n=20;
fp=200;
fs=1000;
fn=2*fp/fs;
window=blackman(n+1);
b=fir1(n,fn,window);
w=0:0.001:pi;
[h,om]=freqz(b,1,w);
a=20*log10(abs(h));
b=angle(h);
subplot(2,1,1);plot(w/pi,a);
xlabel('Normalized frequency');
ylabel('Gain in dB');
title('Magnitude plot');
subplot(2,1,2);plot(w/pi,b);
xlabel('Normalized frequency');
title('Phase response');
% Program-6.Response of band pass FIR filter using Kaiser window
clc; clear all; close all;
fs = 20000; % sampling rate
F = [3000 4000 6000 8000]; % band limits
A = [0 1 0]; % band type: 0='stop', 1='pass'
dev = [0.0001 0.01 0.0001]; % ripple/attenuation specifications
[M,Wn,beta,typ] = kaiserord(F,A,dev,fs); % window parameters
b = fir1(M,Wn,typ,kaiser(M+1,beta),'noscale'); % filter design
w=0:0.001:pi;
[h,om]=freqz(b,1,w);
a=20*log10(abs(h));
b=angle(h);
subplot(2,1,1),plot(w/pi,a);
xlabel('Normalized frequency')
ylabel('Gain in db')
title('magnitude plot')
subplot(2,1,2),plot(w/pi,b);
xlabel('Normalized frequency')
title('Phase Response')
EXPERIMENT-9
% Program-7.Response of low-pass FIR filter using frequency sampling method
clc; clear all; close all
N=20;
alpha=(N-1)/2;
k=0:N-1;
wk = (2*pi /N)*k;
Hr = [1,1,1,zeros(1,15),1,1]; %Ideal Amp Res sampled
Hd = [1,1,0,0];
wdl = [0,0.25,0.25,1]; %Ideal Amp Res for plott ng
k1 = 0:floor((N-1)/2);
k2 = floor((N-1)/2)+1:N-1;
angH = [-alpha*(2*pi )/N*k1, alpha*(2*pi)/N*(N-k2)];
H = Hr.*exp(j*angH);
h = real(ifft(H,N));
[h1,w] = freqz(h,1);
M = length(h);
L = M/2;
b = 2*[h(L:-1:1)];
n = [1:1:L];
n = n-0.5;
w = [0:1:500]'*pi /500;
Hr1 = cos(w*n)*b';
[h1,w] = freqz(h,1);
subplot(2,2,1),stem(Hr);
title('frequency samples')
subplot(2,2,2),stem(k,h);
title('impulse response')
subplot(2,2,3),plot(Hr1);
title('amplitude response')
subplot(2,2,4),plot(20*log10(abs(h1)));
title('magnitude response')
Experiment 10
STUDY OF UPSAMPLER & DOWN SAMPLER
% % EXPERIMENT -6
% % STUDY OF UPSAMPLER & DOWN SAMPLER
Markoni Chapara
% % Date: 22/11/2021
%%1.Down Sampling by an integer factor
clc; clear all; close all;
n = 0: 49;
m = 0: 50*3 - 1;
x = sin(2*pi*0.042*m);
y = x([1 : 3 : length(x)]);
subplot(2,1,1),stem(n, x(1:50));
axis([0 50 -1.2 1.21]);
xlabel('Time index n');
ylabel('Amplitude');
title('lnput Sequence');
subplot(2,1,2),stem(n, y);
axis([0 50 -1.2 1.21]);
xlabel('Time index n');
ylabel('Amplitude');
title('Downsampled Sequence');
%2.Up-Sampling by an integer factor
clc; clear all; close all;
n = 0:50;
x = sin(2*pi*0.12*n);
y = zeros(1, 3*length(x));
y([1: 3: length(y)]) = x;
subplot(2,1,1),stem(n,x);
xlabel('Time index n');
ylabel('Amplitude');
title('lnput Sequence');
subplot(2,1,2),stem(n,y(1:length(x)));
xlabel('Time index n');
ylabel('Amplitude');
title('Up-sampled sequence ');
%3.Sampling Rate alteration by a ratio of two Integers
clc;
clear all;
close all;
L = 3; %Up-sampling factor
M = 2; %Down-sampling factor
n = 0:29;
x = sin(2*pi*0.43*n) + sin(2*pi*0.31*n);
y = resample(x,L,M);
subplot(2,1,1),stem(n,x(1:30));
xlabel('Time index n');
ylabel('Amplitude');
title('lnput Sequence');
m = 0:(30*L/M)-1;
subplot(2,1,2),stem(m,y(1:30*L/M));
axis([0 (30*L/M)-1 -2.2 2.21]);
xlabel('Time index n');
ylabel('Amplitude');
title('Output Sequence');
%4.Interpolation and Decimation operations on the given signal
clc; clear all; close all; t=0:0.01:0.5;
x=1.5*cos(2*pi*50*t);
y=interp(x,4);
y1=decimate(x,4);
subplot(3,1,1),stem(x);
xlabel('Discrete time')
ylabel('Amplitude')
title('lnput sequence') ;
subplot(3,1,2),stem(y);
xlabel('Discrete time');
ylabel('Amplitude');
title('lnterpolated output of the input sequence') ;
subplot(3,1,3),stem(y1);
xlabel('Discrete time')
ylabel('Amplitude')
title('Decimated output of the input sequence')

Love Sehra on 9 Dec 2021
IFR filters transform a vector of numbers into another, where each point in the output is a weighted sum of a finite number of points from the input, For each point of the output, the input points are taken from a moving window related to the current output point's position, just like a moving average.

JIM HAWKINSON on 10 Dec 2021
i hope you are referring to Finite impulse response.