DSP Programs

LOW PASS FILTER (Kaiser Window) :
clc;
clear all;
close all;
rp=input('Enter the Pass Band Ripple : ');
rs=input('Enter the Stop Band Ripple : ');
fp=input('Enter the Pass Band Frequency (Hz) : ');
fs=input('Enter the Stop Band Frequency (Hz) : ');
f=input('Enter the Sampling Frequency (Hz) : ');
beta=input('Enter the Beta Value : ');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
den=14.6*(fs-fp)/f;
n=ceil(num/den);
n1=n+1;
if(rem(n,2)~=0)
    n1=n;
    n=n-1;
end
y=kaiser(n1,beta);
b=fir1(n,wp,y);
[h o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(1,1,1);
plot(o/pi,m);
ylabel('Gain in dB ---->');
xlabel('Normalized Frequency ---->');

Result :
Enter the Pass Band Ripple : 0.02
Enter the Stop Band Ripple : 0.01
Enter the Pass Band Frequency (Hz) : 1000
Enter the Stop Band Frequency (Hz) : 1500
Enter the Sampling Frequency (Hz) : 10000
Enter the Beta Value : 5.8

HIGH PASS FILTER (Kaiser Window) :
clc;
clear all;
close all;
rp=input('Enter the Pass Band Ripple : ');
rs=input('Enter the Stop Band Ripple : ');
fp=input('Enter the Pass Band Frequency (Hz) : ');
fs=input('Enter the Stop Band Frequency (Hz) : ');
f=input('Enter the Sampling Frequency (Hz) : ');
beta=input('Enter the Beta Value : ');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
den=14.6*(fs-fp)/f;
n=ceil(num/den);
n1=n+1;
if(rem(n,2)~=0)
    n1=n;
    n=n-1;
end
y=kaiser(n1,beta);
b=fir1(n,wp,'high',y);
[h o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(1,1,1);
plot(o/pi,m);
ylabel('Gain in dB ---->');
xlabel('Normalized Frequency ---->');

Result :
 Enter the Pass Band Ripple : 0.02
Enter the Stop Band Ripple : 0.01
Enter the Pass Band Frequency (Hz) : 1000
Enter the Stop Band Frequency (Hz) : 1500
Enter the Sampling Frequency (Hz) : 10000
Enter the Beta Value : 5.8


BAND PASS FILTER (Kaiser Window) :
 clc;
clear all;
close all;
rp=input('Enter the Pass Band Ripple : ');
rs=input('Enter the Stop Band Ripple : ');
fp=input('Enter the Pass Band Frequency (Hz) : ');
fs=input('Enter the Stop Band Frequency (Hz) : ');
f=input('Enter the Sampling Frequency (Hz) : ');
beta=input('Enter the Beta Value : ');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
den=14.6*(fs-fp)/f;
n=ceil(num/den);
n1=n+1;
if(rem(n,2)~=0)
    n1=n;
    n=n-1;
end
y=kaiser(n1,beta);
wn=[wp ws]
b=fir1(n,wn,y);
[h o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(1,1,1);
plot(o/pi,m);
ylabel('Gain in dB ---->');
xlabel('Normalized Frequency ---->'); 

 Result :
Enter the Pass Band Ripple : 0.02
Enter the Stop Band Ripple : 0.01
Enter the Pass Band Frequency (Hz) : 1000
Enter the Stop Band Frequency (Hz) : 1500
Enter the Sampling Frequency (Hz) : 10000
Enter the Beta Value : 5.8
 wn = 0.2000          0.3000

  
BAND STOP FILTER (Kaiser Window) :
 clc;
clear all;
close all;
rp=input('Enter the Pass Band Ripple : ');
rs=input('Enter the Stop Band Ripple : ');
fp=input('Enter the Pass Band Frequency (Hz) : ');
fs=input('Enter the Stop Band Frequency (Hz) : ');
f=input('Enter the Sampling Frequency (Hz) : ');
beta=input('Enter the Beta Value : ');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
den=14.6*(fs-fp)/f;
n=ceil(num/den);
n1=n+1;
if(rem(n,2)~=0)
    n1=n;
    n=n-1;
end
y=kaiser(n1,beta);
wn=[wp ws]
b=fir1(n,wn,'stop',y);
[h o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(1,1,1);
plot(o/pi,m);
ylabel('Gain in dB ---->');
xlabel('Normalized Frequency ---->');
  
Result :
Enter the Pass Band Ripple : 0.02
Enter the Stop Band Ripple : 0.01
Enter the Pass Band Frequency (Hz) : 1000
Enter the Stop Band Frequency (Hz) : 1500
Enter the Sampling Frequency (Hz) : 10000
Enter the Beta Value : 5.8
 wn =  0.2000          0.3000


 LOW PASS FILTER (Rectangular Window) :
 clc;
clear all;
close all;
rp=input('Enter the Pass Band Ripple : ');
rs=input('Enter the Stop Band Ripple : ');
fp=input('Enter the Pass Band Frequency (Hz) : ');
fs=input('Enter the Stop Band Frequency (Hz) : ');
f=input('Enter the Sampling Frequency (Hz) : ');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
den=14.6*(fs-fp)/f;
n=ceil(num/den);
n1=n+1;
if(rem(n,2)~=0)
    n1=n;
    n=n-1;
end
y=boxcar(n1);
b=fir1(n,wp,y);
[h o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(1,1,1);
plot(o/pi,m);
ylabel('Gain in dB ---->');
xlabel('Normalized Frequency ---->');

Result :
Enter the Pass Band Ripple : 0.05
Enter the Stop Band Ripple : 0.04
Enter the Pass Band Frequency (Hz) : 1500
Enter the Stop Band Frequency (Hz) : 2000
Enter the Sampling Frequency (Hz) : 9000


 HIGH PASS FILTER (Rectangular Window) :
 clc;
clear all;
close all;
rp=input('Enter the Pass Band Ripple : ');
rs=input('Enter the Stop Band Ripple : ');
fp=input('Enter the Pass Band Frequency (Hz) : ');
fs=input('Enter the Stop Band Frequency (Hz) : ');
f=input('Enter the Sampling Frequency (Hz) : ');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
den=14.6*(fs-fp)/f;
n=ceil(num/den);
n1=n+1;
if(rem(n,2)~=0)
    n1=n;
    n=n-1;
end
y=boxcar(n1);
b=fir1(n,wp,'high',y);
[h o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(1,1,1);
plot(o/pi,m);
ylabel('Gain in dB ---->');
xlabel('Normalized Frequency ---->');

Result :
Enter the Pass Band Ripple : 0.05
Enter the Stop Band Ripple : 0.04
Enter the Pass Band Frequency (Hz) : 1500
Enter the Stop Band Frequency (Hz) : 2000
Enter the Sampling Frequency (Hz) : 9000


BAND PASS FILTER (Rectangular Window) :
clc;
clear all;
close all;
rp=input('Enter the Pass Band Ripple : ');
rs=input('Enter the Stop Band Ripple : ');
fp=input('Enter the Pass Band Frequency (Hz) : ');
fs=input('Enter the Stop Band Frequency (Hz) : ');
f=input('Enter the Sampling Frequency (Hz) : ');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
den=14.6*(fs-fp)/f;
n=ceil(num/den);
n1=n+1;
if(rem(n,2)~=0)
    n1=n;
    n=n-1;
end
y=boxcar(n1);
wn=[wp ws]
b=fir1(n,wn,y);
[h o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(1,1,1);
plot(o/pi,m);
ylabel('Gain in dB ---->');
xlabel('Normalized Frequency ---->');

Result :
Enter the Pass Band Ripple : 0.05
Enter the Stop Band Ripple : 0.04
Enter the Pass Band Frequency (Hz) : 1500
Enter the Stop Band Frequency (Hz) : 2000
Enter the Sampling Frequency (Hz) : 9000
wn =    0.3333    0.4444


 BAND STOP FILTER (Rectangular Window) :
 clc;
clear all;
close all;
rp=input('Enter the Pass Band Ripple : ');
rs=input('Enter the Stop Band Ripple : ');
fp=input('Enter the Pass Band Frequency (Hz) : ');
fs=input('Enter the Stop Band Frequency (Hz) : ');
f=input('Enter the Sampling Frequency (Hz) : ');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
den=14.6*(fs-fp)/f;
n=ceil(num/den);
n1=n+1;
if(rem(n,2)~=0)
    n1=n;
    n=n-1;
end
y=boxcar(n1);
wn=[wp ws]
b=fir1(n,wn,'stop',y);
[h o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(1,1,1);
plot(o/pi,m);
ylabel('Gain in dB ---->');
xlabel('Normalized Frequency ---->');

Result :
Enter the Pass Band Ripple : 0.05
Enter the Stop Band Ripple : 0.04
Enter the Pass Band Frequency (Hz) : 1500
Enter the Stop Band Frequency (Hz) : 2000
Enter the Sampling Frequency (Hz) : 9000
 wn =    0.3333    0.4444


LOW PASS FILTER (Hamming Window) :
clc;
clear all;
close all;
rp=input('Enter the Pass Band Ripple : ');
rs=input('Enter the Stop Band Ripple : ');
fp=input('Enter the Pass Band Frequency (Hz) : ');
fs=input('Enter the Stop Band Frequency (Hz) : ');
f=input('Enter the Sampling Frequency (Hz) : ');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
den=14.6*(fs-fp)/f;
n=ceil(num/den);
n1=n+1;
if(rem(n,2)~=0)
    n1=n;
    n=n-1;
end
y=hamming(n1);
b=fir1(n,wp,y);
[h o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(1,1,1);
plot(o/pi,m);
ylabel('Gain in dB ---->');
xlabel('Normalized Frequency ---->');

Result :
Enter the Pass Band Ripple : 0.02
Enter the Stop Band Ripple : 0.01
Enter the Pass Band Frequency (Hz) : 1200
Enter the Stop Band Frequency (Hz) : 1700
Enter the Sampling Frequency (Hz) : 9000


 HIGH PASS FILTER (Hamming Window) :
 clc;
clear all;
close all;
rp=input('Enter the Pass Band Ripple : ');
rs=input('Enter the Stop Band Ripple : ');
fp=input('Enter the Pass Band Frequency (Hz) : ');
fs=input('Enter the Stop Band Frequency (Hz) : ');
f=input('Enter the Sampling Frequency (Hz) : ');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
den=14.6*(fs-fp)/f;
n=ceil(num/den);
n1=n+1;
if(rem(n,2)~=0)
    n1=n;
    n=n-1;
end
y=hamming(n1);
b=fir1(n,wp,'high',y);
[h o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(1,1,1);
plot(o/pi,m);
ylabel('Gain in dB ---->');
xlabel('Normalized Frequency ---->');

Result :
Enter the Pass Band Ripple : 0.02
Enter the Stop Band Ripple : 0.01
Enter the Pass Band Frequency (Hz) : 1200
Enter the Stop Band Frequency (Hz) : 1700
Enter the Sampling Frequency (Hz) : 9000



BAND PASS FILTER (Hamming Window) :
clc;
clear all;
close all;
rp=input('Enter the Pass Band Ripple : ');
rs=input('Enter the Stop Band Ripple : ');
fp=input('Enter the Pass Band Frequency (Hz) : ');
fs=input('Enter the Stop Band Frequency (Hz) : ');
f=input('Enter the Sampling Frequency (Hz) : ');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
den=14.6*(fs-fp)/f;
n=ceil(num/den);
n1=n+1;
if(rem(n,2)~=0)
    n1=n;
    n=n-1;
end
y=hamming(n1);
wn=[wp ws]
b=fir1(n,wn,y);
[h o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(1,1,1);
plot(o/pi,m);
ylabel('Gain in dB ---->');
xlabel('Normalized Frequency ---->');

Result :
Enter the Pass Band Ripple : 0.02
Enter the Stop Band Ripple : 0.01
Enter the Pass Band Frequency (Hz) : 1200
Enter the Stop Band Frequency (Hz) : 1700
Enter the Sampling Frequency (Hz) : 9000
wn =    0.2667    0.3778

  
 BAND STOP FILTER (Hamming Window) :
 clc;
clear all;
close all;
rp=input('Enter the Pass Band Ripple : ');
rs=input('Enter the Stop Band Ripple : ');
fp=input('Enter the Pass Band Frequency (Hz) : ');
fs=input('Enter the Stop Band Frequency (Hz) : ');
f=input('Enter the Sampling Frequency (Hz) : ');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
den=14.6*(fs-fp)/f;
n=ceil(num/den);
n1=n+1;
if(rem(n,2)~=0)
    n1=n;
    n=n-1;
end
y=hamming(n1);
wn=[wp ws]
b=fir1(n,wn,'stop',y);
[h o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(1,1,1);
plot(o/pi,m);
ylabel('Gain in dB ---->');
xlabel('Normalized Frequency ---->');

 Result :
Enter the Pass Band Ripple : 0.02
Enter the Stop Band Ripple : 0.01
Enter the Pass Band Frequency (Hz) : 1200
Enter the Stop Band Frequency (Hz) : 1700
Enter the Sampling Frequency (Hz) : 9000
wn =    0.2667    0.3778









LOW PASS FILTER (Hanning Window) :
 clc;
clear all;
close all;
rp=input('Enter the Pass Band Ripple : ');
rs=input('Enter the Stop Band Ripple : ');
fp=input('Enter the Pass Band Frequency (Hz) : ');
fs=input('Enter the Stop Band Frequency (Hz) : ');
f=input('Enter the Sampling Frequency (Hz) : ');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
den=14.6*(fs-fp)/f;
n=ceil(num/den);
n1=n+1;
if(rem(n,2)~=0)
    n1=n;
    n=n-1;
end
y=hanning(n1);
b=fir1(n,wp,y);
[h o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(1,1,1);
plot(o/pi,m);
ylabel('Gain in dB ---->');
xlabel('Normalized Frequency ---->');

Result :
Enter the Pass Band Ripple : 0.03
Enter the Stop Band Ripple : 0.01
Enter the Pass Band Frequency (Hz) : 1400
Enter the Stop Band Frequency (Hz) : 2000
Enter the Sampling Frequency (Hz) : 8000



HIGH PASS FILTER (Hanning Window) : 
clc;
clear all;
close all;
rp=input('Enter the Pass Band Ripple : ');
rs=input('Enter the Stop Band Ripple : ');
fp=input('Enter the Pass Band Frequency (Hz) : ');
fs=input('Enter the Stop Band Frequency (Hz) : ');
f=input('Enter the Sampling Frequency (Hz) : ');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
den=14.6*(fs-fp)/f;
n=ceil(num/den);
n1=n+1;
if(rem(n,2)~=0)
    n1=n;
    n=n-1;
end
y=hanning(n1);
b=fir1(n,wp,'high',y);
[h o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(1,1,1);
plot(o/pi,m);
ylabel('Gain in dB ---->');
xlabel('Normalized Frequency ---->');

Result :
Enter the Pass Band Ripple : 0.03
Enter the Stop Band Ripple : 0.01
Enter the Pass Band Frequency (Hz) : 1400
Enter the Stop Band Frequency (Hz) : 2000
Enter the Sampling Frequency (Hz) : 8000



BAND PASS FILTER (Hanning Window) : 
clc;
clear all;
close all;
rp=input('Enter the Pass Band Ripple : ');
rs=input('Enter the Stop Band Ripple : ');
fp=input('Enter the Pass Band Frequency (Hz) : ');
fs=input('Enter the Stop Band Frequency (Hz) : ');
f=input('Enter the Sampling Frequency (Hz) : ');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
den=14.6*(fs-fp)/f;
n=ceil(num/den);
n1=n+1;
if(rem(n,2)~=0)
    n1=n;
    n=n-1;
end
y=hanning(n1);
wn=[wp ws]
b=fir1(n,wn,y);
[h o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(1,1,1);
plot(o/pi,m);
ylabel('Gain in dB ---->');
xlabel('Normalized Frequency ---->');

Result :
Enter the Pass Band Ripple : 0.03
Enter the Stop Band Ripple : 0.01
Enter the Pass Band Frequency (Hz) : 1400
Enter the Stop Band Frequency (Hz) : 2000
Enter the Sampling Frequency (Hz) : 8000
wn =    0.3500    0.5000



BAND STOP FILTER (Hanning Window) :
clc;
clear all;
close all;
rp=input('Enter the Pass Band Ripple : ');
rs=input('Enter the Stop Band Ripple : ');
fp=input('Enter the Pass Band Frequency (Hz) : ');
fs=input('Enter the Stop Band Frequency (Hz) : ');
f=input('Enter the Sampling Frequency (Hz) : ');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
den=14.6*(fs-fp)/f;
n=ceil(num/den);
n1=n+1;
if(rem(n,2)~=0)
    n1=n;
    n=n-1;
end
y=hanning(n1);
wn=[wp ws]
b=fir1(n,wn,'stop',y);
[h o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(1,1,1);
plot(o/pi,m);
ylabel('Gain in dB ---->');
xlabel('Normalized Frequency ---->');

Result :
Enter the Pass Band Ripple : 0.03
Enter the Stop Band Ripple : 0.01
Enter the Pass Band Frequency (Hz) : 1400
Enter the Stop Band Frequency (Hz) : 2000
Enter the Sampling Frequency (Hz) : 8000
 wn =    0.3500    0.5000



Program to compute and plot Poles and Zeros, Gian Constant and Partial Fraction Expansion :
 clc;
clear all;
close all;
num=input('Enter the Co-efficients of Numerator of G(Z) : ');
den=input('Enter the Co-efficients of Denomenator of G(Z) : ');
[Z,P,K]=tf2ZP(num,den);
disp(Z);
disp(P);
disp(K);
Zplane(Z,P);
[r,p,k]=residueZ(num,den);
disp(r);
disp(p);
disp(k);
Zk=roots(num);
Pk=roots(den);
  
Result :
 Enter the Co-efficients of Numerator of G(Z) : [2 16 44 56 32]
Enter the Co-efficients of Denomenator of G(Z) : [3 3 -15 18 -12]
  -4.0000         
  -2.0000         
  -1.0000 + 1.0000i
  -1.0000 - 1.0000i

  -3.2361         
   1.2361          
   0.5000 + 0.8660i
   0.5000 - 0.8660i

    0.6667

  -0.0177         
   9.4914         
  -3.0702 + 2.3398i
  -3.0702 - 2.3398i

  -3.2361         
   1.2361         
   0.5000 + 0.8660i
   0.5000 - 0.8660i

   -2.6667




Program to find Inverse Z Transform using Long Division Method :
clc;
clear all;
close all;
num=input('Enter the Co-efficients of Numerator of G(Z) : ');
den=input('Enter the Co-efficients of Denomenator of G(Z) : ');
L=input('Enter the number of required terms : ');
[h,t]=impz(num,den,L);
Zplane(num,den);
disp(h);


Result :
Enter the Co-efficients of Numerator of G(Z) : [18]
Enter the Co-efficients of Denomenator of G(Z) : [18 3 -4 -1]
Enter the number of required terms : 5
    1.0000
   -0.1667
    0.2500
   -0.0231
    0.0502




Program to find the DFT for a given sequence and to find IFFT for a DFT sequence :
clc;
clear all;
close all;
x=input('enter the Input sequence :');
n=input('enter the length :');
m=fft(x,n);
disp(m);
subplot(2,2,1);
stem(x,'*','b');
xlabel('----> n');
ylabel('----> Amplitude');
title('The Input sequence');
disp(real(m));
p=real(m);
subplot(2,2,2);
stem(p,'*','b');
xlabel('----> n');
ylabel('----> Amplitude');
title('The DFT of a given sequence (Real)');
disp(imag(m));
q=imag(m);
subplot(2,2,3);
stem(q,'*','b');
xlabel('----> n');
ylabel('----> Amplitude');
title('The DFT of a given sequence (Imag.)');
yn=ifft(m);
disp(yn);
subplot(2,2,4);
stem(yn,'*','b');
xlabel('----> n');
ylabel('----> Amplitude');
title('The IFFT of DFT sequence');

Result : 
enter the Input sequence : [0 1 2 3] 
enter the length : 4

   6.0000            -2.0000 + 2.0000i  -2.0000            -2.0000 - 2.0000i

     6    -2    -2    -2

     0     2     0    -2

     0     1     2     3








Program to generate Unit Step Sequence :
 clc;
clear all;
close all;
n=input('Enter the n value :');
t=0:1:n-1;
y=ones(1,n);
subplot(1,1,1);
stem(t,y,'*','b');
xlabel('----> n');
ylabel('----> Amplitude');
title('Unit Step Sequence');

Result : 
Enter the n value : 5




Program to generate Ramp Sequence :
clc;
clear all;
close all;
n=input('Enter the n value :');
t=0:n;
subplot(1,1,1);
stem(t,t,'*','b');
xlabel('----> n');
ylabel('----> Amplitude');
title('Ramp Sequence');

Result :
Enter the n value : 5




Program to generate Exponential Sequence :
 clc;
clear all;
close all;
n=input('Enter the n value :');
t=0:n;
a=input('Enter the a value :');
y=exp(t*a);
subplot(1,1,1);
stem(t,y,'*','b');
xlabel('----> n');
ylabel('----> Amplitude');
title('Exponential Sequence');

Result :
Enter the n value : 10
Enter the a value : 2



Program to generate Sinusoidal Wave :
clc;
clear all;
close all;
t=input('Enter the t value :');
t=0:0.01:pi;
y=sin(2*pi*t);
subplot(1,1,1);
plot(t,y);
xlabel('----> t');
ylabel('----> Amplitude');
title('Sinusoidal Wave');

 Result :
 Enter the t value : 5



Program to generate Cosine Wave :
clc;
clear all;
close all;
t=input('Enter the t value :');
t=0:0.01:pi;
y=cos(2*pi*t);
subplot(1,1,1);
plot(t,y);
xlabel('----> t');
ylabel('----> Amplitude');
title('Cosine Wave');

 Result : 
Enter the t value : 5



Program to find Auto Correlation :
clc;
clear all;
close all;
x=input('Enter the value of x : ');
b=xcorr(x,x);
y=abs(b);
subplot(1,1,1);
stem(y,'*','b');
xlabel('----> n');
ylabel('----> Amplitude');
title('Auto Correlation');

Result : 
Enter the value of x : [1 2 3 4]



Program to find Cross Correlation : 
clc;
clear all;
close all;
x=input('Enter the value of x :');
h=input('Enter the value of h :');
b=xcorr(x,h);
y=abs(b);
subplot(1,1,1);
stem(y,'*','b');
xlabel('----> n');
ylabel('----> Amplitude');
title('Cross Correlation');

Result : 
Enter the value of x : [1 2 3 4]
Enter the value of h : [4 3 2 1]



Program to find solution for Differential Equation : 
clc;
clear all;
close all;
disp('Solution for Differential Equation :');
disp('y(n)-3/4y(n-1)+1/8y(n-2)=x(n)-1/3x(n-1)');
b=input('Enter the Co-efficient of x : ');
a=input('Enter the Co-efficient of y : ');
n=input('Enter the length n : ');
xi=[1 2 3 4];
h=filter(b,a,xi);
disp('Solution of Differential Equation is');
disp(h);
n=0:n-1;
stem(n,h);
grid on;
xlabel('----> n');
ylabel('----> y(n)');
title('Solution of Differential Equation');

Result : 
Solution for Differential Equation :
y(n)-3/4y(n-1)+1/8y(n-2)=x(n)-1/3x(n-1)
Enter the Co-efficient of x : [1 -1/3]
Enter the Co-efficient of y : [1 -3/4 1/8]
Enter the length n : 4
Solution of Differential Equation is
    1.0000    2.4167    4.0208    5.7135


  
Program to find solution for Impulse Response :
clc;
clear all;
close all;
disp('Solution for Impulse Response :');
disp('y(n)-3/4y(n-1)+1/8y(n-2)=x(n)-1/3x(n-1)');
b=input('Enter the Co-efficient of x : ');
a=input('Enter the Co-efficient of y : ');
n=input('Enter the length of Impulse n : ');
xi=[1,zeros(1,n-1)];
h=filter(b,a,xi);
disp('Solution of Impulse Response is');
disp(h);
n=0:n-1;
stem(n,h);
grid on;
xlabel('----> n');
ylabel('----> h(n)');
title('Solution of Impulse Response');

Result :
Solution for Impulse Response :
y(n)-3/4y(n-1)+1/8y(n-2)=x(n)-1/3x(n-1)
Enter the Co-efficient of x : [1 -1/3]
Enter the Co-efficient of y : [1 -3/4 1/8]
Enter the length of Impulse n : 8
Solution of Impulse Response is
    1.0000    0.4167    0.1875    0.0885    0.0430    0.0212    0.0105    0.0052



Program to find Linear Convolution of two given sequences : 
clc;
clear all;
close all;
x=input('Enter the 1st Sequence : ');
h=input('Enter the 2nd Sequence : ');
y=conv(x,h);
subplot(2,2,1);
stem([0:length(x)-1],x);
grid on;
xlabel('----> n');
ylabel('----> Amplitude');
title('(a) The 1st Sequence');
subplot(2,2,2);
stem([0:length(h)-1],h);
grid on;
xlabel('----> n');
ylabel('----> Amplitude');
title('(b) The 2nd Sequence');
subplot(2,2,3);
stem([0:length(x)+length(h)-2],y,'b','*');
grid on;
xlabel('----> n');
ylabel('----> Amplitude');
title('(c) The Convolued Sequence');
disp('The resultant Convolued Sequence is');y
  
Result : 
Enter the 1st Sequence : [1 2 3 4]
Enter the 2nd Sequence : [1 2 3 4]
The resultant Convolued Sequence is
 y =     1     4    10    20    25    24    16



Program to find DFT and IFFT for a given sequence : 
clc;
clear all;
close all;
x=input('Enter Input the Sequence : ');
n=input('Enter the Length : ');
m=fft(x,n);
disp(m);
subplot(2,2,1);
stem(x,'*','b');
xlabel('----> n');
ylabel('----> Amplitude');
title('The Input Sequence');
subplot(2,2,2);
stem(m,'*','b');
xlabel('----> n');
ylabel('----> Amplitude');
title('The DFT of a Input Sequence');
yn=ifft(m);
disp(yn);
subplot(2,2,3);
stem(yn,'*','b');
xlabel('----> n');
ylabel('----> Amplitude');
title('The IFFT of DFT Sequence');
  
Result : 
Enter Input the Sequence : [0 1 2 3]
Enter the Length : 4
   6.0000            -2.0000 + 2.0000i  -2.0000            -2.0000 - 2.0000i

     0     1     2     3




Program to find Linear Convolution of two given sequences : 
clc;
clear all;
close all;
x=input('Enter the 1st Sequence : ');
y=input('Enter the 2nd Sequence : ');
p=conv(x,y);
disp(p);
subplot(2,2,1);
stem(x);
xlabel('----> n');
ylabel('----> Amplitude');
title('The 1st Input sequence');
subplot(2,2,2);
stem(y);
xlabel('----> n');
ylabel('----> Amplitude');
title('The 2nd Input sequence');
subplot(2,2,3);
stem(p,'*b');
xlabel('----> n');
ylabel('----> Amplitude');
title('The Convolued Sequence');

Result :
Enter the 1st Sequence : [1 2 3 4]
Enter the 2nd Sequence : [1 2 1 2]
     1     4     8    14    15    10     8
  



Program to find Linear Convolution of two sequences using DFT method:
clc
clear all;
close all;
x=input('Enter the 1st Sequence : ');
y=input('Enter the 2nd Sequence : ');
m=length(x);
n=length(y);
l=m+n-1;
p=fft(x,l);
disp(p);
subplot(2,2,1);
stem(p);
xlabel('----> n');
ylabel('----> Amplitude');
title('The DFT of 1st Sequence');
q=fft(y,l);
disp(q);
subplot(2,2,2);
stem(q);
xlabel('----> n');
ylabel('----> Amplitude');
title('The DFT of 2nd Sequence');
t=p.*q;
yn=ifft(t);
disp(yn);
subplot(2,2,3);
stem(yn);
xlabel('----> n');
ylabel('----> Amplitude');
title('The Linear Convolution of two given Sequences');

Result : 
Enter the 1st Sequence : [1 2 3 4]
Enter the 2nd Sequence : [1 2 1 2]

  10.0000            -2.0245 - 6.2240i   0.3460 + 2.4791i   0.1784 - 2.4220i   0.1784 + 2.4220i   0.3460 - 2.4791i   -2.0245 + 6.2240i

             6.0000             0.2225 - 3.4064i   0.9010 + 0.0477i  -0.6235 - 2.0358i  -0.6235 + 2.0358i   0.9010 - 0.0477i     0.2225 + 3.4064i
     1.0000    4.0000    8.0000   14.0000   15.0000   10.0000    8.0000




Program to find Circular Convolution of two sequences using DFT method: 
clc
clear all;
close all;
x=input('Enter the 1st Sequence : ');
y=input('Enter the 2nd Sequence : ');
m=length(x);
n=length(y);
l=max(m,n);
p=fft(x,l);
disp(p);
subplot(2,2,1);
stem(p);
xlabel('----> n');
ylabel('----> Amplitude');
title('The DFT of 1st Sequence');
q=fft(y,l);
disp(q);
subplot(2,2,2);
stem(q);
xlabel('----> n');
ylabel('----> Amplitude');
title('The DFT of 2nd Sequence');
t=p.*q;
yn=ifft(t);
disp(yn);
subplot(2,2,3);
stem(yn,'*b');
xlabel('----> n');
ylabel('----> Amplitude');
title('The Circular Convolution of two given Sequences');

Result : 
Enter the 1st Sequence : [1 2 3 4]
Enter the 2nd Sequence : [1 2 1 2]
  10.0000            -2.0000 + 2.0000i  -2.0000            -2.0000 - 2.0000i

     6     0    -2     0

    16    14    16    14




LOW PASS FILTER (Butterworth) 
clc;
clear all;
close all;
kp=input('Enter the Pass Band Attenuation in dB : ');
ks=input('Enter the Stop Band Attenuation in dB : ');
fp=input('Enter the Pass Band Frequency in Hz : ');
fs=input('Enter the Stop Band Frequency in Hz : ');
F=input('Enter the Sampling Frequency in Hz : ');
omp=2*fp/F;
oms=2*fs/F;
[n,wn]=buttord(omp,oms,kp,ks);
[b,a]=butter(n,wn);
w=0:0.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(2,2,1);
plot(om/pi,m);
ylabel('Gain in dB ---->');
xlabel('Normalized Frequency ---->');
subplot(2,2,2);
plot(om/pi,an);
ylabel('Phase in Radians ---->');
xlabel('Normalized Frequency ---->');

Result : 
Enter the Pass Band Attenuation in dB : 0.4
Enter the Stop Band Attenuation in dB : 30
Enter the Pass Band Frequency in Hz : 400
Enter the Stop Band Frequency in Hz : 800
Enter the Sampling Frequency in Hz : 2000