The Moving Average System - Project |, Study notes of Digital Signal Processing

SOLUTION Laboratory Exercise Material Type: Notes; Class: Digital Signal Processing; Subject: Electrical and Computer Engineering; University: United Arab Emirates University; Term: Forever 1989;

Typology: Study notes

2010/2011

Uploaded on 12/06/2011

i-mohd
i-mohd 🇦🇪

2 documents

1 / 50

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
Name: SOLUTION
Section:
Laboratory Exercise 2
DISCRETE-TIME SYSTEMS: TIME-DOMAIN REPRESENTATION
2.1 SIMULATION OF DISCRETE-TIME SYSTEMS
Project 2.1 The Moving Average System
A copy of Program P2_1 is given below:
% Program P2_1
% Simulation of an M-point Moving Average Filter
% Generate the input signal
n = 0:100;
s1 = cos(2*pi*0.05*n); % A low-frequency sinusoid
s2 = cos(2*pi*0.47*n); % A high frequency sinusoid
x = s1+s2;
% Implementation of the moving average filter
M = input('Desired length of the filter = ');
num = ones(1,M);
y = filter(num,1,x)/M;
% Display the input and output signals
clf;
subplot(2,2,1);
plot(n, s1);
axis([0, 100, -2, 2]);
xlabel('Time index n'); ylabel('Amplitude');
title('Signal #1');
subplot(2,2,2);
plot(n, s2);
axis([0, 100, -2, 2]);
xlabel('Time index n'); ylabel('Amplitude');
title('Signal #2');
subplot(2,2,3);
plot(n, x);
axis([0, 100, -2, 2]);
xlabel('Time index n'); ylabel('Amplitude');
title('Input Signal');
subplot(2,2,4);
plot(n, y);
axis([0, 100, -2, 2]);
xlabel('Time index n'); ylabel('Amplitude');
title('Output Signal');
axis;
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32

Partial preview of the text

Download The Moving Average System - Project | and more Study notes Digital Signal Processing in PDF only on Docsity!

Name: SOLUTION

Section:

Laboratory Exercise 2

DISCRETE-TIME SYSTEMS: TIME-DOMAIN REPRESENTATION

2.1 SIMULATION OF DISCRETE-TIME SYSTEMS

Project 2.1 The Moving Average System

A copy of Program P2_1 is given below:

% Program P2_ % Simulation of an M-point Moving Average Filter % Generate the input signal n = 0:100; s1 = cos(2pi0.05n); % A low-frequency sinusoid s2 = cos(2pi0.47n); % A high frequency sinusoid x = s1+s2; % Implementation of the moving average filter M = input('Desired length of the filter = '); num = ones(1,M); y = filter(num,1,x)/M; % Display the input and output signals clf; subplot(2,2,1); plot(n, s1); axis([0, 100, -2, 2]); xlabel('Time index n'); ylabel('Amplitude'); title('Signal #1'); subplot(2,2,2); plot(n, s2); axis([0, 100, -2, 2]); xlabel('Time index n'); ylabel('Amplitude'); title('Signal #2'); subplot(2,2,3); plot(n, x); axis([0, 100, -2, 2]); xlabel('Time index n'); ylabel('Amplitude'); title('Input Signal'); subplot(2,2,4); plot(n, y); axis([0, 100, -2, 2]); xlabel('Time index n'); ylabel('Amplitude'); title('Output Signal'); axis;

Answers:

Q2.1 The output sequence generated by running the above program for M = 2 with x[n] =

s1[n]+s2[n] as the input is shown below.

Time index n

Amplitude

Signal #

Time index n

Amplitude

Signal #

Time index n

Amplitude

Input Signal

Time index n

Amplitude

Output Signal

The component of the input x[n] suppressed by the discrete-time system simulated by this

program is – Signal #2, the high frequency one (it is a low pass filter).

Q2.2 Program P2_1 is modified to simulate the LTI system y[n] = 0.5(x[n]–x[n–1]) and

