0% found this document useful (0 votes)
43 views19 pages

Labsheet DSP

Uploaded by

hx477n
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views19 pages

Labsheet DSP

Uploaded by

hx477n
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

19EAC283 Digital Signal Processing & Processors Lab

Ex. No: 4
Ex. Name: Linear filtering with Overlap and Overlap save
Name of the student: N SASIDHAR Reg. No: AM.EN.U4EAC22046

Task 1 Objective: Determine the output of an LTI system with impulse response h[n]={1,-1,1,2}
for the input x[n]={1,2,-1,3,2,1-2,1,0,-1,-2,3,-2,1,1,2,2,1} using overlap add method.
Code:
clc;
x=[1,2,-1,3,2,1,-2,1,0,-1,-2,3,-2,1,1,2,2,1];
H=[1,-1,1,2];
K=length(x);
m=length(H);
fl=K+m-1;
l=3;
n=l+m-1;
x1=zeros(n,n);
k=1;
for i=1:n
for j=1:l
if k<=K
x1(i,j)=x(k);
k=k+1;
else
x1(i,j)=0;
end
end
end
h=zeros(1,n);
for i=1:m
h(i)=H(i);
end
y1=zeros(n,n);
for i=1:n
a=zeros(1,n);
for j=1:l
a(j)=x1(i,j);
end
b=cconv(a,h);
for j=1:n
y1(i,j)=b(j);
end
end
Y1=zeros(n,fl);
for i=1:n
for j=1:n
Y1(j,j+(i-1)*l)=y1(i,j);
end
end
y=zeros(1,fl);
for i=1:n
for j=1:fl
y(j)=y(j)+Y1(i,j);
end
end
disp("Output sequence y[n]:");
19EAC283 Digital Signal Processing & Processors Lab

disp(y);
disp("Output using cconv Function:")
disp(cconv(x,H));

Output:

Inference:
The provided code effectively implements the method and showcases the expected behavior
of the overlap-add approach. Successfully applied to compute the output of the LTI system for
the given input sequence, this method involves segmenting the input, applying circular
convolution to each segment, and then combining the results by overlapping and adding. This
process is highly efficient for long sequences and ensures accurate computation of the
system's response. The verification step has confirmed the correctness of the output sequence.

Task 2 Objective: Determine the output of an LTI system with impulse response h[n]={1,-1,1,2}
for the input x[n]={1,2,-1,3,2,1-2,1,0,-1,-2,3,-2,1,1,2,2,1} using overlap save method.
Code:
clc
clear all
close all
x=[1,2,-1,3,2,1,-2,1,0,-1,-2,3,-2,1,1,2,2,1];
H=[1,-1,1,2];
K=length(x);
m=length(H);
fl=K+m-1;
l=5;
n=l+m-1;
x1=zeros(5,n);
k=1;
for i=m:n
x1(1,i)=x(k);
k=k+1;
end
k=3;
for i=2:4
for j=1:8
19EAC283 Digital Signal Processing & Processors Lab

if k<=K
x1(i,j)=x(k);
k=k+1;
else
x1(i,j)=0;
end
end
for j=1:m-1
k=k-1;
end
end
x1(5,1)=1;
h=zeros(1,n);
for i=1:m
h(i)=H(i);
end
y1=zeros(5,n);
for i=1:5
a=zeros(1,n);
for j=1:n
a(j)=x1(i,j);
end
b=cconv(a,h);
for j=1:n
y1(i,j)=b(j);
end
end
k=1;
y=zeros(1,fl);
for i=1:5
for j=4:8
y(k)=y1(i,j);
k=k+1;
end
end
disp("Output sequence y[n]:");
disp(y);
disp("Output using cconv Function:")
disp(cconv(x,H));

Output:
19EAC283 Digital Signal Processing & Processors Lab

Inference:
The code for Task 2 effectively implements the overlap-save method to determine the output
of an LTI system with impulse response ℎ[�] for the input sequence �[�]. By segmenting
the input sequence and applying circular convolution to each segment, the method efficiently
computes the system's response. Overlapping parts are discarded to form the final output.
This approach is computationally efficient for long sequences, and the verification step using
the cconv function confirms the correctness of the output. The code showcases the expected
behavior of the overlap-save method, ensuring accurate and efficient computation.

******
19EAC283 Digital Signal Processing & Processors Lab

Ex. No: 1
Ex. Name: DFT and IDFT
Name of the student: N SASIDHAR Reg. No: AM.EN.U4EAC22046
Objective:
Prelab:

Exercise:

