Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
57 views

DSP Lab Project #2

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views

DSP Lab Project #2

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

ECE 537 Digital Signal Processing

MATLAB-Based Laboratory Projects – Prof. Azubogu


Laboratory Project 2: Discrete-time Systems Representation and Simulation
1.0 Background Review
 Let 𝑥 𝑛 and 𝑦 𝑛 be the input and output discrete-time signals respectively, of a
system. Then the system is viewed as a transformation (or mapping) of input signals,
𝑥 𝑛 to a set of output or response signals 𝑦 𝑛 .
 This transformation is represented by the mathematical notation:
𝑦= ℱ 𝑥 𝑛 (1)
Where ℱ . is the operator representing some well-defined rule by which 𝑥 𝑛 is
transformed into 𝑦 𝑛 . Signal processing involves many tasks, such as signal analysis,
coding, error correction, signal compression, quantization, and transmission.
 Digital signal processing can be considered simply to be the analysis and manipulation of
digital signals by a digital processor.
 Digital signal processors are designed to efficiently handle DSP algorithms such as
Finite/Infinite Impulse Response filters (FIR/IIR) and Fast Fourier Transform (FFT).
Common applications include audio and video encoding and decoding, motor control,
and speech recognition. DSP instructions include multiply, add, and multiply-accumulate
(MAC). MAC is a distinguishing feature separating DSP instruction sets from regular
instruction sets. It is very commonly used in DSP algorithms and doubles the
performance relative to separate multiply and add instructions.
 DSP algorithms may be run on general-purpose computers and digital signal processors.
DSP algorithms are also implemented on purpose-built hardware such as application-
specific integrated circuit (ASICs). Additional technologies for digital signal processing
include more powerful general purpose microprocessors, graphics processing units, field-
programmable gate arrays (FPGAs), digital signal controllers (mostly for industrial
applications such as motor control)
 Project 1.1: Signal Smoothing by Averaging
A common example of a digital signal processing application is the removal of the noise
component from a signal corrupted by additive noise.
Let s[n] be the signal corrupted by a random noise d[n] resulting in the noisy signal:
x[n] = s[n] + d[n]. (2)

The objective is to operate on x[n] to generate a signal y[n] which is a reasonable


approximation to s[n]. To this end, a simple approach is to generate an output sample by
averaging a number of input samples around the sample at instant n.
Project 1.1 – Moving Average Filters
A three-point moving average algorithm described by the following input/output
equation:
y[n] = 1/3 (x[n − 1] + x[n] + x[n + 1]). (3)

Program P1_1 implements the above algorithm:


% Program P1_1
% Signal Smoothing by Averaging
clf;
R = 51;
d = 0.8*(rand(R,1) - 0.5); % Generate random noise
m = 0:R-1;
s = 2*m.*(0.9.^m); % Generate uncorrupted signal
x = s + d'; % Generate noise corrupted signal
subplot(2,1,1);
plot(m,d, 'r-', m,s, 'g--', m,x, 'b-.');
xlabel('Time index n');ylabel('Amplitude');
legend('d[n] ','s[n] ','x[n] ');
x1 = [0 0 x];x2 = [0 x 0];x3 = [x 0 0];
y = (x1 + x2 + x3)/3;
subplot(2,1,2);
plot(m,y(2:R+1),'r-', m,s, 'g--');
legend( 'y[n] ','s[n] ');
xlabel('Time index n');ylabel('Amplitude');

Q1. Run Program P1_1 and generate all pertinent signals.


Q2. What is the form of the uncorrupted signal s[n]? What is the form of the
additive noise d[n]?
Q3. Can you use the statement x = s + d to generate the noise-corrupted signal? If
not, why not?
Q4. What are the relations between the signals x1, x2, and x3, and the signal x?

 Simulation of Discrete-Time Systems


A discrete-time system processes a digital input signal linearly to produce a digital output
signal as illustrated in Fig. 2.1

xn DSP yn 


A linear time-invariant (LTI) discrete-time system that satisfies both the linearity and the
time-invariance properties can be described (modeled) using any of the following:
 
Convolution summation: hn  xn   xk hn  k    hk xn  k  (4)
k   

N M
Difference equation:  ak yn  k    bk xn  k ; a0  0 (5)
k 0 k 0
M

Y z 
 bk z k
H z    k 0
Transfer function H(z): X z  N (6)
1   a k z k
k 1

Table P2-1: MATLAB DSP Tool box Commands for DT Systems Analysis
Commands/ Numerical Results and Description
Operations
conv Convolution and polynomial multiplication.

filter(B,A,X) filters the data in vector X with the


filter described by vectors A and B

roots Roots of a polynomial.

impz Inverse of a rational z-transform

residue Partial fraction expansion.

freqz Frequency response of discrete system.

residuez Partial-fraction expansion

Project 2.1: Simulation of Discrete-Time Systems – Difference Equation

Notes

 For the simulation of causal LTI discrete-time systems described by difference equation,