process the input x[n] = s1[n]+s2[n] resulting in the output sequence shown below:

Note: the code is not required; however, it is included here to demonstrate a tricky way of

making the modification to P2_1.

% Program Q2_ % Modification of P1_1 to convert it to a high pass filter % Generate the input signal n = 0:100; s1 = cos(2pi0.05n); % A low-frequency sinusoid s2 = cos(2pi0.47n); % A high frequency sinusoid x = s1+s2; % Implementation of high pass filter M = input('Desired length of the filter = '); % By comparing eq. (2.13) to (2.3), you can see that "num" % actually contains the impulse response (times the constant % M). What we are actually doing in Q2.2 is multiplying the % impulse response of the low pass filter in P2_1 by the % sequency (-1)^n. This shifts the low pass frequency

Q2.3 Program P2_1 is run for the following values of filter length M and following values of the fre-

quencies of the sinusoidal signals s1[n] and s2[n]. The output generated for these

different values of M and the frequencies are shown below.

f1=0.05; f2=0.47; M=

0 50 100

0

1

2

Time index n

Amplitude

Signal #

0 50 100

0

1

2

Time index n

Amplitude

Signal #

0 50 100

0

1

2

Time index n

Amplitude

Input Signal

0 50 100

0

1

2

Time index n

Amplitude

Output Signal

From these plots we make the following observations – with M=15, the low pass

characteristic is much more pronounced (the passband is now very narrow). s2 is still

nearly eliminated in the output signal. s1 is still passed, but at an attenuated level.

f1=0.30; f2=0.47; M=

0 50 100

0

1

2

Time index n

Amplitude

Signal #

0 50 100

0

1

2

Time index n

Amplitude

Signal #

0 50 100

0

1

2

Time index n

Amplitude

Input Signal

0 50 100

0

1

2

Time index n

Amplitude

Output Signal

From these plots we make the following observations – with M=4, this filter performs more

smoothing than in the case M=2. Both s1 and s2 are high frequency in this case, and

they are both substantially attenuated in the output.

f1=0.05; f2=0.10; M=

0 50 100

0

1

2

Time index n

Amplitude

Signal #

0 50 100

0

1

2

Time index n

Amplitude

Signal #

0 50 100

0

1

2

Time index n

Amplitude

Input Signal

0 50 100

0

1

2

Time index n

Amplitude

Output Signal

The output signal generated by running this program is plotted below.

Time index n

Amplitude

Input Signal

Time index n

Amplitude

Output Signal

The results of Questions Q2.1 and Q2.2 from the response of this system to the swept-

frequency signal can be explained as follows: we see again that this system is a low pass

filter. At the left of the graphs, the input signal is a low frequency sinusoid that is

passed to the output without attenuation. As n increases, the frequency of the input

rises, and increasing attenuation is seen at the output. In Q2.1, the input was a sum of

two sinusoids s1 and s2 with f1=0.05 and f2=0.47. The swept frequency input of

Q2.4 reaches a frequency of 0.05 at n=10, where there is virtually no attenuation in the

output shown above. This “explains” why s1 was passed by the system in Q2.1. The

swept frequency input of Q2.4 reaches a frequency of 0.47 at approximately n=94,

where the attenuation of the system is substantial. This “explains” why s2 was almost

completely suppressed in the output in Q2.1.

There is no direct relationship between the result shown above for Q2.4 and the result

obtained in Q2.2. However, using frequency domain concepts (Chapter 3) we can

reason that, if the swept frequency signal was input to the system y[n] =

0.5(x[n] – x[n-1]), we would see a result opposite to what is shown above.

Since the system would then be a high pass filter, there would be substantial attenuation

of the output at the left side of the graph and virtually no attenuation at the right side of

the graph. This “explains” why in Q2.2 the low frequency component s1 was

suppressed in the system output, whereas the high frequency component s2 was

passed.

