You are on page 1of 2

Digital Signal Processing

Representation of Difference Equation


Filtering with moving averager
Lab # 5

Lab work
When we sample an analogue signal, we get discrete samples of analogue
signal. To represent the samples of the signal, we use difference
equation. Purpose of this lab is to show how to represent the difference
equation or samples of signals in MATLAB. We will also see different
interpretations of row vectors in MATLAB. In the end we will create a
moving averaging filter and see its effect on signal after filtering.

Difference equation is the mathematical representation of samples of


signal obtained after sampling of signal. In MATLAB, difference equation
can be represented by a row vector with each element of row vector
representing a delayed/scaled sample of difference equation. If we have a
difference equation given below

signal = x( n − 5) + 5 x( n − 4) −2 x( n −2) +8 x( n)

Its representation in MATLAB will be

signal=[1 5 0 -2 0 1];

In MATLAB, row vector can have many different interpretations. A row


vector in MATLAB may be representing some stream of binary data with each
2, 3, or 4 etc set of bits representing some level/code etc. Row vector
may be representing difference equation or it may be representing some
polynomial and so on. Below are few possibilities of row vectors in
MATLAB

Binarydata = [1 1 0 1 0 1 1 1 0 0……] % this row vector represent stream


of binary data

Samples = [0.3 1.7 3.3 5.4 2.6 ……] % this row vector represent the
difference equation

Polynomial = [2 3 0 0 -5] % this vector represent polynomial 2x4+3x3-5

For MATLAB, a row vector is just a row vector; it cannot interpret what
each row vector is representing. It’s the programmer or user of MATLAB
who know what each row vector is representing. For example, when we
create a time vector given below

T=0:0.1:1;

T will be equal to T = [0 0.1 0.2 0.3 … 1]; % a row vector


For MATLAB, T is just a row vector and it cannot interpret if it is
representing time. It is user who knows T is representing time in
seconds. MATLAB cannot tell if its unit is seconds or milliseconds etc,
but it depends on programmer’s interpretation. Similarly when we generate
a sinusoid signal using T

Signal=cos(2*pi*3*t);
Digital Signal Processing

Values in Signal will be Signal=[1 0.8 0.5 …] % a row vector


Again for MATLAB, Signal is just a row vector, and it cannot know if it
is representing samples or difference equation of sinusoid signal. It’s
the programmer who knows what Signal is representing and uses it
accordingly.

Lab tasks:
Step1:
• Create a signal represented by following difference equation
Signal= 2x[n-1]+4x[n-2]+6x[n-3]+8x[n-4]+10x[n-5]+8x[n-6]+
6x[n-7]+5x[n-8]+4x[n-9]+4x[n-10]+5x[n-11]+6x[n-12]+7x[n-13]+
5x[n-14]+3x[n-15]+3x[n-16]+7x[n-17]+7x[n-18]+3x[n-19]+3x[n-20]+
7x[n-21]+ 7x[n-22]+3x[n-23]+3x[n-24]+x[n-29]+2x[n-30]+3x[n-31]+
4x[n-32]+ 5x[n-33]+6x[n-34]+5x[n-35]+4x[n-36]+3x[n-37]+
2x[n-38]+1x[n-39];
• Plot it to see its graph

Step2:
• Create a moving averaging filter of length 2
1 1
Averaging_filter= x[n]+ x[n-1]
2 2

Step3:
• To apply filter to signal, we convolve them. Use conv command in
MATLAB to apply above filter to the signal. Plot the resultant
signal after applying filter to see the change.

TASK2
• Repeat the above steps using averaging filter of length 4.
• Repeat the above steps using averaging filter of length 8.

You might also like