EXPERIMENT3

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

EXPERIMENT-3A

Circular Convolution of Discrete Time Signals

AIM:
To perform Circular convolution of discrete time signals.

SOFTWARE REQUIRED:
Matlab software

THEORY:
To calculate circular convolution for two sequences namely,
x[n] = [a, b, c]
h[n] = [e, f, g]
The convolved output will be
x[n] ⊛ h[n] =

MATLAB SOURCE CODE:


clc
clear all
close all
x1=input('Enter sample values of x1');
x2=input('Enter sample values of x2');
l1=length(x1);
l2=length(x2);
l=max(l1,l2);
n1=0:l1-1;
n2=0:l2-1;
n3=0:l-1;
x1=[x1 zeros(1,l-l1)]';
x2=[x2 zeros(1,l-l2)]';
for i=1:l
c(:,i)=circshift(x2,i-l);
end
x3=c*x1;
figure
subplot(3,1,1)
stem(n1,x1);
xlabel('Time index(n)');
ylabel('x1[n]');
title('First sequence');
subplot(3,1,2)
stem(n2,x2);
xlabel('Time index(n)');
ylabel('x2[n]');
title('Second sequence');
subplot(3,1,3)
stem(n3,x3);
xlabel('Time index(n)')
ylabel('x3[n]');
title('Cicle shifted sequence');

PROCEDURE:
Type the above code in Matlab, simulate the same and get the output.

SIMULATION RESULTS:

OBSERVATION:
The resulting convolved signal has the same length as the original
signals. This contrasts with linear convolution, where the length of the
resulting signal is the sum of the lengths of the original signals minus
one.
Since circular convolution involves wrapping the signals around,
the resulting convolved signal exhibits periodic behaviour. This
periodicity can be observed by plotting the convolved signal and noticing
the repeating patterns.
CALCULATION:
1.Given two discrete time signals x[n] and h[n] of lengths N and M,
respectively.
2.If necessary, zero-pad the signals to make them of equal length,
i.e., N = M = max(N, M). This step ensures that the resulting convolved
signal has the same length as the original signals.
3.Take the Discrete Fourier Transform (DFT) of both signals using
an FFT algorithm, resulting in X[k] and H[k], where k represents the
frequency index.
4.Perform point-wise multiplication of the frequency domain
representations: Y[k] = X[k] * H[k].
5.Take the inverse DFT (IDFT) of the product Y[k] using an inverse
FFT algorithm to obtain the circularly convolved signal y[n].
6.If necessary, truncate the length of y[n] to match the length of the
original signals, removing any additional zero-padding.
CONCLUDING REMARKS:
The circular convolution of two discrete time signals have been
calculated and the same has been plotted

EXPERIMENT-3B
Spectrum Analysis using Discrete Fourier Transform (DFT)

AIM:

To perform Spectrum Analysis using Discrete Fourier Transform (DFT)

SOFTWARE REQUIRED:
Matlab software
THEORY:
Given a discrete-time signal x[n] of length N, the DFT is calculated
as follows:

X[k] = sum(x[n] * exp(-j*2*pi*k*n/N)),


for k = 0 to N-1

|X[k]| = sqrt(Re[X[k]]^2 + Im[X[k]]^2)

where Re[X[k]] and Im[X[k]] represent the real and imaginary


parts of X[k] respectively.

MATLAB SOURCE CODE:


clc
clear all
close all
x=input('Enter Sample values of x');
L=length(x);
N=input('Enter no. of DFT points');
if(N<L)
error('N must be>=L');
end
Xk=zeros(1,N);
n1=0:L-1;
k1=0:N-1;
for k=0:N-1
for n=0:N-1
Xk(k+1)=Xk(k+1)+x(n+1)*exp(-i*2*pi*k*n/N);
end
end
disp("DFT Cofficients")
Xk
m=abs(Xk);
p=(angle(Xk)*180)/pi;
ix=zeros(1,N);
for n=0:N-1
for k=0:N-1
ix(n+1)=ix(n+1)+Xk(k+1)*exp(i*2*pi*k*n/N);
end
end
disp("IDFT of X[k]");
ix=ix./N
figure
subplot(2,2,1);
stem(n1,x);
xlabel('Time index(n)');
ylabel('x[n]');
title('Given Sequence');
subplot(2,2,2);
stem(k1,m);
xlabel('Time index(n)');
ylabel('|X[k]|');
title('Magnitude Spectrum of X[k]');
subplot(2,2,3);
stem(k1,p);
xlabel('Time index(n)');
ylabel('Phase');
title('Phase Spectrum of X[k]');
subplot(2,2,4);
stem(n1,double(ix));
xlabel('Time index(n)');
ylabel('x[n]');
title('IDFT of X[k]');

title('Correlated signal');

PROCEDURE:
Type the above code in Matlab, simulate the same and get the output.

SIMULATION RESULTS:
OBSERVATION:
1. He DFT provides frequency resolution determined by the
length of the input signal. A longer signal or higher DFT length
allows for finer frequency resolution, meaning smaller frequency
bins and the ability to distinguish closely spaced frequencies.

CALCULATION:
1.Obtain a discrete-time signal x[n] of length N.
2.Apply any necessary preprocessing steps, such as
windowing the signal to reduce spectral leakage effects. Let's
denote the windowed signal as x_w[n].
3.Calculate the DFT of the windowed signal x_w[n] using the
DFT formula:

X[k] = sum(x_w[n] * exp(-j * 2 * pi * k * n / N)), for k = 0 to N-1

where j is the imaginary unit, n represents the sample index,


and X[k] is the complex-valued DFT output.

4.Compute the magnitude spectrum by taking the absolute


value of each complex value in X[k]:

|X[k]| = sqrt(Re[X[k]]^2 + Im[X[k]]^2)

where Re[X[k]] and Im[X[k]] represent the real and imaginary


parts of X[k] respectively.

5.Calculate the corresponding frequency values for each bin


k by scaling the frequency bins by the sampling rate and dividing
by N: f_k = k * (Fs / N)

where f_k represents the frequency associated with bin k,


and Fs is the sampling rate.
6. Optionally, compute the phase spectrum by taking the
complex argument (angle) of each complex value in X[k]:

phase(X[k]) = atan2(Im[X[k]], Re[X[k]])

where phase(X[k]) represents the phase spectrum.

7, Visualize the magnitude spectrum |X[k]| and/or phase


spectrum phase(X[k]) using suitable plots, such as a frequency
spectrum plot or spectrogram.
CONCLUDING REMARKS:
Spectrum Analysis using Discrete Fourier Transform (DFT)
experiment.

You might also like