Project 2.2 (Optional) A Simple Nonlinear Discrete-Time System

A copy of Program P2_2 is given below:

% Program P2_ % Generate a sinusoidal input signal clf; n = 0:200; x = cos(2pi0.05n); % Compute the output signal x1 = [x 0 0]; % x1[n] = x[n+1] x2 = [0 x 0]; % x2[n] = x[n] x3 = [0 0 x]; % x3[n] = x[n-1] y = x2.x2-x1.*x3; y = y(2:202); % Plot the input and output signals subplot(2,1,1) plot(n, x) xlabel('Time index n');ylabel('Amplitude'); title('Input Signal') subplot(2,1,2) plot(n,y) xlabel('Time index n');ylabel('Amplitude'); title('Output signal');

Answers:

Q2.5 The sinusoidal signals with the following frequencies as the input signals were used to

generate the output signals: f=0.05, f=0.1, f=0.

The output signals generated for each of the above input signals are displayed below:

0 20 40 60 80 100 120 140 160 180 200

0

1

2

Time index n

Amplitude

Output Signal

The output signals depend on the frequencies of the input signal according to the following

rules: up to “edge effects” visible at the very left and right sides of the first graph, the

output is given by y[n] = sin

2

(2πf).

This observation can be explained mathematically as follows: Let ω =^2 π^ f. Then

x [ ] n = cos( ω n )and

2 2

x [ ] n = cos ( ω n ) (1.1)

Now, x n [ + 1] = cos[ ω( n + 1)] = cos( ω n + ω) and x n [ − 1] = cos[ ω( n − 1)]=

cos( ω n − ω) , so x n [ + 1] [ x n − 1] = cos( ω n + ω) cos( ω n − ω). Applying the

trigonometric identity cos( A + B ) cos( A − B ) = 12 cos(2 A ) + 12 cos(2 B ), this

becomes

[ 1] [ 1] cos(2 ) cos(2 ).

x n + x n − = ω n + ω (1.2)

Applying the trigonometric identity cos(2 A ) = 2 cos (^2 A ) − 1 to the first term of

(1.2), we obtain

[ 1] [ 1] cos (^2 ) 1 1 cos(2 ).

x n + x n − = ω n − + ω (1.3)

Applying the identity cos(2 A ) = 1 − 2sin (^2 A )to the second term of (1.3) gives

us

2 2

x n [ + 1] [ x n − 1] = cos ( ω n ) − sin ( ω). (1.4)

It follows immediately from (1.1) and (1.4) that

2

2

2

[ ] [ ] [ 1] [ 1]

sin ( )

sin (2 ).

y n x n x n x n

f

Combining the this result with (1.5), it follows immediately that

y [ ] n = sin (2^2 π f ) + 2 K [1 − cos(2 π f )]cos(2 π fn ).

So addition of the constant K to the input cosine signal has the effect of adding

a ripple onto the result that was obtained before in Q2.5. This ripple is a cosine

wave of frequency f and amplitude 2 K [1 − cos(2 π f )],as can be seen plainly in

the graph above.

Project 2.3 Linear and Nonlinear Systems

A copy of Program P2_3 is given below:

% Program P2_ % Generate the input sequences clf; n = 0:40; a = 2;b = -3; x1 = cos(2pi0.1n); x2 = cos(2pi0.4n); x = ax1 + bx2; num = [2.2403 2.4908 2.2403]; den = [1 -0.4 0.75]; ic = [0 0]; % Set zero initial conditions y1 = filter(num,den,x1,ic); % Compute the output y1[n] y2 = filter(num,den,x2,ic); % Compute the output y2[n] y = filter(num,den,x,ic); % Compute the output y[n] yt = ay1 + by2; d = y - yt; % Compute the difference output d[n] % Plot the outputs and the difference signal subplot(3,1,1) stem(n,y); ylabel('Amplitude'); title('Output Due to Weighted Input: a \cdot x_{1}[n] + b \cdot x_{2}[n]'); subplot(3,1,2) stem(n,yt); ylabel('Amplitude'); title('Weighted Output: a \cdot y_{1}[n] + b \cdot y_{2}[n]'); subplot(3,1,3) stem(n,d); xlabel('Time index n');ylabel('Amplitude'); title('Difference Signal');

