Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

National University of Modern Languages, Islamabad Communication System Lab

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

National University of Modern Languages,

Islamabad
Communication System Lab

EXPERIMENT # 02: Convolution, Correlation and DFT

Name of Student: …………………………………..

Roll No.: ……………………………………………

Date of Experiment: ………………………………..

Report submitted on: ………………………………..

Marks obtained: ……………………………………

Remarks: ……………………………………………

Instructor’s Signature: …………………………….....

Department of Engineering, NUML, Islamabad Page 1


Lab Session 2
Convolution, Correlation and DFT
Objective
1. Analysis of convolution of different signals
2. Analysis of correlation of different signals
3. To find the Discrete Fourier Transform of a different sinusoidal sequence.

Convolution
Definition of convolution

The convolution sum describes the relationship between the input and output of discrete-time system, and
is easily evaluated to a compute as a sum of products of numbers.

To perform discrete time convolution, x[n]*h[n], define the vectors x and h with elements in the
sequences x[n] and h[n].
Then use the command

y = conv(x,h)

This command assumes that the first element in x and the first element in h correspond to n = 0, so that
the first element in the resulting output vector corresponds to n = 0 . If this is not the case, then the output
vector will be computed correctly, but the index will have to be adjusted.

Example

>> x = [1 1 1 1 1];

>> h = [0 1 2 3];

>> y = conv(x,h)

Result of conv of x and y is

y=

Columns 1 through 7

0 1 3 6 6 6 5

Column 8

Department of Engineering, NUML, Islamabad Page 2


Cross correlation

Cross-correlations are useful for determining the time delay between two signals, e.g. for determining
time delays for the propagation of acoustic signals across a microphone array.After calculating the cross-
correlation between the two signals, the maximum of the cross-correlation function indicates the point in
time where the signals are best aligned,

f= xcorr(x,y) returns the cross-correlation sequence in a length 2*N-1 vector, where x and y are length N
vectors (N>1). If x and y are not the same length, the shorter vector is zero-padded to the length of the
longer vector.

DEFINITION OF 'AUTOCORRELATION'
A mathematical representation of the degree of similarity between a given time series and a lagged
version of itself over successive time intervals.

DEFINITION OF DFT AND IDFT

The Fourier transform takes a signal in the so called time domain (where each sample in the signal is
associated with a time) and maps it, without loss of information, into the frequency domain. The
frequency domain representation is exactly the same signal, in a different form. The inverse Fourier
transform maps the signal back from the frequency domain into the time domain.

A time domain signal will usually consist of a set of real values, where each value has an associated time
(e.g., the signal consists of a time series). The Fourier transform maps the time series into a a frequency
domain series, where each value is a complex number that is associated with a given frequency. The
inverse Fourier transform takes the frequency series of complex values and maps them back into the
original time series. Assuming that the original time series consisted of real values, the result of the IDFT
will be complex numbers where the imaginary part is zero.

GENERATION OF DISCRETE FOURIER TRANSFORM (DFT) OF A SEQUENCE

In this program the Discrete Fourier Transform


(DFT) of a sequence x[n] is generated by using the formula,
N-1
X(k) = Σ x(n) e -2πjk / N
Where, X(k)  DFT of sequence x[n]

n=0

N represents the sequence length and it is calculated by using the command ‘length’. The DFT of any
sequence is the powerful computational tool for performing frequency analysis of discrete-time signals.

MATLAB CODE :

clc;
clear all;
close all;
a=input('Enter the sequence :');
N=length(a);
disp('The length of the sequence is:');N

Department of Engineering, NUML, Islamabad Page 3


for k=1:N
y(k)=0;
for i=1:N
y(k)=y(k)+a(i)*exp((-2*pi*j/N)*((i-1)*(k-1)));
end;
end;
k=1:N
disp('The result is:');y
figure(1);
subplot(211);
stem(k,abs(y(k)));
grid;
xlabel('sample values n-->');
ylabel('Amplitudes-->');
title('Mangnitude response of the DFT of given sequence');
subplot(212);
stem(angle(y(k))*180/pi);
grid;
xlabel('sample values n-->');
ylabel('phase-->');
title('Phase response of the DFT of given sequence');