the command filter can be used. There are several versions of this command. If the
numerator and denominator coefficients are denoted as follows:
num = [ p0 p1 ... pM]; num ⇒ numerator coefficient vector
den = [ d0 d1 ... dN]; den ⇒ denominator coefficient vector
 Then y = filter (num, den,x) generates an output vector y of the same length as the
specified input vector x with zero initial conditions, that is, y[-1] y[-2] = ... = y[-N] = 0.
 The output can also be computed using y = filter(num, den, x, ic)
Where ic = [y[-1], y[-2], ..., y[-N]] is the vector of initial conditions.
 Access to final conditions can be obtained using [y, fc] = filter (num, den,x, ic).

Project 2.1 – A discrete system is modeled by the difference equation:


yn  0.2 yn  1  0.5 yn  2  xn  xn  1

a. Use the MATLAB filter command to find the output signal for an input signal:

x0  1, x1  3, xn  0,  k  2


b. Consider the following discrete-time systems characterized by the difference equations:
System No. 1: yn  0.5 xn1  0.27 xn  1  0.77 xn  2

System No. 2: yn  0.53 yn  1  0.46 yn  2  0.45xn  0.5 xn  1  0.45xn  2

a. Compute the responses of the above two systems for a sinusoidal input:
 2n   200n 
xn  cos   cos ,  0  n  299
 256   256 

b. In this project both filters are lowpass filters but with different attenuation in the
stopband, especially at the frequencies of the input signal. Which filter has better
characteristics for suppression of the high-frequency component of the input signal x[n]?

Project 2.2: Simulation of Discrete-Time Systems – Convolution


Notes
 The convolution summation characterizes LTI discrete-time system in terms of the
impulse response h[n].
 Based on the duration of the impulse response h[n], LTI systems can be sub-divided into:
(i) Finite-impulse response (FIR):
M 1
yn  hn* xn   hk xn;  k  (7)
k 0

hn  0, n  0 & n  M
yn  is output sequence
xn is input sequence
hk  is system impulse response
(ii) Infinite-impulse response (IIR)

yn  hn  xn   hk xn  k  (8)
k 0

 The convolution operation is implemented in MATLAB by the command conv, provided


the two sequences to be convolved are of finite length.
 There are several applications of convolution. In digital image processing, convolutional
filtering is used in edge detection and other processes. In audio applications, convolution
summation can be used to make the digital audio signal sound more realistic.

Project 2.2 – A discrete-time system is modeled by the input/output equation:

yn  0.25xn  0.5 xn  1  0.3xn  2


Using the conv command compute the output response for an input sequence:

1 0  1 2

Project 2.3: Simulation of LTI Discrete-Time Systems – Transfer Function


Notes
 The transfer function of a linear system describes how the system transfers an input
signal, xn , into an output signal, yn  , assuming the system is initially at rest.
 For discrete-time systems, the transfer function is derived by taking the Z-Transform of
the input/output difference equation and putting the result in the form:
M

Y z 
 bk z k
H z    k 0
X z  N
1   a k z k (9)
k 1

― Roots of the denominator of the transfer function – system poles.


― Roots of the numerator of the transfer function – system zeros
 The transfer function can be derived easily from the input/output difference equation
without all the intervening algebra.
 The transfer function is useful for determining stability of a LTI discrete-time system, the
output response, and frequency response.
 The transfer function is important for designing and analyzing digital filters and for
applications involving Fast-Fourier transforms and convolution or correlation operations.
Ex. #1
Find the transfer functions for the following discrete systems:
a) y[n] + 0.2y[n–1] + 0.5y[n–2] = x[n] – x[n – 1]
b) y[n] = 0.25x[n] + 0.5x[n – 1] + 0.3x[n – 2]
Project 2.3:
1. A discrete-time system is modeled by the difference equation:
y[n] + 0.2y[n–1] + 0.5y(n–2) = x(n) – x(n – 1)
a) Determine the transfer function and use MATLAB function filter to find the
output signal for an input signal x(0) = 1, x(1) = 3, x(n) = 0 for n > 2.
b) Using MATLAB impz function, determine the impulse response for the discrete
system: y[n] = 0.1y(n – 1) + x(n) – 0.5x(n – 1)

Stability of Discrete-Time Systems


Note:
• A discrete-time system is stable if for any bounded input signal, the output signal
remains bounded for any set of initial conditions.
• A discrete-time system is stable if and only if the impulse response goes to zero as
time goes to infinity.
• From the transfer function, a LTI discrete-time system is stable if and only if all
of the system poles have magnitude strictly less than 1; i.e. all the system poles lie
within the unit circle.
• MATLAB functions roots and abs can be used to determine the poles of DT
system for denominators that are difficult to factor by inspection and the stability
of the system.
2. Determine which of the following discrete-time systems are stable.
(a) y(n) + 0.2y(n–1) + 0.5y(n–2) = x(n) – x(n – 1)
(b) y(n) = 0.1y(n – 1) + x(n) – 0.5x(n – 1)

