0% found this document useful (0 votes)
13 views5 pages

DSP Lab 03

This document outlines a lab experiment focused on Digital Signal Processing, specifically on difference equations, system identification, convolution, and deconvolution using MATLAB. Students will learn to represent discrete time systems, perform system identification, and implement convolution and deconvolution techniques. The lab includes objectives, required resources, and MATLAB code examples for practical implementation of the concepts discussed.

Uploaded by

khizar abbas
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)
13 views5 pages

DSP Lab 03

This document outlines a lab experiment focused on Digital Signal Processing, specifically on difference equations, system identification, convolution, and deconvolution using MATLAB. Students will learn to represent discrete time systems, perform system identification, and implement convolution and deconvolution techniques. The lab includes objectives, required resources, and MATLAB code examples for practical implementation of the concepts discussed.

Uploaded by

khizar abbas
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/ 5

International Islamic University, Islamabad

Faculty of Engineering and Technology


Department of Electrical and Computer Engineering

Digital Signal Processing Lab

EXPERIMENT # 03: Difference Equation, System Identification,


Convolution & Deconvolution

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

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

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


Difference Equation, System Identification,
Convolution & Deconvolution
1. Objective
This lab focuses on representing discrete time systems using difference equations in MATLAB.
System identification, Convolution and Deconvolution will be implemented in MATLAB. After
performing the lab, the students will be able to
• Create discrete time systems using difference equation in MATLAB
• Identify systems, perform convolution and deconvolution in MATLAB.

2. Resources Required
• A computer
• MATLAB 7.0 or higher

3. Difference Equation:
The difference equation is a formula for computing an output sample at time based on past and
present input samples and past output samples in the time domain. We may write the general,
causal, LTI difference equation as follows:
𝑦(𝑛) = 𝑏0𝑥(𝑛) + 𝑏1𝑥(𝑛 − 1) + ⋯ + 𝑏𝑀𝑥(𝑛) − 𝑎1𝑦(𝑛 − 1) − ⋯ − 𝑎𝑁𝑦(𝑛 − 𝑁)
𝑀 𝑁

𝑦(𝑛) = ∑ 𝑏𝑖 𝑥(𝑛 − 𝑖) − ∑ 𝑎𝑗 𝑦(𝑛 − 𝑗)


𝑖=0 𝑗=1

4. FIR System Identification

Estimating an impulse response from input-output measurements is called system identification,

Cross-correlation can be used to compute the impulse response h(n) of a filter from the cross-
correlation of its input and output signals x(n) and y(n) = x(n)*h(n) , respectively. To see this, note
that, by the correlation theorem,

𝑥 ⋆ 𝑦 ⇔ 𝑋̅ ∙ 𝑌 = 𝑋̅ ∙ (𝐻 ∙ 𝑋) = 𝐻 ∙ |𝑋|2

Therefore, the frequency response equals the input-output cross-spectrum divided by the input
power spectrum:

𝑋̅ ⋅ 𝑌 𝑅̂𝑥𝑦
𝐻= =
|𝑋|2 𝑅̂𝑥𝑥

where multiplication and division of spectra are defined point wise, i.e.,
2
𝐻(𝑤𝑘) = 𝑋(𝑤𝑘 ) ∙ 𝑌(𝑤𝑘 )/|𝑋(𝑤𝑘) |

Digital Signal Processing Lab Page 2


% Matlab Code
% correlation to compute the impulse response
% of a filter given its input and output.
% This is called "FIR system identification".

close all; clear all; clc;