Magnitude and phase response of DFT

GENERATION OF INVERSE DISCRETE FOURIER TRANSFORM (IDFT) OF A SEQUENCE


PROGRAM DESCRIPTION :

In this program the Inverse Discrete Fourier Transform ( IDFT ) of a sequence X(k) is generated by using
the formula,

N-1

x [n] = Σ X(k) e 2πjk/N


Where, x[n]  IDFT of sequence X (k)

Department of Engineering, NUML, Islamabad Page 4


n=0

N represents the sequence length and it is calculated by using the command ‘length’.
The IDFT results in the sequence from its DFT.

MATLAB CODE :
clc;
clear all;
close all;
a=input('Enter the sequence :');
N=length(a);
disp('The length of the sequence is:');N
for n=1:N
y(n)=0;
for k=1:N
y(n)=y(n)+a(k)*exp((2*pi*j*(k-1)*(n-1))/N);
end;
end;
n=1:N
y1=1/N*y(n);
disp('The result is:');y1
figure(1);
stem(n,y1);
grid;
xlabel('sample values n-->');
ylabel('Amplitudes-->');
title('Mangnitude response of the IDFT of given DFT');

Inverse DFT results

FINDING THE FFT OF DIFFERENT SIGNALS

Fast Fourier transform (FFT) algorithm computes the discrete Fourier transform (DFT) of a sequence,
or its inverse. Fourier analysis converts a signal from its original domain (often time or space) to a
representation in the frequency domain and vice versa.

PROGRAM DESCRIPTION: In this program using the command FFT for impulse response. In the
process of finding the FFT the length of the FFT is taken as N. The FFT consists of two parts:

Department of Engineering, NUML, Islamabad Page 5


MAGNITUDE PLOT and PHASE PLOT. The magnitude plot is the absolute value of magnitude versus
the samples and the phase plot is the phase angle versus the samples.

MATLAB CODE:

clc;
clear all;
close all;
%impulse sequence
t=-2:1:2;
y=[zeros(1,2) 1 zeros(1,2)];
subplot (3,1,1);
stem(t,y);
grid;
input('y=');
disp(y);
title ('Impulse Response');
xlabel ('time -->');
ylabel ('--> Amplitude');
xn=y;
N=input('enter the length of the FFT sequence: ');
xk=fft(xn,N);
magxk=abs(xk);
angxk=angle(xk);
k=0:N-1;
subplot(3,1,2);
stem(k,magxk);
grid;
xlabel('k');
ylabel('|x(k)|');
subplot(3,1,3);
stem(k,angxk);
disp(xk);
grid;
xlabel('k');
ylabel('arg(x(k))');

Command window

y=[1 2 3 4]

0 0 1 0 0

enter the length of the FFT sequence: 8

Columns 1 through 4

1.0000 0 - 1.0000i -1.0000 0 + 1.0000i

Columns 5 through 8

1.0000 0 - 1.0000i -1.0000 0 + 1.0000i

Department of Engineering, NUML, Islamabad Page 6


Output graph

Lab task

1) Compute cross-correlation of the sequences


x=[1, 2, 3, 4] and h=[4, 3, 2, 1]
2) Compute auto-correlation of sequence of any random vector of length 6
3) Compute discrete Fourier transform(fft)
X(n)= n 0<=n<8

Exercise
Q1:
Consider the analog signal xa(t) given by
a) Xa(t)=3cos(2000πt)+ 5sin(6000πt)+ cos(8000πt)
Plot it in matlab
b) Compute the autocorrelation of Xa(t) and plot it.
Without using matlab command (try to do it with loop)
c) Explain Relation between convolution and correlation
Q2:

Compute discrete Fourier transform (fft) using the command FFT for step, ramp and
exponential sequences .Plot input signal its magnitude and phase angles.

Department of Engineering, NUML, Islamabad Page 7

You might also like