Task 1 Objective: Generate 320 samples of a 50Hz sine wave sampled at 8KHz and multiply
this by a 1KHz sine wave sampled at 8KHz. Plot the resulting waveform

Code:
clear all;
close all;
clc
f1=50;
f2=1000;
fs=8000;
t=0:1/fs:(1/fs)*320-1/fs;
xt1=sin(2*pi*f1*t);
xt2=sin(2*pi*f2*t);
r=xt1.*xt2;
stem(t,r);
xlabel("t");
ylabel("x(t)");
title("x(t)");

Graph:

Inference:
The resulting waveform represents the product of the two original sine waves. Since
multiplication in the time domain corresponds to convolution in the frequency domain, the
product wave will contain frequency components at the sum and difference of the original
frequencies (50 Hz and 1 kHz). In this case, the product wave will have components at around
19EAC283 Digital Signal Processing & Processors Lab

950 Hz (1 kHz + 50 Hz) and 50 Hz (1 kHz - 50 Hz). The specific amplitude and phase
relationships of these components will depend on the initial phases of the original sine waves.
You can visualize the frequency content of the product wave using the `fft` function.

Task 2 Objective: Generate and plot the signal x(t) = 3cos(20πt)−2sin(30πt) over a time range of 0 <
t < 400msec. Also plot the DT signal formed by sampling this function at the following sampling
intervals: (a)Ts = 1/120sec (b) Ts = 1/60sec (c) Ts = 1/30sec (d) Ts = 1/15sec

Code:
clear all;
close all;
clc
fs=200;
t=0:1/fs:0.4;
xt=3*cos(20*pi*t)-2*sin(30*pi*t);
stem(t,xt);
xlabel("t");
ylabel("x(t)");
title("x(t)");
figure
%a
fsa=120;
ta=0:1/fsa:0.4;
xta=3*cos(20*pi*ta)-2*sin(30*pi*ta);
subplot(2,2,1);
stem(ta,xta);
xlabel("t");
ylabel("x(t)");
title("x(t) when T=1/120sec");
%b
fsb=60;
tb=0:1/fsb:0.4;
xtb=3*cos(20*pi*tb)-2*sin(30*pi*tb);
subplot(2,2,2);
stem(tb,xtb);
xlabel("t");
ylabel("x(t)");
title("x(t) when T=1/60sec");
%c
fsc=30;
tc=0:1/fsc:0.4;
xtc=3*cos(20*pi*tc)-2*sin(30*pi*tc);
subplot(2,2,3);
stem(tc,xtc);
xlabel("t");
ylabel("x(t)");
title("x(t) when T=1/30sec");
%d
fsd=15;
td=0:1/fsd:0.4;
xtd=3*cos(20*pi*td)-2*sin(30*pi*td);
subplot(2,2,4);
stem(td,xtd);
xlabel("t");
ylabel("x(t)");
title("x(t) when T=1/15sec");
19EAC283 Digital Signal Processing & Processors Lab

Graph:

Inference:
➢ By sampling the signal at intervals of Ts = 1/120sec, Ts = 1/60 sec, Ts = 1/30sec, and Ts
= 1/15sec, we can observe the effects of different sampling rates on the reconstructed
signal. Sampling at a rate higher than the Nyquist rate will allow for accurate
reconstruction, while sampling at a rate lower than the Nyquist rate will result in
aliasing and distortion of the signal. Therefore, based on the results obtained from
sampling the signal at different intervals, we can infer that to accurately reconstruct the
signal x(t) it should be sampled at a rate higher than the Nyquist rate of 30 Hz.
Sampling at a rate lower than this would lead to aliasing and loss of information in the
reconstructed signal.
➢ Regarding how fast the signal should be sampled for reconstruction, according to the
Nyquist theorem, the sampling frequency should be at least twice the maximum
frequency component of the signal. In this case, the maximum frequency component is
30 Hz (corresponding to the sine term with 30πt). So, the sampling frequency should be
at least 2*30=60Hz. From the sampling intervals provided, Ts=1/60sec (60 Hz) would
be the minimum sampling interval required for proper reconstruction.
19EAC283 Digital Signal Processing & Processors Lab

Task 3 Objective: Sample the CT signal x(t) = sin(2πt) at a sampling rate fs. Then, using
MATLAB, plot the interpolation between samples in the time range −1 < t < 1 using the
approximation

Code:
clear all;
close all;
clc
t=-1:0.01:1;
y1=zeros(1,length(t));
y2=zeros(1,length(t));
y3=zeros(1,length(t));
xt=sin(2*pi*t);
subplot(4,1,1);
plot(t,xt);
%a
fs=4;
fc=2;
N=2;
Ts=1/fs;
for i=1:length(t)
for n=-N:N
y1(i)=y1(i)+sin(2*pi*n*Ts)*sinc(2*fc*(t(i)-n*Ts));
end