Answers:

Q2.7 The outputs y[n], obtained with weighted input, and yt[n], obtained by combining the two

outputs y1[n] and y2[n] with the same weights, are shown below along with the

difference between the two signals:

Amplitude

Output Due to Weighted Input: a (^) ⋅ x 1 [n] + b (^) ⋅ x 2 [n]

Amplitude

Weighted Output: a (^) ⋅ y 1 [n] + b (^) ⋅ y 2 [n]

x 10

Time index n

Amplitude

Difference Signal

The two sequences are – the same up to numerical roundoff.

The system is – Linear.

Q2.8 Program P2_3 was run for the following three different sets of values of the weighting

constants, a and b, and the following three different sets of input frequencies:

1. a=1; b=-1; f1=0.05; f2=0.4;

2. a=10; b=2; f1=0.10; f2=0.25;

3. a=2; b=10; f1=0.15; f2=0.20;

The plots generated for each of the above three cases are shown below:

0 5 10 15 20 25 30 35 40

0

200

Amplitude

Output Due to Weighted Input: a (^) ⋅ x 1 [n] + b (^) ⋅ x 2 [n]

0 5 10 15 20 25 30 35 40

0

200

Amplitude

Weighted Output: a (^) ⋅ y 1 [n] + b (^) ⋅ y 2 [n]

0 5 10 15 20 25 30 35 40

0

5

x 10-

Time index n

Amplitude

Difference Signal

Based on these plots we can conclude that the system with different weights is – Linear.

Q2.9 Program 2_3 was run with the following non-zero initial conditions – ic = [5 10];

The plots generated are shown below -

0 5 10 15 20 25 30 35 40

0

20

Amplitude

Output Due to Weighted Input: a (^) ⋅ x 1 [n] + b (^) ⋅ x 2 [n]

0 5 10 15 20 25 30 35 40

0

50

Amplitude

Weighted Output: a (^) ⋅ y 1 [n] + b (^) ⋅ y 2 [n]

0 5 10 15 20 25 30 35 40

0

50

Time index n

Amplitude

Difference Signal

Based on these plots we can conclude that the system with nonzero initial conditions is –

Nonlinear.

Q2.10 Program P2_3 was run with nonzero initial conditions and for the following three different sets

of values of the weighting constants, a and b, and the following three different sets of input

frequencies:

1. a=1; b=-1; f1=0.05; f2=0.4;

2. a=10; b=2; f1=0.10; f2=0.25;

3. a=2; b=10; f1=0.15; f2=0.20;

The plots generated for each of the above three cases are shown below:

Amplitude

Output Due to Weighted Input: a (^) ⋅ x 1 [n] + b (^) ⋅ x 2 [n]

Amplitude

Weighted Output: a (^) ⋅ y 1 [n] + b (^) ⋅ y 2 [n]

Time index n

Amplitude

Difference Signal

Based on these plots we can conclude that the system with nonzero initial conditions and

different weights is – Nonlinear.

Q2.11 Program P2_3 was modified to simulate the system:

y[n] = x[n]x[n–1]

The output sequences y1[n], y2[n],and y[n]of the above system generated by

running the modified program are shown below:

y 1 [n]

y 2 [n]

y (^) t[n]

Amplitude

Output Due to Weighted Input: a (^) ⋅ x 1 [n] + b (^) ⋅ x 2 [n]

Amplitude

Weighted Output: a (^) ⋅ y 1 [n] + b (^) ⋅ y 2 [n]

Time index n

Amplitude

Difference Signal

Comparing y[n] with yt[n] we conclude that the two sequences are – Not the Same.

This system is – Nonlinear.