Anda di halaman 1dari 6

Course On DSP Design Using MATLAB

Marcelo Basilio Joaquim, José Carlos Pereira and Vilma Alves de Oliveira
Department of Electrical Engineering
School of Engineering of São Carlos – University of São Paulo
CP: 359, 13560-970 São Carlos SP - Brazil

Abstract - In this paper is reported a graduate Digital Discrete-time signals are represented by a sequence of
Signal Processing laboratory course at the School of numbers where each element represents the signal value at
Engineering of São Carlos - University of São Paulo. The a determined point of time. The Matlab and its Signal
course is based on MATLAB for windows programming Processing Toolbox have incorporated many commands and
language to aid in the teaching of DSP. Through some functions useful to generate basic signals used in DSP as
examples, the students are introduced in a fast and natural well as complex signals composed by the basic ones. At the
way to the DSP concepts and practical applications. beginning of the course is introduced the generation of
waveforms like sine, square wave, unit sample real
Introduction exponential and random signals with uniform and gaussian
distributions.
The main difficulty in DSP course is the large amount of By the use of these signals concepts of linear and
mathematical models and equations. The repetitive circular convolution and sampling are introduced. An
algebraic and the complete understanding of the physical important point as far as discrete time signals is concerned
concepts embedded in the equations require the use of a is the clean understanding of the sampling theorem and its
suitable computational tool. The introduction of MATLAB implications. As an example, a 8 kHz sinusoidal signal
in this course is due to its facility to build up mathematical sampled at 32 kHz is used for this purpose. The sampling
functions and also due to its powerful graphical user frequency is reduced to 8.6 kHz, resulting a 600 Hz
interface in order to display the results. sinusoidal signal, outlining the tendency of high frequencies
Important concepts on DSP are smoothly introduced by to become low as a result of aliasing effect.
examples and graphical output. The following topics: In order to better illustrate the aliasing effect, a damped
Discrete-time signal generation; convolution; sampling sinusoidal signal (second order system response) is used.
theorem and aliasing effects on the signals; discrete linear This signal is sampled at several frequencies (16, 8 and 4
systems and z- transform (impulse and frequency response, Hz) to demonstrate the spectrum superposition as shown in
stability by pole analysis and series convergence, inversion figure 1. This procedure in the course has helped the
of the z transform by partial fraction expansion and residue students to better understand the sampling theorem and
calculus; discrete Fourier transform and spectral analysis meaning of the convolution.
(windowing spectral resolution); FIR and IIR filter design;
linear estimation and introduction to Wiener filters. S ig n a l S p e c trum S a m p ling a t 1 6 H z
1 1
In most examples the emphasis is given to practical
0 .8 0 .8
application of the related theory. The exercises are built in
0 .6 0 .6
such a way that the students can fix the important concepts
on each experiment, and at the end of the course a final 0 .4 0 .4

project is suggested evolving all concepts fixed before. The 0 .2 0 .2

course has been organized in order to allow the students to 0 0


0 10 0 20
design systems rather than just to solve exercises. Under
this point of view the iterative procedure provided by 1
S a m p ling a t 8 H z
1
S a m p ling a t 4 H z

MATLAB together with its high flexibility propitiates an


0 .8 0 .8
ideal environment in which the students design DSP
0 .6 0 .6
systems, verify results and change parameters, if necessary,
to find out the best performance. This procedure inherently 0 .4 0 .4

makes the students to incorporate the design quality in their 0 .2 0 .2

tasks. 0 0
0 20 0 20

Discrete Signals, Convolution And Sampling Figure 1. Aliasing Effect Of The Sampling.
Discrete Systems And Z-Transforms
Cumulative Sum of |h(n)| - (a) Poles & Zeros Diagram - (b)
4
1.5
In this section, an introduction to linear discrete-time 3.5
1
systems (LTI) is presented. Stability, causality, z-transform 3

and its inverse using partial fraction expansion and residue 0.5

Imaginary part
2.5
theorem are studied. 2 0
As we know, a LTI can be described in the time domain by 1.5
-0.5
a linear difference equation with constant coefficients like:
1
-1
0.5
N M

∑a
k =0
k y (n − k ) = ∑ bk x (n − k )
k =0
(1) 0
0 20 40 60 80 100
-1.5
-1.5 -1 -0.5 0
Real part
0.5 1

Or alternatively, in the frequency domain, the system Figure 2. Cumulative Sum And Pole Locations.
can be represented by its system function H(z):
The inverse of the z-transform of a linear system can
−1 −M be obtained by expanding H(z) in partial fractions, i. e.,
b0 + b1z + ⋅ ⋅⋅bM z
H (z ) = (2)
a 0 + a1 z − 1 + ⋅⋅ ⋅a N z − N N
Rk N−M
H ( z) = ∑ −k + ∑ k jz j (4)
k =1 1 − p k z j =0
The impulse response, which is the inverse of the z-
transform is another way to characterize the system.
In the Matlab, this system is easily represented by two where Rk is the residue of pk and kj are the direct
coefficients vectors, b=[ b0 b1 ... bM] and a=[a0 a1 ... aN]. coefficients when N<M. Through this expansion the inverse
The unit sample response can be observed using the of the z-transform can be obtained by inspection. The
unit sample function synthesized before and the filter Matlab function [R P K] = residuez(b,a) is used to perform
function of the Matlab or directly from the impz function. this calculus. A system where b = [1 2 1] and a = [ 1 -1.5
Using sinusoidal signals is possible to verify frequency 0.5] results in R = [8 -9]; P = [1 0.5] and k = [2]. Then,
selective characteristics of a LTI. An important point is the with these values, the unit sample response is:
verification of the system stability. A necessary condition
for the system stability is that all its poles must be inside the h(n) = 8(1) n − 9(0.5) n + 2δ (n) (5)
unit circle of the z-plane. The functions root(a) and
zplane(b,a) are used for this purpose. Another way to verify As can be observed, by its potentiality and friendly use,
the system stability is to observe the convergence of the the software allows to characterize easily the LTI systems.
cumulative sum of h(n) absolute values. The frequency Other examples are shown like: unstable systems, systems
response of the system is determined by the freqz function. with poles with multiplicity higher than one, facilitating the
As an example considers the following system: theoretical DSP teaching.

y (n) + 0.2 y (n − 1) + 0.8 y (n − 2) = 0.3x (n) + DFT And Spectral Analysis


0.6 x (n − 1) + 0.2 x (n − 2)
The Discrete Fourier Transform (DFT) is one of the most
where the poles are: -0.1 ± 0.8888j important tools in DSP. It is used to represent a discrete-
time signal in the frequency domain. The DFT pair defined
In Matlab the following program part can be as:
N −1
implemented to find the poles and their mapping in the z-
plane. The results are shown in figure 2. X (k ) = ∑ x ( n) e
n=0
− jwkn

N −1
(6)
x ( n) = ∑ X ( k ) e
a=[1 0.2 0.8]; jwkn
b=[0.3 0.6 0.2];
k =0
roots(a)
zplane(b,a);
For high N values, the equation (6) is computed fast
cumsum(abs(h)); % Cumulative sum
and efficiently when FFT algorithms are used. Note that the
freqz(b,a,N,fs);
N length truncation of the sequence impose a periodic parameter modification leads to a complete re-design. By
signal with period N, so special care must be taken when other hand the computer aided design allows to overcome
analyzing the results. In order to visualize the effects of the these difficulties as well as to visualize the results. Digital
signal truncation an example is shown in figure 3. First, the filters can be classified in two classes: IIR (Infinite impulse
DFT of a 3 cycles sinusoidal signal is computed (figure response) filter and FIR (Finite impulse response) filter.
3.a), then is calculated the DFT for the same signal with a Normally, IIR filter are chosen due to its sharper frequency
non integer number of cycles (3.3 periods) as shown in response, but, when linear phase characteristic is desired,
figure 3.b. The signal truncation at a non integer number of only FIR filters can be used. The filter designs start from an
periods produces spectral leakage. analog counterpart followed by a transformation to the
digital domain.
3.3 periods of a cossine wave (b) TDF of High Resolution (c)
3 periods of a Cossine wave (a)
0.5
0.45 0.6

0.4
0.45

0.4 0.35
0.5 IIR Filters
0.35 0.3 0.4
0.3

0.25
0.25
0.3
In the section 3, three distinct way to represent a LTI has
0.2
0.2
0.15 0.2
been shown: System function H(z), unit sample response
0.15

0.1
0.1 and linear constant- coefficient difference equation. As far
0.1
0.05 0.05
as the IIR filter design is concerned, these three
0 0 0
0 10 20 30 40 0 10 20 30 40 0 50 100 150 200 250 300
representations lead to three different approaches of design,
i e, impulse variance, bilinear transformation and derivative
Figure 3. DFT Of A Sinusoidal Signal. approximation.
In the impulse invariance approach, the desired
Figure 3.c shows a higher spectral resolution for a continuous impulse response is sampled as:
better visualization of the signal spectrum, that can be
performed by zero-padding in the time domain signal. h(n) = hd (nT ) (7)
TDF Signal two tones (a) Hanning Window (b) High Resolution (c)
0.6 0.18 0.18
where T is the sampling interval. The function system H(z)
0.16 0.16
0.5
0.14 0.14
and, consequently, the filter coefficients are given by [1],
0.4 0.12 0.12 [2], [5]:
0.1 0.1
0.3
0.08 0.08
N
AK
H ( z) = ∑
0.2 0.06 0.06

0.04
sk T −1 (8)
k =1 1 − e
0.04
0.1
0.02 0.02 z
0 0 0
0 10 20 30 40 0 10 20 30 40 0 50 100 150 200 250 300

where sk are the poles in the s-plane and Ak are the


Figure 4. DFT Using Windows coefficients of the partial fraction expansion. In the Matlab
this design can be performed by the use of the impinvar
The necessity to window the signal can be observed function directly.
using a signal composed by two sinusoidal components. In The bilinear transformation is the most used method for
the figure 4.a the signal is masked and it is difficult to IIR filter design. In this case the mapping of s into z is
identify clearly the spectral components of the signal. performed using the following transformation [3], [4]:
Figure 4.b shows the spectrum when the signal is
windowed by a Hanning window, showing both spectral 2 1 − z −1
components. Increasing the spectral resolution (through a s= and H ( z ) = H ( s) s= 2 1− z −1 (9)
zero-padding in the time domain) the components are T 1 + z −1 T 1+ z −1

clearly identified as can see in the figure 4.c.


The relationship between digital frequency and analog
frequency for this transformation is:

Digital Filters w = arctg ΩT 2 ( ) (10)

One of the most important class of LTI is the selective It can be noted that this relationship applies a non
frequency filters. Their design by manual calculation evolve linear compression on digital frequency. In order to
a large number of steps and calculus, and any filter
minimize this effect a pre-warping in s domain is required, Figure 5. Frequency Response Of The Filter
i. e., a non linear expansion is applied for posterior
compression. FIR Filters

( )
2 The acronym FIR stands for finite impulse response filters,
Ω' = arctg ΩT 2 (11) as a consequence, the system function (equation 2) has a0=
T 1 and ai = 0, i = 0, 1, ..., N.
The most important property of these filters is that
As can be observed, the design of these filters evolve
linear phase response can be obtained, which is impossible
some phases which require a great deal of calculus like:
with IIR filters. By other hand, its great disadvantage is the
specification of the filters characteristics, auxiliary analog
large number of coefficients required for a given
filter design and H(s) to H(z) transformation. The functions
characteristic related to IIR filters. Some functions of
buttord and butter of the Matlab can easily to design a filter
Matlab used in the course for this topic are: fir1, fir2 and
with Butterworth characteristics. Furthermore, the
remez.
Chebyshev and Elliptic characteristics are also incorporated
The system filter function is:
in the software. As an example is shown a part of a program
for a Butterworth digital filter design using bilinear N −1
transformation.
disp(' --------------------------------------------');
H ( z) = ∑ h( n) z
n =0
−n
(12)
disp('| Design of a Digital Low-pass Filter |');
disp(' --------------------------------------------'); It can be noticed that the filters coefficients is the unit
% Data of the Analog Filter sample response and the linear phase is implied when h(n)
fap=input('Pass-band frequency: '); = h(M-n) [1]. [2].
Rp=input('Maximun atenuation on pass-band: '); The most used method to design FIR filters is
faa=input('Stop band frequency: '); windowing the data. The design begins by choosing an ideal
Ra=input('Minimun atenuation on stop-band: '); filters characteristic hi(n). The response h(n) of the FIR
fs=input('Sampling frequency: '); filter is obtained by multiplying hi(n) by a finite length
% Seletion of the filter order window w(n), i. e.,
[N,wn] = buttord(2*fap/fs,2*faa/fs,Rp,Ra)
% Filter Coefficients h(n) = hi (n) w(n) (13)
[bd,ad] = butter(N,wn)
pause;
% Frequency Response Figure 6. shows the frequency response for a low-pass
freqz(bd,ad,128,fs); title('Filtro Digital - Bilinear'); filter by using rectangular and Hamming windows. It can be
Example: Using fap=1.5 kHz, Rp=1 dB, faa=4kHz, observed from this figure the ripple in the passband when a
Ra=40 dB and fs= 10kHz, results in the following filter rectangular window is used. This effect comes from the
coefficients: high magnitude of the sides lobes in the spectrum of this
bd = [0.0834 0.2501 0.2501 0.0834] window. If a Hamming is used the filter response is
ad = [1.0000 -0.7355 0.4773 -0.0748] smoother but presents a larger transition band.

FIR Filter - Retangular and Hamming window


Magnitude Response (dB

Filtro Digital - Bilinear 1.2


0

-50 1

-100
0.8
-150
0 1000 2000 3000 4000 5000
Frequency (Hertz) 0.6
0
Phase (degrees)

0.4
-100

0.2
-200

-300 0
0 1000 2000 3000 4000 5000 0 0.1 0.2 0.3 0.4 0.5
Frequency (Hertz)
Figure 6. FIR Filters comparison between the signal periodogram (DFT) and the
Also, other techniques are exemplified to the students results obtained.
like frequency sampling method and design using the
Parks-McClellan algorithm. 30
P o w e r D e n s i ty S p e c trum a n d P e r i o d o g r a m

Linear Prediction And Wiener Filter 20

10
At this phase of the course some related topics of linear
estimation and adaptive filters are presented. Particularly 0
are studied the parametric estimation of the power spectral
density for a stochastic signal (autoregressive model - AR) -10

and an adaptive filtering of a embedded noise signal


(Wiener filter). -20

-30
Linear Prediction 0 10 20 30 40

Linear prediction is a parametric modeling technique used


to describe a signal through time series. This technique is Figure 7. DFT And Parametric Spectrum
very efficient used in signal compression, voice analysis and
synthesis and power spectrum estimation. Wiener Filter
Supposing x(n) to be a M-order autoregressive process,
the linear prediction consists to estimate a non observed The Wiener filter is an adaptive digital non recursive FIR
sample x(n) based on the past M observed samples {x(n-1), filter designed to produce an optimal output in mean square
..., x(n-M)}. The linear estimate of x(n), denoted by sense. One of the filtering methods that are implemented in
the course is shown bellow.
x$ (n) can be written as:
Consider a stochastic signal x(n) composed by two
components: a pure signal f(n) and an additive white noise
x$ (n) = − a1 x (n − 1) − ⋅ ⋅⋅ − a M x (n − M ) (14) v(n). Suppose also, that these signals are stationary in the
wide sense.
where a(k) are constant coefficients and M is the order of
the predictor. x ( n) = f (n) + v ( n) (17)
The coefficients a(k) are calculated based on the least
square criterion, i. e., minimizing the mean square error The problem to be solved is to obtain the best estimate
e(n) = x(n) - x$ (n) . After some mathematical of f(n) when only x(n) and the joint statistics of x(n) and
manipulation, the coefficients a(k) can be obtained from the v(n) are known. A way to find out the filter coefficients is
following expression, to use an adaptive algorithm [6] shown as follows:

M (1) Set an initial value for the filter coefficients


∑ a ( j) R x ( k − j) = − Rx ( j), k = 1,2,⋅ ⋅⋅ M (15)
j =1 [h] = 0 (18)

where Rx(k) is the autocorrelation function of x(n) and the (2) Compute the gradient vector [D(n)] which is the error
signal spectrum is given by: derivative "minimum mean square (MMS)" related to the
filter coefficients.
1
X ( z) = E ( z) (16)
A( z ) de(n)
[ D(n)] = = −2 E {e(n) x (n − k )] (19)
dh( k , n)
In order to solve the system equations (15) the
Levinson-Durbin and Cholesky algorithms are presented (3) Update the coefficients in a reversed order of the
and implemented. As an illustration of this model is gradient vector.
determined, in the Matlab, the coefficients of the predictor
filter and the power spectral density of an AR signal [h(n + 1) = [h(n)] − u[ D(n)] (20)
synthesized in the Matlab. In the figure 7. there is a
where u is a constant which determine the correction step. solve related problems and beyond this, with the use of this
program it was noted a higher progress and interest of the
(4) Compute the new error vector and repeat the process students in theoretical aspects of DSP and its practical
until to reach the optimum h(n). applications.
A good approximation of this algorithm is to replace
the error in the step 2 by an instantaneous error called "least References
mean square (LMS)", [6] defined by:
1) Oppenheim, A. V. & Schafer, R. W., “Discrete-time
d (n) = −2e(n)[ x (n)] (21) Signal Processing”, Prentice Hall, 1989.
2) Proakis, J. G. & Manolakis, D. G., “Digital Signal
In this approach, the coefficients are updated for any Processing: Principles, algorithms and applications”,
time as: Macmillan Publishing Co., 1992.
3) The Mathworks Inc., “Matlab Reference Guide”, 1992.
e(n) = f (n) − [ x (n)]'[h(n)] 4) The Mathworks Inc., “Signal Processing Toolbox
(22) User’s Guide”, 1992.
[h(n + 1)] = [h(n)] + ue(n)[ x (n)] 5) Joaquim, M. B. & Pereira, J. C. “Laboratório de
Processamento de Sinais”, Classroom Notes, 1996.
The variable n is increased until a stable solution to be 6) Ifeachor, E. C. & Jervis, B. W., “Digital Signal
reached. Although this algorithm presents only an Processing: A Practical Approach”, Addison-Wesley,
approximated solution of the optimum Wiener filter, it is 1993.
simpler and can be realized in real time. This algorithm is
implemented at the end of the course as an example of
optimum filtering. A signal noised embedded with white
noise is applied to the filter to observe the Wiener filter
performance and the results are shown in figure 8.

Signal free of noise


1

-1
0 200 400 600 800 1000
Signal plus noise
1

-1
0 200 400 600 800 1000
Signal filtered
1

-1
0 200 400 600 800 1000

Figure 8. Wiener Filter Example

Conclusion

The introduction of DSP students to high level


programming language is important in modern engineering
curricula. As far as the students interested is concerned , the
use of Matlab package in the experiments has been useful to
assimilate the DSP concepts, to provide better capability to

Anda mungkin juga menyukai