end
subplot(4,1,2);
plot(t,y1);
title("a");
xlabel("t");
ylabel("x(t)");
%b
fs=16;
fc=8;
N=16;
Ts=1/fs;
for i=1:length(t)
for n=-N:N
y2(i)=y2(i)+sin(2*pi*n*Ts)*sinc(2*fc*(t(i)-n*Ts));
end
end
subplot(4,1,3);
plot(t,y2);
title("b");
xlabel("t");
ylabel("x(t)");
%c
fs=8;
fc=4;
19EAC283 Digital Signal Processing & Processors Lab

N=4;
Ts=1/fs;
for i=1:length(t)
for n=-N:N
y3(i)=y3(i)+sin(2*pi*n*Ts)*sinc(2*fc*(t(i)-n*Ts));
end

end
subplot(4,1,4);
plot(t,y3);
title("c");
xlabel("t");
ylabel("x(t)");

Graph:

Inference:
Case (a): If the sampling rate and cut-off frequency are relatively low, and the interpolation
depth is small, the resulting interpolated signal may be significantly distorted. This is because
there are not enough sampling and interpolation points to accurately reconstruct the original
signal.
Case (b): If the sampling rate is higher and the cut-off frequency is also higher, the chances of
accurate interpolation are better. With a larger interpolation depth, the interpolated signal is
expected to closely resemble the original continuous-time signal.
Case (c): This case represents a moderate scenario with intermediate values for sampling rate,
cut-off frequency, and interpolation depth. The resulting interpolated signal may exhibit some
distortion, but it should still capture the general characteristics of the original continuous-time
signal.

******
19EAC211 DIGITAL SIGNAL PROCESSING
LABSHEET-2
Experiment: DFT and IDFT
Name of the Student: N Sasidhar Reg. No: AM.EN.U4EAC22046

Exercise:

Code :
N=16;
n=0:N-1;
x=cos(pi*6/16*n);
w=-pi:2*pi/(N-1):pi;
W=length(w);
DTFT=zeros(1, W);
for k=1:W
for m=1:N
DTFT(k)=DTFT(k)+x(m)*exp(-1j*w(k)*n(m));
end
end
DFT=zeros(1,N);
for m=1:N
for k=1:N
DFT(m)=DFT(m)+x(k)*exp(-1j*2*pi*(m-1)*(k-1)/N);
end
end
figure;
plot(w,abs(DTFT));
hold on;
stem(2*pi*n/N, abs(DFT));
title("16-point DFT");
xlabel('Frequency');
ylabel('Magnitude');
legend("DTFT","DFT")

RESULT AND INFERENCE:


the plot shows the comparison between the Discrete-Time Fourier Transform (DTFT) and the Discrete Fourier Transform (DFT) of a
16-point cosine signal. While the DTFT provides a continuous spectrum, the DFT, with its discrete frequency bins, accurately captures
the periodic nature of the signal's spectrum, though it suffers from spectral leakage due to its finite resolution.

OUTPUT:
19EAC211 DIGITAL SIGNAL PROCESSING

CODE:
clear all;
close all;
clc;
X=[6,-2+2j,-2,-2-2j];
N=4;
x=zeros(1,N);
for n=0:N-1
for k=0:N-1
x(n+1)=x(n+1)+X(k+1)*exp(1j*2*pi/N*k*n)/N;
end
end
stem(0:N-1,x);
xlabel('n');
ylabel('x[n]');
title('IDFT');
disp(ifft(X));
19EAC211 DIGITAL SIGNAL PROCESSING
OUTPUT:

RESULT AND INFERENCE:


Both codes implement the inverse Discrete Fourier Transform (IDFT) to reconstruct a signal from its frequency-
domain representation. The first code calculates the IDFT through manual summation, while the second code
utilizes the built-in function ifft() for efficient computation. Both plots demonstrate identical results, depicting
the original signal accurately reconstructed from its frequency-domain representation.

