National University of Modern Languages, Islamabad Communication System Lab
National University of Modern Languages, Islamabad Communication System Lab
National University of Modern Languages, Islamabad Communication System Lab
Islamabad
Communication System Lab
Remarks: ……………………………………………
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)
y=
Columns 1 through 7
0 1 3 6 6 6 5
Column 8
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.
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.
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
In this program the Inverse Discrete Fourier Transform ( IDFT ) of a sequence X(k) is generated by using
the formula,
N-1
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');
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:
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
Columns 1 through 4
Columns 5 through 8
Lab task
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.