0% found this document useful (0 votes)
26 views

Digital Signal Lab Experiment Record

Uploaded by

Rukya Begum
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Digital Signal Lab Experiment Record

Uploaded by

Rukya Begum
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 27

Exp1: Computation of Linear and Circular convolution

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

%plotting Magnitude of DFT of x


k=0:7;
subplot(3,1,1)
stem(k,abs(X))

%plotting phase of DFT of x


subplot(3,1,2)
stem(k,angle(X))
% calculating DFT by FFT algorithm
X2=fft(x);
% plotting magnitude X2
subplot(3,1,3)
stem(k,abs(X2))
Output/Observation:
X=

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

Equipment and Software Requirement:


1. PC: windows OS,
2. Software: MATLAB

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:');

%calculating Order N, Angular cutoff frequencies


Op=2*pi*fp;
Os=2*pi*fs;
[N,Oc]= buttord(Op,Os,rp,rs, 's');

% Finding Transfer function H(s) coefficient of analog butterworth filter


[b,a] = butter(N,Oc,'s');

% Finding Transfer function H(z) coefficient of digital butterworth filter


[bz,az]=impinvar(b,a,FS);

%Following syntax calculate Frequency response of H(z)


[Hw, f]= freqz(bz,az,500,FS);
% Gain vs frequency plot
gain_abs=abs(Hw);
subplot(2,1,1);
plot(f,gain_abs);
% Gain in dB vs frequency plot
gain_dB=20*log(abs(Hw));
subplot(2,1,2);
plot(f,gain_dB);
Output/Observation:
enter passband edge frequency:500
enter stopband edge frequency:1000
Attenuation at passband edge frequency:3
Attenuation at stopband edge frequency:40
sampling rate orSampling frequency:5000
>> bz

bz =

-0.0000 0.0000 0.0016 0.0056 0.0037 0.0005 0.0000 0

>> az

az =

1.0000 -4.1476 7.7482 -8.3442 5.5547 -2.2747 0.5287 -0.0537

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:');

%calculating Order N, Angular cutoff frequencies


Op=2*FS*tan(pi*fp/FS); % pre warping frequencies
Os=2*FS*tan(pi*fs/FS); % pre warping frequencies
[N,Oc]= buttord(Op,Os,rp,rs, 's');
% Finding Transfer function H(s) coefficient of analog butterworth filter
[b,a] = butter(N,Oc,'s');

% Finding Transfer function H(z) coefficient of digital butterworth filter

[bz,az]=bilinear(b,a,FS); %use this command for bilinear transformation

%Following syntax calculate Frequency response of H(z)


[Hw, f]= freqz(bz,az,500,FS);
% Gain vs frequency plot
gain_abs=abs(Hw);
subplot(2,1,1);
plot(f,gain_abs);
% Gain in dB vs frequency plot
gain_dB=20*log(abs(Hw));
subplot(2,1,2);
plot(f,gain_dB);
Output/Observation:
enter passband edge frequency:500
enter stopband edge frequency:1000
Attenuation at passband edge frequency:3
Attenuation at stopband edge frequency:40
sampling rate orSampling frequency:5000
>> az

az =

1.0000 -3.4944 5.4250 -4.6889 2.3579 -0.6500 0.0764

>> bz
bz =

0.0004 0.0024 0.0061 0.0081 0.0061 0.0024 0.0004

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.

Equipment and Software Requirement:


1. PC: windows OS,
2. Software: MATLAB

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)';

%Desired Frequency Response


Hd=zeros(length(w),1);
for i=1:length(w)
if(abs(w(i))<=wc)
Hd(i)=1*e^(-1i*w(i)*(m-1)/2);
else
Hd(i)=0;
end
end
%obtaining corresponding impulse response
hd=zeros(50,1);
for n=0:49
hd(n+1)=trapz(w,Hd.*(e.^(1i*w*n))/(2*pi));
end

%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)));

%impulse response of FIR filter


h=hd.*wr;
H=zeros(length(w),1);
for i=1:length(w)
sm_H=0;
for n=0:length(h)-1
sm_H=sm_H+h(n+1)*exp(-1i*w(i)*n);
end
H(i)=sm_H;
end

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.

Equipment and Software Requirement:


1. PC: windows OS,
2. Software: MATLAB

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);

%FIR filter specification


Fc=2500; %cutt-off of LPF
Fn=Fs/2;
Wc=Fc/Fn;
N=10; %Order of FIR filter
b_fir=fir1(N,Wc); %designing of FIR filter

% Filtering with downsampling (Decimator)


Ds=4;%downsampling rate
x_filter=filter(b_fir,1,x); %filtering by FIR filter
x_dc=downsample(x_filter, Ds);

% Filtering with upsampling (Interpolator)


Us=4; % upsampling rate
x_up=upsample(x_dc,Us); % upsampling
x_int=filter(b_fir,1,x_up); % filtering
subplot(3,1,1)
stem(n,x);
subplot(3,1,2)
stem(0:24,x_dc);
subplot(3,1,3)
stem(n,x_int);
figure
subplot(3,1,1)
stem(n,abs(fft(x)));
subplot(3,1,2)
stem(0:24,abs(fft(x_dc)));
subplot(3,1,3)
stem(n,abs(fft(x_int)));
Output/Observation:

Output Plots:
Result:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy