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

DSP LAB 1to 6

The document describes an experiment to implement Parseval's theorem using the discrete Fourier transform (DFT). It defines a test signal in the time domain, takes the DFT, and calculates the energy in both the time and frequency domains. It displays the energies and checks that they are equal, verifying Parseval's theorem that the total energy is conserved between the two domains. A plot is produced to compare the calculated energies.

Uploaded by

daddyplays25
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)
45 views

DSP LAB 1to 6

The document describes an experiment to implement Parseval's theorem using the discrete Fourier transform (DFT). It defines a test signal in the time domain, takes the DFT, and calculates the energy in both the time and frequency domains. It displays the energies and checks that they are equal, verifying Parseval's theorem that the total energy is conserved between the two domains. A plot is produced to compare the calculated energies.

Uploaded by

daddyplays25
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/ 12

EXPERIMENT NO -01

Aim: Write a program to compute N point DFT of a given sequence and plot
magnitude and phase spectrum.
%write a program to compute N point DFT of a given sequence and plot magnitude and phase
spectrum.

clc;
close all;
clear all;
N = input(' Enter the DFT sequence:');
j =sqrt(-1);
xn = zeros (1,N);
xn(1)=1/3;
xn(2) =1/3;
xn(3) = 1/3;
XK =zeros (1,N);
for k =0:1:N-1
for n= 0:1:N-1
XK(k+1) =XK(k+1)+xn(n+1)*exp(-j*2*pi*k*n/N);
end
end
disp('The DFT sequence is');
XK
disp('The Magnitude sequence is ');
MagXK = abs(XK)
disp ('the phase sequence is');
phaXK =angle(XK)

wk =0:1:N-1;

subplot(2,1,1); stem(wk,MagXK);
title('Magnitude spectrum');
xlabel('k');
ylabel ('MagXK');

subplot(2,1,2)
stem(wk, phaXK);
title('Phase spectrum');
xlabel('k');
ylabel ('PhaseXK');

1
2
EXPERIMENT NO -02
Aim: To find a linear Convolution of two given sequences
clc;
close all;
x=input('enter the value of x(n):');%[1 2 3 1]
y=input('enter the value of y(n):');%[1 1 2 3]
v=conv(x,y);
x3=length(v);
t1=0:1:x3-1;
subplot(1,1,1);
stem(t1,v);
disp(v);
title('linear convolution of x(n) and y(n):');
xlabel('frequency');
ylabel('amplitude');
grid on;

3
4
EXPERIMENT NO -03
Aim: To find a Circular Convolution of two given sequences

%To Find the circular convolution of given sequences:


clc;
clear all;
close all;
x=input('Enter the first sequence x(n):');%[1 2 3 1 0 0 0]
h=input('Enter the second sequence h(n):');%[1 1 2 3 0 0 0]
m=length(x);
n=length(h);
N=max(m,n);
x=[x,zeros(1,N-m)];
h=[h,zeros(1,N-n)];
for n=1:N
y(n)=0;
for i=1:N;
j=n-i+1;
if(j<=0)
j=N+j;
end
y(n)=y(n)+x(i)*h(j);
end
end
n=0:N-1;
subplot(1,1,1);
disp('convoluted sequence y(n) is:');
disp(y)
stem(n,y)
xlabel('n')
ylabel('y(n)')
title('circular convoluted sequence ')
grid on;

5
6
EXPERIMENT NO - 04
Aim: To Perform linear Convolution from Circular Convolution and vice
versa
Code:
%Program to find the linear convolution using circular convolution method

clc;
clear all;
close all;
x1=input('Enter the value of First sequence:'); %[1 2 3 1]
x2=input('Enter the value of Second sequence:'); %[1 1 2 3]
l1=length(x1);
l2=length(x2);
n=l1+l2-1;
display(n);

subplot(3,1,1);
stem(x1);
xlabel('time');
ylabel('Amplitude');
title('first Sequence(x1)');
grid on;

subplot(3,1,2);
stem(x2);
xlabel('time');
ylabel('Amplitude');
title('Second Sequence(x2)');
grid on;

if l1>l2
l3=l1-l2
x2=[x2,zeros(1,l3)];
elseif l2>l1
l3=l2-l1
x1=[x1,zeros(1,l3)];
end

n=l1+l2-1
v=conv(x1,x2);
disp('The Convoluted Sequence is:');
disp(v);

subplot(3,1,3);
stem(v);
xlabel('time');
ylabel('Amplitude');
title('The Convoluted Sequence of x1 and x2');
grid on;

7
OUTPUT

8
EXPERIMENT NO - 05
Aim: To Implement Time Shifting and Time Reversal property of DFT
Code:
clc;
clear all;
close all;
t=input('Enter the Time Sequence');%[1,2,3,4]
n=input('Enter the Amplitude Sequence');%[0,1,2,3]
subplot(4,1,1);
stem(t,n);
title('Original signal');
xlabel('amplitude');
ylabel('time');
grid on;
subplot(4,1,2);
stem(t-1,n);
title('Advanced Signal');
xlabel('amplitude');
ylabel('time');
grid on;
subplot(4,1,3);
stem(t+1,n);
title('Delayed Signal');
xlabel('amplitude');
ylabel('time');
grid on;
subplot(4,1,4);
stem(-t,n);
title('Reversed Signal');
xlabel('amplitude');
ylabel('time');
grid on;

9
OUTPUT

10
EXPERIMENT NO - 06
To Implement Parseval Theorem of DFT
Code:
% Define a signal in the time domain
clc;
clear all;
close all;
N = input('Enter the no. of Samples'); % 64
display(N);
t = 0:1:N-1; % Time vector
x = cos(2*pi*0.1*t) + 0.5*cos(2*pi*0.3*t); % Example signal
% Calculate the DFT of the signal
X = fft(x);
% Calculate the energy in the time domain
energy_time_domain = sum(abs(x).^2);
% Calculate the energy in the frequency domain using Parseval's theorem
energy_frequency_domain = sum(abs(X).^2) / N;
% Display the energies and compare them
fprintf('Energy in the time domain: %.2f\n', energy_time_domain);
fprintf('Energy in the frequency domain: %.2f\n', energy_frequency_domain);
% Check if Parseval's theorem holds (within a small tolerance)
tolerance = 1e-10;
if abs(energy_time_domain - energy_frequency_domain) < tolerance
disp('Parseval''s theorem holds: Energy is conserved.');
else
disp('Parseval''s theorem does not hold: Energy is not conserved.');
end
subplot(1,1,1);
stem(energy_frequency_domain,energy_time_domain);
title('energy plot')
xlabel('Energy time domain');
ylabel('Energy frequency domain');
grid on;

11
Output:

12

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