Nx = 32; % input signal length
Nh = 10; % filter length
Ny = Nx+Nh-1; % max output signal length % FFT size to
accommodate cross-correlation:
Nfft = 2^nextpow2(Ny); % FFT wants power of 2
x = rand(1,Nx); % input signal = noise
%x = 1:Nx; % input signal = ramp
h = [1:Nh]; % the filter
xzp = [x,zeros(1,Nfft-Nx)]; % zero-padded input
yzp = filter(h,1,xzp); % apply the filter
X = fft(xzp); % input spectrum
Y = fft(yzp); % output spectrum
Rxx = conj(X) .* X; % energy spectrum of x
Rxy = conj(X) .* Y; % cross-energy spectrum
Hxy = Rxy ./ Rxx; % should be the freq. response
hxy = ifft(Hxy); % should be the imp. response
hxy(1:Nh) % print estimated impulse response
freqz(hxy,1,Nfft); % plot estimated freq response

err = norm(hxy - [h,zeros(1,Nfft-Nh)])/norm(h);


disp(sprintf(['Impulse Response Error = ',...
'%0.14f%%'],100*err));

err = norm(Hxy-fft([h,zeros(1,Nfft-Nh)]))/norm(h);
disp(sprintf(['Frequency Response Error = ',...
'%0.14f%%'],100*err));

5. Convolution in Matlab (without using built in command)

Output of LTI system y(n) can be computed by convolving the input signal x(n) with system
response h(n).
One method to implement is a fast convolution method which includes fft of signal and system
response.
For much longer convolutions, the savings become enormous compared with “direct'' convolution.
This happens because direct convolution requires on the order of 𝑁 2 operations (multiplications
and additions), while FFT-based convolution requires on the order of 𝑁𝑙𝑜𝑔(𝑁) operations, where
𝑙𝑜𝑔(𝑁) denotes the logarithm-base-2 of 𝑁.

Digital Signal Processing Lab Page 3


close all; clear all; clc;
N = 1024; % FFT much faster at this length
t = 0:N-1; % [0,1,2,...,N-1]
h = exp(-t); % filter impulse reponse
H = fft(h); % filter frequency response
x = ones(1,N); % input = dc (any signal will do)
Nrep = 100; % number of trials to average
t0 = clock; % latch the current time
for i=1:Nrep, y = conv(x,h); end % Direct convolution
t1 = etime(clock,t0)*1000; % elapsed time in msec
t0 = clock;
for i=1:Nrep, y = ifft(fft(x) .* H); end % FFT convolution
t2 = etime(clock,t0)*1000;
disp(sprintf([...
'Average direct-convolution time = %0.2f msec\n',...
'Average FFT-convolution time = %0.2f msec\n',...
'Ratio = %0.2f (Direct/FFT)'],...
t1/Nrep,t2/Nrep,t1/t2));

6. Another simple way to implement Convolution


A simple code is created using C++ logics to implement convolution formula of sum of products

close all; clear all; clc;


x=input('Enter x: ');
h=input('Enter h: ');
m=length(x); n=length(h);
X=[x,zeros(1,n)];
H=[h,zeros(1,m)];
for i=1:n+m-1 Y(i)=0;
for j=1:m
if(i-j+1>0)
Y(i)=Y(i)+X(j)*H(i-j+1);
else
end
end
end
Y
stem(Y);
ylabel('Y[n]');
xlabel('----->n');
title('Convolution of Two Signals without conv function');

Digital Signal Processing Lab Page 4


7. Deconvolution:
If the impulse response and the output of the system are known, then the procedure to obtain
the unknown input is known as Deconvolution. Deconvolution can be implemented by a similar
procedure to that of convolution or system identification. i.e.
𝑦(0)
𝑥(0) =
ℎ(0)
And
𝑦(𝑛) − ∑𝑛𝑚=1 ℎ(𝑚)𝑥(𝑛 − 𝑚)
𝑥(𝑛) =
ℎ(0)

8. Lab Task:

1. Write code for deconvolution process to find an unknown input signal.

2. Write a code for convolution process using convolution as an inner product (hint: use
toeplitz matrix or convmtx for help)

3. In system identification code why we are using zero padding, what will be the output if we
don’t use zero padding?

Digital Signal Processing Lab Page 5

You might also like