Project 2.4: Simulation of LTI Discrete-Time Systems in the Frequency Domain

Notes

 A linear, time-invariant (LTI) discrete-time system is completely characterized in the


time domain by its impulse response sequence hn , and the output sequence yn  of the
LTI system can be computed for any input sequence xn by convolving the input
sequence with its impulse response sequence.
 Certain classes of LTI discrete-time systems are characterized also by a linear, constant-
coefficient difference equation. For such systems, the output sequence can be computed
recursively for any input sequence.
 By applying the DTFT or the Z-transform to either the convolution sum description or to
the difference equation representation, the LTI discrete-time system can also be
characterized in the frequency domain.
 Frequency domain representations provide additional insight into the behavior of LTI
discrete-time systems, in addition to making it simpler to design and implement them for
specific applications.
 If hn denotes the impulse response sequence of an LTI DT system, its Frequency
response H   is given by the DTFT of hn , that is:

H     hne jn  H   e j  
n   (10)
where H   is the magnitude response
and    is the phase response

 Design specifications for DT systems in many applications are given in terms of


magnitude or phase response or both. In some cases, the magnitude function is specified :
in dB H    20Log10 H   , dB

 Thus for complex exponential input sequence, the output of an LTI DT system is also a
complex exponential signal of the same frequency multiplied by a complex constant,
H  
that is:
yn  H  e jwn
(11)
 In the most general case if the input to an LTI DT system consists of an arbitrary linear
combination of sinusoids of the form
N
xn   Ai cosi n   i , -   n   (12)
i 1
Then the response of the system is simply:
N
yn   Ai H i  cosi n  i   i , (13)
i 1

 Equation (13) gives the steady-state response of the LTI DT system


 The Frequency response function H(ω) is very useful in the characterization of LTI
systems; it defines how complex sinusoidal sequence is changed in amplitude when it is
filtered by the system.
 The nature of this filtering action is determined by the Frequency response
characteristics, which in turn depends on the choice of the coefficient parameters {ak}
and {bk} in the difference equation or transfer function representation of the system. Thus
by proper selection of these coefficients, one can design frequency selective filters that
pass signal components in some bands while attenuating signals containing frequency
components in other bands.
 Thus H(ω) acts as a weighting function or spectral shaping function to different
frequency components of the input signal to an LTI DT system. Viewed in this context,
any LTI system can be considered to be a frequency-shaping filter.
 Filtering operation is performed a lot in digital signal processing, such as removal of
undesirable noise from desired signals, spectral shaping such as equalization of
communication channels, signal detection in Radar and communication systems.
Exercises
1. Consider a real coefficient LTI DT system characterized by the following magnitude
response:
1,   c
H    
0, c    
Suppose the input signal is:
xn  A cos1n  B cos2 n, 0  1  c  2  
Determine and comment on the steady-state response of the system.
2. An FIR filter of length 3 is defined by the impulse response:
ℎ 0 = ℎ 2 = 𝑎1 , ℎ 1 = 𝑎2
Let the input to this filter be a sum of two cosine sequences of angular frequencies:
0.1 rad/sample and 0.4 rad/sample. Determine the impulse response coefficients 𝑎1
and 𝑎2 so that the filter passes only the high frequency component of the input signal.
 The MATLAB command freqz (h, w) can be used to determine the values of the
frequency response of a prescribed impulse response vector h at a set of given
frequencies w. From these frequency response values the real and imaginary parts can be
computed using the MATLAB functions: real and imag; and the magnitude and phase
computed using the MATLAB functions: abs and angle.
 The MATLAB function freqz is also used in the following variations:
[h, w] = freqz (num, den, w)
[h, w] = freqz (num, den, f, Fs)
[h, w] = freqz (num, den, k, Fs)
The vectors num and den are the row vectors of the numerator and denominator
coefficients {ak} and {bk}.
Project 2.4
1. Consider an FIR filter with the finite number of coefficients:
1.0 0.8 0.6 0.4 0.6 0.8 1.0
Write the MATLAB script to compute the frequency response and plot the magnitude
and phase spectra for the whole range of frequency: 0 to 𝜋
2. A causal LTI IIR digital filter is described by the following constant coefficient
difference equation: 𝑦 𝑛 = 0.9 𝑦 𝑛 − 1 + 0.3𝑥 𝑛 + 0.24𝑥 𝑛 − 1

i. Draw a block diagram realization of the system.


ii. Obtain the impulse response of the system by replacing x[n] with δ[n] in the
above equation. (Use causality to set up the initial conditions.)
iii. Use the answer in (ii) to obtain the Frequency response of the system.
iv. Find the Frequency response of the system using another method. Specifically,
take the DTFT of the left-hand-side and right-hand-side of the difference
equation, and then use linearity and the time-shifting property of the DTFT along
with the fact that H(ω) = Y (ω) X(ω).
v. Use MATLAB to compute and plot the magnitude and phase responses, |H(ω)|
and    , for −π < ω < π. You may use MATLAB functions phase and abs

You might also like