Digital Signal Lab Experiment Record
Digital Signal Lab Experiment Record
Aim: To compute linear convolution and circular convolution of two signal by executing
MATLAB program
Equipment and Software Requirement:
1. PC: windows OS,
2. Software: MATLAB
Program 1:
close all; clear all; clc;
x1=[1,2,3,1]
x2= [-1,2,0,-1]
% ploting x1
n1= 0:3;
stem(n1,x1);
% ploting x2
n2= 0:3;
stem(n2,x2);
% Calculating linear convolution between x1 and x2
x3= conv(x1,x2);
% ploting plotting convolution between x1 and x2 i.e x3
n3= 0:6;
stem(n3,x3)
% Displaying x3
disp(x3)
x1=[1,2,3,1]
x2= [-1,2,0,-1]
% ploting x1
n1= 0:3;
subplot(3,1,1);
stem(n1,x1);
% ploting x2
n2= 0:3;
subplot(3,1,2);
stem(n2,x2);
% Calculating linear convolution between x1 and x2
x3= conv(x1,x2)
% ploting plotting convolution between x1 and x2 i.e x3
n3= 0:6;
subplot(3,1,3);
stem(n3,x3)
% Displaying x3
disp(x3)
Output/Observation:
x1 =
1 2 3 1
x2 =
-1 2 0 -1
x3 =
-1 0 1 4 0 -3 -1
Plots:
Program 2
% Finding Circular convolution of two signals
close all; clear all; clc;
x1=[1,-1,1,1]
x2= [2,3,1,4]
% ploting x1
n1= 0:3;
subplot(3,1,1);
stem(n1,x1)
% ploting x2
n2= 0:3;
subplot(3,1,2);
stem(n2,x2)
% Calculating Circular convolution between x1 and x2
x3= cconv(x1,x2,4)
% ploting plotting circular convolution between x1 and x2 i.e x3
n3= 0:3;
subplot(3,1,3);
stem(n3,x3)
% Displaying x3
Output/Observation:
x1 =
1 -1 1 1
x2 =
2 3 1 4
x3 =
2 6 4 8
Plots:
Result:
Exp2: Spectrum analysis of different signals using DFT/ FFT.
Aim: To implement MATLAB program to obtain magnitude spectrum of signal by DFT/FFT
Equipment and Software Requirement:
1. PC: windows OS,
2. Software: MATLAB
Program:
clc;clear all; close all;
% Finding Length of signal
x=[1 0 1 0 1 0 1 0];
N=length(x);
e=exp(1);
% Computing DFT of signal
X=zeros(N,1); % array of with N zeros
for k=0:N-1
sum=0;
for n=0:N-1
sum= sum+x(n+1)*e^(-i*2*pi*n*k/N);
end
X(k+1)=sum;
end
4.0000 + 0.0000i
-0.0000 - 0.0000i
0.0000 - 0.0000i
0.0000 - 0.0000i
4.0000 + 0.0000i
-0.0000 - 0.0000i
0.0000 - 0.0000i
-0.0000 - 0.0000i
Plots:
Result:
Exp3: Design IIR filter for the given specifications using impulse invariant
and bilinear transformation technique.
Aim: to design IIR filter for the given specifications using impulse invariant method and
bilinear transformation method
Program 1:
% IIR filter by Impulse invariance method
clc;clear all;close all;
fp=input('enter passband edge frequency:');
fs= input('enter stopband edge frequency:');
rp=input('Attenuation at passband edge frequency:');
rs=input('Attenuation at stopband edge frequency:');
FS=input('sampling rate orSampling frequency:');
bz =
>> az
az =
Plots:
Program 2:
%IIR filter design by Bilinear Transformation method
clc;clear all;close all;
fp=input('enter passband edge frequency:');
fs= input('enter stopband edge frequency:');
rp=input('Attenuation at passband edge frequency:');
rs=input('Attenuation at stopband edge frequency:');
FS=input('sampling rate orSampling frequency:');
az =
>> bz
bz =
Plots:
Result:
Exp4: Design of FIR filter for the given specifications using frequency
sampling and windowing technique.
Aim: To design of FIR filter for the given specifications using frequency sampling and
windowing technique.
Program:
% MATLAB program for windowing technique.
clc;
close all;
clear all;
e=exp(1);
%duration of FIR filter impulse response
m=input('enter the value of m=');
%cutt off frequency
wc=input('enter the value of wc=');
w=linspace(-pi,pi,1000)';
%window function
wr= [ones(m,1);zeros(50-m,1)];
%wr(1:m,:)=(1-cos(2*pi*(0:m-1)/(m-1)))/2;
wr(1:m,:)=(0.54-0.46*cos(2*pi*(0:m-1)/(m-1)));
W_wf=zeros(length(w),1);
for i=1:length(w)
sm_W=0;
for n=0:length(wr)-1
sm_W=sm_W+wr(n+1)*exp(-1i*w(i)*n);
end
W_wf(i)=sm_W;
end
subplot(3,1,1);
n=0:49;
stem(n,hd);
title('hd(n)');
subplot(3,1,2);
n=0:49;
stem(n,wr);
title('window function');
subplot(3,1,3);
n=0:49;
stem(n,h)
title('h(n) impulse response of FIR filter');
figure,
subplot(3,1,1);
plot(w,abs(Hd));
title('Desired magnitude response');
subplot(3,1,2);
plot(w,abs(W_wf));
title('Fourier transform of window function');
subplot(3,1,3);
plot(w,abs(H));
title('Magnitude response of FIR filter');
Output/Observation:
enter the value of m=10
enter the value of wc=pi/3
>> real(h(1:m))
ans =
-0.0707
-0.0455
0.0637
0.2122
0.3183
0.3183
0.2122
0.0637
-0.0455
-0.0707
Plots:
Program 2:
%MATLAB program by frequency sampling method
clc;
close all;
clear all;
e=exp(1);
fs=10000;
m=15;
w=((2*pi)/m)*(0:(m-1)/2);
mHd=[1 1 1 1 0 0 0 0];
Hrw=mHd;
k=0:7;
Gk=zeros(8,1);
for k=0:7
Gk(k+1)=((-1)^k)*Hrw(k+1);
end
Hd= mHd.*(e.^(-1j*w*(m-1)/2));
h=zeros(m,1);
h1=zeros(m,1);
for n=0:m-1
sm=0;
sm1=0;
for k=1:(m-1)/2
sm=sm+(2*real(Hd(k+1)*e.^(1i*(2*pi/m)*k*n)));
sm1=sm1+2*Gk(k+1)*cos(2*pi*k/m*(n+0.5));
end
h(n+1)=(sm+Hd(0+1))*1/m;
h1(n+1)=(sm1+Gk(0+1))/m;
end
subplot(3,1,1);
n=0:length(h)-1;
stem(n,h);
[Hf fr]=freqz(h,1,500,fs);
wfr=2*pi*fr/fs;
subplot(3,1,2);
plot(wfr,abs(Hf));
subplot(3,1,3);
plot(wfr,angle(Hf));
Output/Observation:
h=
-0.0498
0.0412
0.0667
-0.0365
-0.1079
0.0341
0.3189
0.4667
0.3189
0.0341
-0.1079
-0.0365
0.0667
0.0412
-0.0498
Plots:
Result:
Exp5: Study and comparison of different non-parametric spectral
estimation techniques
Aim: To compute spectral density of a given signal by using MATLAB program.
Program:
clc;
clear all;
close all;
N=20;
A=input('enter the value of A');
B=input('enter the value of B');
n=0:N-1;
x=A*[ones(N/2,1);-1*ones(N/2,1)]+B*randn(N,1);
subplot(2,1,1);
stem(n,x);
[pxx,w]=periodogram(x);
subplot(2,1,2);
stem(w,pxx);
Output/Observation:
enter the value of A10
enter the value of B0.1
Plots:
Result:
Exp 6: Design of Multirate LPF filters for the given specification
Aim: To design multirate LPF filters for the given specification.
Equipment and Software Requirement:
1. PC: windows OS
2. Software: MATLAB
Program:
clc;clear all; close all;
% Multirate filters with decimator and interpolator
Fs=8000;
n=0:99;
x=10*cos(2*pi*500/Fs*n)+5*cos(2*pi*2000/Fs*n)+0.1*rand(1,100);
Output Plots:
Result: