Sunteți pe pagina 1din 5

INSTITUTE OF BIOMEDICAL ENGINEERING & TECHNOLOGY LIAQUAT

UNIVERSITY OF MEDICAL & HEALTH SCIENCES JAMSHORO

Subject: Biosignal Processing Year:3rd, Semester6th


LAB HANDOUT- 04

Name: Roll No: _____________________

Score: Signature of Tutor: Date:________________

Convolution and Correlation

LAB OBJECTIVE:

To generate the basic concept regarding convolution and cross correlation

CONVOLUTION:

The response y(n) of the LTI system as a function of the input signal x(n) and the unit
sample (impulse) response h(n) is a convolution sum between x(n) & h(n). The input x(n)
is convolved with the impulse response h(n) to yield the output y(n).

MATHEMATICAL MEANS:


y ( n) = �x(k )h(n - k )
k =-�

THE CONVOLUTION OF THE EQUATION:

y ( n) = h( n) �x( n)

SYNTAX
w = conv(u,v)
w = conv(u,v,shape)
shape — Subsection of convolution
'full' (default) | 'same' | 'valid'

It is implemented in MATLAB by the command, “conv”, provided the two sequences to


be convolved are of finite length. For example, the output sequence of an FIR system can
be computed by convolving its impulse response with the given finite length input
sequence

1
INSTITUTE OF BIOMEDICAL ENGINEERING & TECHNOLOGY LIAQUAT
UNIVERSITY OF MEDICAL & HEALTH SCIENCES JAMSHORO
1 'full' Full convolution (default).
2 'same' Central part of the convolution of the same size as u.
3 'valid' Only those parts of the convolution that are computed without the zero-padded
edges. Using this option, length(w) is max(length(u)-length(v)+1,0), except
when length(v) is zero. If length(v) = 0, then length(w) = length(u).

IN LAB TASK:

TASK#1:
Write an Example of Convolution in MATLAB:

CODE:
%% Performs convolution between two signals
h=[5 4 3 2 1]; % First Sigal
x=[1 1 1 1 1]; % Second Signal
c=conv(h,x); % Convolution result stored in variable ‘c’
m=length(c)-1; %Find number of convolution output terms
n=0:1:m; %Generate time vector
stem(n,c); %Plot the output
title('Convolution between x and h');
grid on; %Show grid on the plot

OUTPUT:

Convolution between x and h


15

10

0
0 1 2 3 4 5 6 7 8

Figure 1: Convolution between x and h

2
INSTITUTE OF BIOMEDICAL ENGINEERING & TECHNOLOGY LIAQUAT
UNIVERSITY OF MEDICAL & HEALTH SCIENCES JAMSHORO
CORRELATION:

Correlation is a mathematical operation that is very similar to convolution. Just as with


convolution, correlation uses two signals to produce a third signal. This third signal is
called the cross-correlation of the two input signals. If a signal is correlated with itself,
the resulting signal is instead called the autocorrelation.
Convolution is the relationship between a system's input signal, output signal, and
impulse response whereas Correlation is a way to detect a known waveform in a noisy
background.
Suppose we have two DT signals, x(n) and y(n). There cross correlation r xy(j) is
calculated as:

rxy (n) = �x(k ) y(k - n)
k =-�

SYNTAX

The cross correlation of two signals is implemented in MATLAB by “xcorr” function.

TASK#2:
Write an Example of Correlation in MATLAB:

CODE:
Instructions:
 Please complete your lab reports neatly.
%% Cross Correlation
 All code must be commented appropriately and included in the file submitted.
 f=1;
Handouts are required
%Frequency to be submitted by the next lab.
of signal
 Fs=20*f;
Make sure%Sampling Frequency
your handout contains of the required
all the signal information and that the file is
Ts=1/Fs; %Determine sampling time
named correctly.
nTs=0:Ts:1; %Indices of samples in the signal
sig1=sin(2*pi*f*nTs); %Compute sample values of the signal
sig2=sin(2*pi*f*nTs+pi); %Compute sample values of the signal
corsig=xcorr(sig1,sig2); %Compute the correlation between the
signals
subplot(311);plot(nTs,sig1); %Plot the signals
title('Correlation between two sinusoids'); %Give title to plot
xlabel('Time'); %Give label to x-axis
ylabel('Amplitude'); %Give label to y-axis
grid on; %display grid
subplot(312);plot(nTs,sig2); %Plot the signals
xlabel('Time'); %Give label to x-axis
ylabel('Amplitude'); %Give label to y-axis
grid on; %display grid
subplot(313);stem(-20:20,corsig); %Plot the signals
xlabel('Time Lag'); %Give label to x-axis
ylabel('Amplitude'); %Give label to y-axis
grid on; %display grid

3
INSTITUTE OF BIOMEDICAL ENGINEERING & TECHNOLOGY LIAQUAT
UNIVERSITY OF MEDICAL & HEALTH SCIENCES JAMSHORO

OUTPUT:
Correlation between two sinusoids

A m p litu de
1

-1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Time
A m p litu de

-1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Time
A m p litu de

10

-10
-20 -15 -10 -5 0 5 10 15 20
Time Lag

Figure 2: Correlation output between two sinusoids

POST LAB TASK:

1. and find the convolution of given polynomial equation.


2. Create two vectors. Find the central part of the convolution of u and v that is the same size
as u.
3. Create two vectors whereas generate those parts of the convolution that are computed
without the zero-padded edges.
4. Write a program to perform Autocorrelation of an input sequence.
5. Write the difference between correlation and covariance.

BONUS TASK:
Convolute an exponential signal with a unit step function, and plot three different
graph in one window using subplot command.

Instructions:
 Please complete your lab reports neatly.
 All code must be commented appropriately and included in the file submitted.
 Handouts are required to be submitted by the next lab.
 Make sure your handout contains all the required information and that the file is
named correctly.

4
INSTITUTE OF BIOMEDICAL ENGINEERING & TECHNOLOGY LIAQUAT
UNIVERSITY OF MEDICAL & HEALTH SCIENCES JAMSHORO

S-ar putea să vă placă și