CODE:
close all;
clear all;
clc;
%a
n=0:5;
x=n;
19EAC211 DIGITAL SIGNAL PROCESSING
N=8;
k=0:N-1;
w=2*pi*k/N;
x_dtft=zeros(1, N);
for i=1:length(w)
x_dtft(i)=sum(x.*exp(-1i*w(i)*n));
end
subplot(3,1,1);
stem(w, abs(x_dtft));
title('DTFT sampled at 8 points');
xlabel('Frequency');
ylabel('Magnitude');
x_rec=ifft(x_dtft,length(n));
subplot(3,1,2);
stem(n,real(x_rec));
title('IDFT');
xlabel('Time index');
ylabel('Amplitude');
subplot(3,1,3);
stem(n, imag(x_rec));
title('Imaginary part of IDFT');
xlabel('Time index');
ylabel('Amplitude');
figure;
%b
n=0:5;
x=n;
N=4;
k=0:N-1;
w=2*pi*k/N;
x_dtft=zeros(1, N);
for i=1:length(w)
x_dtft(i)=sum(x.*exp(-1i*w(i)*n));
end
subplot(3,1,1);
stem(w,abs(x_dtft));
title('DTFT sampled at 4 points');
xlabel('Frequency');
ylabel('Magnitude');
x_rec = zeros(1,length(n));
for a = 1:length(n)
for b=1:N
x_rec(a)=x_rec(a)+x_dtft(b)*exp(1i*w(b)*n(a));
end
x_rec(a)=x_rec(a)/N;
end
subplot(3,1,2);
stem(n,real(x_rec));
title("IDFT");
xlabel('Time index');
ylabel('Amplitude');
subplot(3,1,3);
stem(n,imag(x_rec));
title('Imaginary part of IDFT');
xlabel('Time index');
ylabel('Amplitude');

OUTPUT:
19EAC211 DIGITAL SIGNAL PROCESSING

RESULT AND INFERENCE:


The first subplot presents the original signal. Subsequent plots illustrate the Discrete-Time Fourier Transform
(DTFT) magnitude spectra for different sampling frequencies (8 and 4 points), and their corresponding
reconstructed signals using the Inverse Discrete Fourier Transform (IDFT). As expected, higher sampling
frequency (8 points) captures more frequency information, resulting in a more accurate reconstruction compared
to the lower sampling frequency (4 points).

******
19EAC283 Digital Signal Processing & Processors Lab

Ex. No: 3
Ex. Name: Properties of DFT
Name of the student: N SASIDHAR Reg. No: AM.EN.U4EAC22046

Exercise:

Task 1 Objective:

1. Sketch the signal x[n] = sin(2pi * [0:19]/20)


2. Find the DFT of x[n].
3. Shift x[n] circularly by 2 units and name it as x₁[n]. Plot x(n).
4. Find DFT of x₁[n]. Observe the relationship between X(k) and X, (k).

Code:
clear all;
close all;
clc;
n=0:19;
x=sin(2*pi*(n)/20);
subplot(2,1,1);
stem(n,x)
xlabel('n');
ylabel('Magnitude');
title('signal');
N=length(n);
%DFT
X=zeros(1,length(n));
for r=0:length(n)-1
for k=0:19
X(r+1)=X(r+1)+x(k+1)*exp(-1i*2*pi*k*r/N);
end
end
subplot(2,1,2);
stem(n,abs(X));
xlabel('Frequency');
ylabel('Magnitude');
title('X(k) DFT');
%x1(n)
x1=zeros(1,length(x));
for r=1:length(x1)-2
x1(r+2)=x(r);
end
x1(1)=x(19);
x1(2)=x(20);
figure;
subplot(2,1,1)
stem(n,x1);
xlabel('n');
ylabel('Magnitude');
title('x1(n) signal');
%DFT of x1(n)
X1=zeros(1,length(n));
for r=0:length(n)-1
for k=0:19
19EAC283 Digital Signal Processing & Processors Lab

X1(r+1)=X1(r+1)+x1(k+1)*exp(-1i*2*pi*k*r/N);
end
end
subplot(2,1,2);
stem(n,abs(X1));
xlabel('Frequency');
ylabel('Magnitude');
title('X1(k)');

Graph:

Inference:
The plot of X(k) represents the magnitude spectrum of the original signal, and the plot of X1(k)
represents the magnitude spectrum of the circularly shifted signal. We have observed that X(k)
and X1(k) are identical, but they might have different starting points due to the circular shift.
This is because circularly shifting a signal in time domain does not change its frequency
domain representation, hence the DFTs of �[�] and �1[�] are the same, just with different
starting points in frequency domain.

Task 2 Objective:

The DFT of the 5-point signal x[n] is given by X[k] = [5, 6, 1, 2, 9] . Another signal is defined
by x_{1}[n] = e ^ (j(2n / 5) * 2n) * x[n] / 0 <= n <= 4. Determine X1[k] using suitable
property. Plot x[n], Real part of X[k], Imaginary part of X[k] in one figure. Plot x[n], Real part
of X1[k], Imaginary part of X1[k] in another figure.

