Dgital Signal Processing Lab - Manual
Dgital Signal Processing Lab - Manual
MANUAL
LIST OF EXPERMENTS
Experiment No:- 1
%LINEAR CONVOLUTION USING MATLAB
%AIM: - TO write a MATLAB program to compute linear convolution of two given sequences
%PROCEDURE:-
%Open MATLAB
%Open new M-file
%Type the program
%Save in current directory
%Compile and Run the program
%For the output see command window\ Figure window
%ALGORITHM:-
%Read the input sequence x[n] ,and plot
%Read the impulse sequence h[n] , and plot
%Use the matlab function ‘conv’
%Convolve the two sequence and plot the result
%linear convolution
MATLAB CODE:-
clc;
clear all;
close all;
a=input('enter i/p sequance1=');
n1=length(a);
b=input('enter i/p sequence2=');
n2=length(b);
x=0:1:n1-1;
subplot(2,2,1), stem(x,a);
title('i/p sequencce1');
xlabel('---->n');
ylabel('---->a(n)');grid;
y=0:1:n2-1;
subplot(2,2,2), stem(y,b);
title('i/p sequencce2');
xlabel('---->n');
ylabel('---->b(n)');grid;
c=conv(a,b);
disp(c);
disp('o/p c=conv(a,b)is');
n3=0:1:n1+n2-2;
subplot(2,1,2), stem(n3,c);
title('convolution of two sequances');
xlabel('---->n');
ylabel('---->c(n)');
grid;
output
enter i/p sequance1=[2 3 4]
enter i/p sequance2=[1 2 3]
%MATLAB CODE:-
clc;
clear all;
close all;
a=input('Enter the starting point of x[n]=');
b=input('Enter the starting point of h[n]=');
x=input('Enter the co-efficients of x[n]=');
h=input('Enter the co-efficients of h[n]=');
y=conv(x,h);
subplot(3,1,1);
p=a:(a+length(x)-1);
stem(p,x);
grid on;
xlabel('Time');
ylabel('Amplitude');
title('INPUT x(n)');
subplot(3,1,2);
q=b:(b+length(h)-1);
stem(q,h);
grid on;
xlabel('Time');
ylabel('Amplitude');
title('IMPULSE RESPONSE h(n)');
subplot(3,1,3);
n=a+b:length(y)+a+b-1;
stem(n,y);
grid on;
disp(y)
xlabel('Time');
ylabel('Amplitude');
title('LINEAR CONVOLUTION');
%SAMPLE INPUT:--
%Enter the starting point of x(n)=0
%Enter the starting point of h(n)=-1
%Enter the co-efficient of x(n)=[1 2 3]
%Enter the co-efficient of h(n)=[1 1 1]
Experiment No: - 02
CIRCULAR CONVOLUTION
%AIM: - TO write a MATLAB program to compute circular convolution of two given sequences
%PROCEDURE:-
%Open MATLAB
%Open new M-file
%Type the program
%Save in current directory
%Compile and Run the program
%For the output see command window\ Figure window
%ALGORITHM:-
%Read the input sequence x1[n] ,and plot
%Read the input sequence x2[n] , and plot
%Use the user defined matlab function ‘crconc’
%Convolve the two sequence and plot the result
%MATLAB CODE:-
clc;
x=input('enter i/p x(n):');
h=input('enter i/p sequence h(n)');
n1=length(x);
n2=length(h);
n=max(n1,n2);
z=cconv(x,h,n);
subplot(2,2,1),stem(x)
xlabel('n')
ylabel('amplitude')
title('i/p sequance h[n]')
subplot(2,2,2),stem(h)
xlabel('n')
ylabel('amplitude')
title('i/p sequance h[n]')
subplot(2,2,3),stem(z)
xlabel('n')
ylabel('amplitude')
title('o/p z=conv of x[n]&h[n]')
disp(z)
%SAMPLE INPUT:--
%Enter the co-efficients of x1[n]=[1 2 3]
%Enter the co-efficients of x2[n]=[1 2 ]
Experiment No: - 03
DISCRETE FOURIER TRANSFORM
%A, DISCRETE FOURIER TRANSFORM
%AIM: - TO write a MATLAB program to find the DFT of a sequence
%PROCEDURE:-
%Open MATLAB
%Open new M-file
%Type the program
%Save in current directory
%Compile and Run the program
%For the output see command window\ Figure window
%ALGORITHM:-
%Enter the input sequence x[n]
%Enter the length of sequence,N
%Use the matlab function ‘fft’
%Plot the input and output sequence
%MATLAB CODE:-
clc;
clear all;
close all;
N=input('Enter the value of N');
x=input('Enter the input sequence X(n):');
t=0:N-1;
subplot(2,1,1);
stem(t,x);
xlabel('TIME');
ylabel('AMPLITUDE');
title('INPUT SIGNAL');
grid on;
y=fft(x,N)
subplot(2,1,2);
stem(t,y);
xlabel('TIME');
ylabel('AMPLITUDE');
title('OUTPUT SIGNAL');
grid on;
%SAMPLE INPUT:-
%Enter the value of N 4
%Enter the input sequence X(n):[1 2 3 4]
SAMPLE I/PS:-
Howmany point DFT do you want?4
Enter the first sequence=[1 2 3 4]
Enter the second sequence=[4 3 2 1]
Enter the first constant a=1
Enter the second constant b=4
Experment 5
% PROPERTIES OF DISCRETE FOURIER TRANSFORM
%FRQUANCY SHIFT PROPERTY
%AIM: - TO write a MATLAB program to find the frquancy shift proprty of DFT sequence
%PROCEDURE:-
%Open MATLAB
%Open new M-file
%Type the program
%Save in current directory
%Compile and Run the program
%For the output see command window\ Figure window
%ALGORITHM:-
%Enter how many point dft do you want?
%Enter the seq=[]
%enter the amount of shift in frequency domain
%MATLAB CODE:-
close all;
clear all;
N=input('how many point dft do you want?');
x1=input('enter the seq');
n2=length(x1);
c=zeros(N);
x1=[x1 zeros(1,N-n2)];
for k=1:N
for n=1:N
w=exp((-2*pi*i*(k-1)*(n-1))/N);
x(n)=w;
end
c(k,:)=x;
end
disp('dft is ');
r=c*x1';
a1=input('enter the amount of shift in frequency domain');
for n=1:N
w=exp((2*pi*i*(n-1)*(a1))/N);
x2(n)=w;
end
r1=x2.*x1;
subplot(221);
stem(abs(r));
grid on;
title('orginal dft magnitude plot');
subplot(222);
stem(angle(r));
grid on;
title('orginal dft angle');
for k=1:N
for n=1:N
w=exp((-2*pi*i*(k-1)*(n-1))/N);
x(n)=w;
end
c(k,:)=x;
end
disp('dft is');
r2=c*r1';
subplot(223);
stem(abs(r2));
grid on;
title('shifted dft magnitude');
subplot(224);
stem(angle(r2));
grid on;
title('shifed dft angle');
%output
%how many point dft do you want?8
%enter the seq=[1 2 3 4]
%enter the amount of shift in frequency domain4
Experment 6
%A, FIR LOW PASS FILTER USING RECTANGULAR WINDOW
%AIM: - TO write a MATLAB program to plot magnitude response and phase response of digital FIR LP
filter
%using rectangular window
%PROCEDURE:-
% Open MATLAB
%Open new M-file
%Type the program
%Save in current directory
%Compile and Run the program
%For the output see command window\ Figure window
%ALGORITHM:-
%Get the order of the filter
%%Get the cut off frequency
%use ‘ fir1 ’& ‘rectwin’ function to compute the filter coefficient
%Draw the magnitude and phase response
%MATLAB CODE:-
clc;
clear all;
close all;
N=input('Enter the value of N:');
wc=input('Enter cutoff frequency:');
h=fir1(N,wc/pi,rectwin(N+1));
freqz(h);
%SAMPLE INPUT:-
%Enter the value of N:28
%Enter cutoff frequency:0.5*pi
%B,FIR HIGHPASS FILTER USING RECTANGULAR WINDOW
%AIM: - TO write a MATLAB program to plot magnitude response and phase response of digital FIR HP
filter
%using rectangular window
%MATLAB CODE:-
clc;
clear all;
close all;
N=input('Enter the value of N:');
wc=input('Enter cutoff frequency:');
h=fir1(N,wc/pi,'high',rectwin(N+1));
freqz(h);
%SAMPLE INPUT:-
%Enter the value of N:28
%Enter cutoff frequency:0.5*pi
%SAMPLE INPUT:-
%Enter the value of N:28
%Enter cutoff frequency:[0.3*pi,0.7*pi]
%MATLAB CODE:-
clc;
clear all;
close all;
N=input('Enter the value of N:');
wc=input('Enter cutoff frequency:');
h=fir1(N,wc/pi,’stop’,rectwin(N+1));
freqz(h);
%SAMPLE INPUT:-
%Enter the value of N:28
%Enter cutoff frequency:[0.2*pi,0.7*pi]
Experment 7
IIR FILTERS FILTER DESIN MATLAB CODE
%AIM: - TO write a MATLAB program to plot magnitude response and phase response of digital IIR lpf
&hpf filter
A,BUTTERWORTH DIGITAL IIR FILTERS Low-pass Filter
MATLAB CODE:-
clc;
clear all;
close all;
rp=input('enter the passband ripple');
rs=input('enter the stopband ripple');
wp=input('enter the passband freq');
ws=input('enter the stopband freq');
fs=input('enter the sampling freq');
w1=2*wp/fs;w2=2*ws/fs;
[n,w]=buttord(w1,w2,1,50); % finding the order of the filter
[b,a]=butter(n,w);
figure(1)
[h,q] = freqz(b,a,512,fs);
plot(q,abs(h)); % Normalized Magnitude plot
grid;
sample inputs
enter the passband ripple=1
enter the stopband ripple=50
enter the passband freq=1200
enter the stopband freq=1500
enter the sampling freq=8000
MATLAB CODE:-
clear all;
clear all;
close all;
rp=input('enter the passband ripple');
rs=input('enter the stopband ripple');
wp=input('enter the passband freq');
ws=input('enter the stopband freq');
fs=input('enter the sampling freq');
w1=2*wp/fs;w2=2*ws/fs;
[n,w]=buttord(w1,w2,1,50); % finding the order of the filter
[b,a]=butter(n,w,'high');
figure(1)
freqz(b,a,512,fs);
figure(2)
[h,q] = freqz(b,a,512,fs);
plot(q,abs(h)); % Normalized Magnitude plot
sample inputs
enter the passband ripple=1
enter the stopband ripple=50
enter the passband freq=1200
enter the stopband freq=1500
enter the sampling freq=8000
grid
Experment 8
MATLAB CODE:-
clear all;
clear all;
close all;
rp=input('enter the passband ripple');
rs=input('enter the stopband ripple');
wp1=input('enter the 1st passband freq');
wp2=input('enter the 2nd passband freq');
ws1=input('enter the 1st stopband freq');
ws2=input('enter the 2nd stopband freq');
fs=input('enter the sampling freq');
w1=2*wp1/fs;w2=2*wp2/fs;w3=2*ws1/fs;w4=2*ws2/fs;
[n,w]=buttord([w1,w2],[w3, w4],1,50);
[b,a]=butter(n,w,'bandpass');
%figure(1)
%freqz(b,a,fs)
figure(1)
[h,w]=freqz(b,a,fs);
plot(w,abs(h))
grid
sample inputs
enter the passband ripple1
enter the stopband ripple50
enter the 1st passband freq1200
enter the 2nd passband freq2800
enter the 1st stopband freq400
enter the 2nd stopband freq3200
enter the sampling freq8000
%matlab code:-
clear all;
clear all;
close all;
rp=input('enter the passband ripple');
rs=input('enter the stopband ripple');
wp1=input('enter the 1st passband freq');
wp2=input('enter the 2nd passband freq');
ws1=input('enter the 1st stopband freq');
ws2=input('enter the 2nd stopband freq');
fs=input('enter the sampling freq');
w1=2*wp1/fs;w2=2*wp2/fs;
w3=2*ws1/fs;w4=2*ws2/fs;
[n,w]=buttord([w1,w2],[w3, w4],1,50);
[b,a]=butter(n,w,'stop');
%figure(1)
%freqz(b,a,fs)
figure(1)
[h,w]=freqz(b,a,fs);
plot(w,abs(h))
grid
sample inputs
enter the passband ripple1
enter the stopband ripple50
enter the 1st passband freq1200
enter the 2nd passband freq2800
enter the 1st stopband freq400
enter the 2nd stopband freq3200
enter the sampling freq8000
Experment 9
DIGITAL IIR CHEBYSHEV(TYPE-1) FILTER DESIGHN
A,DIGITAL CHEBYSHEV(TYPE-1) LOW PASS FILTER
%AIM: - TO write a MATLAB program to plot magnitude response and phase response of digital
Chebyshev type-1 Low pass filter
%PROCEDURE:-
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
ALGORITHM:-
Get the passband and stopband ripples
Get the passband and stopband edge frequencies
Calculate the order of the filter using ‘ cheb1ord ’ function
Find the filter coefficients, using ‘cheby1’ function
Draw the magnitude and phase response
%MATLAB CODE:-
clc;
clear all;
close all;
rp=input ('Enter the pass band attenuation:');
rs=input ('Enter the stop band attenuation:');
wp=input ('Enter the pass band frequency:');
ws=input ('Enter the stop band frequency:');
[N,wn]=cheb1ord(wp/pi,ws/pi,rp,rs);
[b,a]=cheby1(N,rp,wn);
freqz(b,a);
SAMPLE INPUT:-
Enter the pass band attenuation:20
Enter the stop band attenuation:50
Enter the pass band frequency:0.3*pi
Enter the stop band frequency:0.4*pi
MATLAB CODE:-
clc;
clear all;
close all;
rp=input ('Enter the pass band attenuation:');
rs=input ('Enter the stop band attenuation:');
wp=input ('Enter the pass band frequency:');
ws=input ('Enter the stop band frequency:');
[N,wn]=cheb1ord(wp/pi,ws/pi,rp,rs);
[b,a]=cheby1(N,rp,wn,'high');
freqz(b,a);
SAMPLE INPUT:-
Enter the pass band attenuation:20
Enter the stop band attenuation:50
Enter the pass band frequency:0.4*pi
Enter the stop band frequency:0.3*pi
C,DIGITAL CHEBYSHEV(TYPE-1) BAND PASS FILTER
AIM: - TO write a MATLAB program to plot magnitude response and phase response of digital
Chebyshev type-1 Band pass filter
MATLAB CODE:-
clc;
clear all;
close all;
rp=input ('Enter the pass band attenuation:');
rs=input ('Enter the stop band attenuation:');
wp=input ('Enter the pass band frequency:');
ws=input ('Enter the stop band frequency:');
[N,wn]=cheb1ord(wp/pi,ws/pi,rp,rs);
[b,a]=cheby1(N,rp,wn);
freqz(b,a);
SAMPLE INPUT:-
Enter the pass band attenuation:20
Enter the stop band attenuation:98
Enter the pass band frequency:[0.3*pi,0.5*pi]
Enter the stop band frequency:[0.1*pi,0.8*pi]
MATLAB CODE:-
clc;
clear all;
close all;
rp=input('Enter the pass band attenuation:');
rs=input('Enter the stop band attenuation:');
wp=input('Enter the pass band frequency:');
ws=input('Enter the stop band frequency:');
[N,wn]=cheb1ord(wp/pi,ws/pi,rp,rs);
[b,a]=cheby1(N,rp,wn,'stop');
freqz(b,a);
SAMPLE INPUT:-
Enter the pass band attenuation:20
Enter the stop band attenuation:98
Enter the pass band frequency:[0.1*pi,0.8*pi]
Enter the stop band frequency:[0.3*pi,0.5*pi]
experment 4
%FIR LOW PASS FILTER USING HAMMING WINDOW
AIM: - TO write a MATLAB program to plot magnitude response and phase response of digital FIR LP
filter
using Hamming window
%A ,MATLAB CODE:-
clc;
clear all;
close all;
N=input('Enter the value of N:');
wc=input('Enter cutoff frequency:');
h=fir1(N,wc/pi,hamming(N+1));
freqz(h);
RESULTS:- Thus the magnitude response and phase response of fir Low pass filter using hamming
window
was verified.
AIM: - TO write a MATLAB program to plot magnitude response and phase response of digital FIR HP
filter
using Hanning window
%MATLAB CODE:-
clc;
clear all;
close all;
N=input('Enter the value of N:');
wc=input('Enter cutoff frequency:');
h=fir1(N,wc/pi,'high',hamming(N+1));
freqz(h)
RESULTS:- Thus the magnitude response and phase response of fir high pass filter using hamming
window
was verified.
%MATLAB CODE:-
clc;
clear all;
close all;
N=input('Enter the value of N:');
wc=input('Enter cutoff frequency:');
h=fir1(N,wc/pi,hamming(N+1));
freqz(h);
FIGURE:-
SAMPLE INPUT:-
Enter the value of N:28
Enter cutoff frequency:[0.3*pi,0.7*pi]
RESULTS:- Thus the magnitude response and phase response of fir band pass filter using hamming
window
was verified.
%MATLAB CODE:-
clc;
clear all;
close all;
N=input('Enter the value of N:');
wc=input('Enter cutoff frequency:');
h=fir1(N,wc/pi,’stop’,hamming(N+1));
freqz(h);
SAMPLE INPUT:-
Enter the value of N:28
Enter cutoff frequency:[0.2*pi,0.7*pi]
RESULTS:- Thus the magnitude response and phase response of fir band stop filter using hamming
window
was verified.