Code:
clear all;
close all;
clc;
X=[5,6,1,2,9];
n=0:4;
x1=exp(1i*(2*pi/15)*2*n);
%determining X1[k]
X1=zeros(1,length(n));
N=length(n);
for r=0:length(n)-1
19EAC283 Digital Signal Processing & Processors Lab

for k=0:4
X1(r+1)=X1(r+1)+x1(k+1)*exp(-1j*2*pi*k*r/N);
end
end
%plotting x[n]
x=zeros(1,length(n));
for r=0:length(n)-1
for k=0:4
x(r+1)=x(r+1)+X(k+1)*exp(1i*2*pi*k*r/N);
end
end
x(r+1)=(1/N)*x(r+1);
subplot(3,1,1)
stem(n,x);
title('x(n)')
%real and imaginary part of X[k]
subplot(3,1,2);
stem(n,real(X))
title('real part of X(k)')
subplot(3,1,3)
stem(n,imag(X))
title('imaginary part of X(k)')
%plotting x1,imaginary and real of X1
figure;
subplot(3,1,1)
stem(n,x1);
title('x1(n)')
subplot(3,1,2)
stem(n,real(X1))
title('real part of X(k)')
subplot(3,1,3)
stem(n,imag(X1))
title('imaginary part of X1(k)')

Graph:

Inference:

➢ In the first figure, I had plotted the original signal �[�], its real part Re(�[�]) and
imaginary part Im(�[�])
19EAC283 Digital Signal Processing & Processors Lab

➢ In the second figure, I had plotted the modified signal �1[�], its real part Re(�1[�])
and imaginary part Im(�1[�]).
➢ The signal �1[�] is a modified version of �[�], and �1[�] is computed using the
time-shifting property of the DFT.

Task 3 Objective:
Let x[n] be the finite sequence and its DFT is X[k] = [0, 1 + j, 1, 1 - f] Using the properties,
find DFT of the following sequences.
a. x_{1}[n] = e ^ ((l*pi)/2 * n) * x[n].
b. x_{2}[n] = cos((n*pi)/2) * x[n].
c. x3nx(n-1)4.

Code:
close all;
clear all;
clc;
X=[0,1+1j,1,1-1j];
n=0:3;
subplot(2,2,1)
stem(n,X)
xlabel('Frequency');
ylabel('Magnitude');
title('X(k)');
x=zeros(1,length(X));
N=length(X);
for r=0:length(X)-1
for k=0:3
x(r+1)=x(r+1)+X(k+1)*exp(1i*2*pi*k*r/N);
end
x(r+1)=(1/N)*x(r+1);
end
x1=exp((1j*pi/2)*n);
%above equation represnt freq shift of X(k-l)
%shifted by 1 i.e X(k-1) therfore
%dft is just one circular shift of X[k]
X1=zeros(1,length(X));
for r=1:length(X1)-1
X1(r+1)=X(r);
end
X1(1)=X(3);
subplot(2,2,2)
stem(n,X1);
xlabel('Frequency');
ylabel('Magnitude');
title('X1(k)');
%plotting dft of x2(n)
x2=cos(n*pi/2).*x;
X2=zeros(1,length(x2));
for r=0:length(n)-1
for k=0:3
X2(r+1)=X2(r+1)+x2(k+1)*exp(-1j*2*pi*k*r/N);
19EAC283 Digital Signal Processing & Processors Lab

end
end
subplot(2,2,3)
stem(n,X2);
xlabel('Frequency');
ylabel('Magnitude');
title('X2(k)');
%plotting dft of x3
X3=zeros(1,length(X));
for r=0:length(X)-1
X3(r+1)=X3(r+1)+X(r+1)*exp(-1i*2*pi*r/N); %here we use time shift property
end
subplot(2,2,4)
stem(n,X3);
xlabel('Frequency');
ylabel('Magnitude');
title('X3(k)');

Graph:

Inference:

➢ X1(k) is obtained by circularly shifting �[�] by one position, corresponding to a


frequency shift of the original sequence.
➢ �2[�] is calculated by modulating the time-domain sequence �[�] with a cosine
function, resulting in frequency scaling effects.
➢ �3[�] is computed using the time-shift property, reflecting the sequence about the
origin in the time domain, thereby affecting the phase of the DFT.
➢ The code demonstrates the application of properties like frequency shift, modulation,
and time-shift in the frequency domain, showcasing how these properties affect the DFT
of a sequence.

******

You might also like