Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

Section 1.

4 Examples of Systems

0.8
0.6
y(t)
0.4
0.2
0
0 5 10 15
Time

FIGURE 1.26
Response of the mass–spring–damper system to a unit-step input
with M = 1, K = 2, and D = 0.5.

values for M, D, and K, the response y(t) to a step input, x1t2 = u1t2, is a decaying
oscillation that settles to a constant (or steady-state) value, as seen in Figure 1.26.
The oscillation is due to the transfer of energy between kinetic energy (proportional to
the velocity squared of the mass) and the potential energy (energy stored in the spring
as it compresses or stretches). The decay of the oscillation is due to the dissipation of
energy that occurs in the damper.
Mass–
Spring– A detailed discussion of vibrations is not the objective of this example or the online
Damper demo. However, the mass–spring–damper is a system whose response can be visualized
System
readily via animation.A series RLC circuit is governed by the same general equation and
responds in the same manner as this system, but the response cannot be visualized
easily via animation. Therefore, the mass–spring–damper system and the accompany-
ing online demo will be used throughout this text to demonstrate basic system
input/output concepts.

1.4.3 Moving Average Filter


Given a positive integer N, the N-point moving average (MA) filter is a discrete-time
system given by the input/output relationship

1
y[n] = [x[n] + x[n - 1] + x[n - 2] + Á + x[n - N + 1]] (1.11)
N

where x[n] is the input applied to the filter and y[n] is the resulting output response.
For example, if N = 3, the 3-point MA filter is given by the input/output relationship

1
y[n] = [x[n] + x[n - 1] + x[n - 2]]
3

From (1.11), it is seen that the output y[n] at time n of the N-point MA filter is the
average of the N input values x[n], x[n - 1], x[n - 2], Á , x[n - N + 1]. Hence, the
term “N-point” refers to the number of input values used in the computation of the filter’s
output. The filter is referred to as a “moving average filter,” since we compute the
next value y[n + 1] of the output by moving the range of time points over which the

27

www.EngineeringEBooksPdf.com
Chapter 1 Fundamental Concepts

filter output is computed. In particular, y[n + 1] is the average of x[n + 1], x[n],
x[n - 1], Á , x[n - N + 2], so that

1
y[n + 1] = [x[n + 1] + x[n] + x[n - 1] + Á + x[n - N + 2]] (1.12)
N

Note that (1.12) follows from (1.11) by the setting of n = n + 1 in (1.11). Some au-
thors refer to the MA filter as the running average filter.
MA filters are often used to reduce the magnitude of the noise that may be pre-
sent in a signal. To see how this is possible, suppose that the input x[n] is given in the
form x[n] = s[n] + e[n], where s[n] is the smooth part of x[n] and e[n] is the erratic or
noisy part of x[n]. Then the output y[n] of the N-point MA filter is given by

1
y[n] = [s[n] + s[n - 1] + Á + s[n - N + 1]]
N
1
+ [e[n] + e[n - 1] + Á + e[n - N + 1]] (1.13)
N

The noisy part of the MA filter output y[n] given by (1.13) is the average of the noise
values e[n], e[n - 1], Á , e[n - N + 1], which is equal to

1
[e[n] + e[n - 1] + Á + e[n - N + 1]] (1.14)
N

If e[n] varies randomly about zero, the noisy term given by the average (1.14) can be
made as small as desired (in theory) by taking the value of N to be sufficiently large.
This explains why MA filters can work well in reducing the magnitude of the erratic or
noisy part of a signal.
If the value of N is sufficiently large, the output of the MA filter is approximately
equal to a time delay of the smooth part s[n] of x[n] with the amount of the delay equal
to 1N - 12/2 time units. The occurrence of the time delay will be verified mathemati-
cally in Chapter 5 with the discrete Fourier transform. An illustration of the N-point
MA filter and the time delay that can occur is given in the next example, where the fil-
ter is applied to price data for the stock fund QQQQ. First, it should be pointed out
that the output y[n] of the filter given by (1.11) is easily computed by the MATLAB
command sum. In particular, if the input signal x[n] is written as the column vector

x[n - N + 1]
x[n - N + 2]
x = D T
o
x[n]

then the output y[n] at time n is equal to the MATLAB command (1/N)*sum(x).

28

www.EngineeringEBooksPdf.com
Section 1.4 Examples of Systems

Example 1.4 Application to Stock Price Data


The closing price of QQQQ for the 50-business-day period from March 1, 2004, up to and in-
cluding May 10, 2004, will be considered. To acquire the data, follow the procedure described
in Section 1.2, and then save the data in the file QQQQdata2.csv. Setting N = 11 days, the 11-
day MA filter can then be applied to the closing prices of QQQQ by the MATLAB commands
c=csvread('QQQQdata2.csv',1,4,[1 4 50 4]);
for i=11:50;
y(i)=(1/11)*sum(c(i-10:i));
end;
n=11:50;
plot(n,c(n),n,c(n),'o',n,y(n),n,y(n),'*')
grid
xlabel('Day(n)')
ylabel('c[n] and y[n]')

Note that in this case the input x[n] to the filter is the closing price c[n] of QQQQ. Also
note that the first value of the filter output y[n] is the output y[11] at day 11, since the 11-day MA
filter requires the input values c[1], c[2], c[3], Á , c[11] in order to compute y[11]. The resulting
MATLAB plot for the filter input c[n] and the filter output y[n] is given in Figure 1.27. In the
plot, the values of c[n] are plotted with o’s, and the values of y[n] are plotted with *’s. Note that
even though the closing prices are quite erratic, the filter does a good job of smoothing out the
data. However, it’s clear from the plot that the filter delays the input signal by several days. As
noted previously, the delay is approximately equal to 1N - 12/2, which is equal to five days in
this example. If y[n] is shifted to the left by five days (which corresponds to the left-shifted signal

37.5

37

36.5
c[n] and y[n]

36

35.5

35

34.5

34
10 15 20 25 30 35 40 45 50
Day (n)

FIGURE 1.27
MATLAB plot of filter input and output.

29

www.EngineeringEBooksPdf.com
Chapter 1 Fundamental Concepts

37.5

37

36.5

c[n] and y[n5]


36

35.5

35

34.5

34
5 10 15 20 25 30 35 40 45
Day (n)

FIGURE 1.28
MATLAB plot of filter input and left-shifted output.

y[n + 5]) and then plotted with c[n], the result is as shown in Figure 1.28. Note that the left-shifted
output y[n + 5] fits the input data very nicely. Unfortunately, the shifted output cannot be
generated in real time, since its computation requires future values of c[n]. To see this, let
r[n] = y[n + 5]. Then, replacing n by n + 5 and setting N = 11 in (1.11) give

1
r[n] = [c[n + 5] + c[n + 4] + c[n + 3] + c[n + 2] + c[n + 1]
11
+ c[n] + c[n - 1] + Á + c[n - 5]] (1.15)

Hence, the computation of r[n] at time n requires the future values c[n + 5], c[n + 4],
c[n + 3], c[n + 2], and c[n + 1] of the input c[n].

Application to trading QQQQ. Individuals who trade stocks sometimes use MA fil-
ters to determine when to buy and when to sell a particular stock (such as QQQQ).
In the application to trading, MA filters are often referred to as SMA filters, where
SMA stands for “simple moving average.” An even more common type of filter used
in trading is the EWMA filter, also called the EMA filter, where EWMA stands for
“exponentially-weighted moving average.” The N-point EWMA filter is defined in
Section 2.1; in Section 7.5, a “recursive version” of the EWMA filter is defined. In
Section 7.5, an approach to buying and selling QQQQ is given in terms of the differ-
ence in the responses to two EWMA filters having different parameter values. For
details on the use of moving average filters in trading, type “moving average crossover”
into a search engine.

30

www.EngineeringEBooksPdf.com
Chapter 1 Fundamental Concepts

Except for the brief introduction to nonlinear systems given previously, this book
deals only with linear systems. A general class of linear systems is defined in the next
chapter.

1.5.3 Time Invariance


Given a real number t1 and a signal x(t), recall that x1t - t12 is equal to x(t) shifted to
the right by t1 seconds if t1 7 0, and that x1t - t12 is equal to x(t) shifted to the left by
t1 seconds if t1 6 0. Now consider a system with input x(t) and output y(t). The system
is said to be time invariant or constant if for any input x(t) and any t1, the response to
the shifted input x1t - t12 is equal to y1t - t12, where y(t) is the response to x(t).
Therefore, in a time-invariant system the response to a left or right shift of the input
x(t) is equal to a corresponding shift in the response y(t) to x(t). In a time-invariant sys-
tem, there are no changes in the system structure as a function of time t. A system is
time varying or time variant if it is not time invariant.

Example 1.13 Amplifier with Time-Varying Gain


Suppose that y1t2 = tx1t2. It is easy to see that this system is memoryless and linear. Now for
any t1,

y1t - t12 = 1t - t12x1t - t12

But the response to input x1t - t12 is tx1t - t12, which does not equal 1t - t12x1t - t12, in
general. Hence y1t - t12 is not equal to the t1-second shift of the response to x(t), and thus the
system is time varying. Note that this system can be viewed as an ideal amplifier with time-varying
gain t.

Example 1.14 MA Filter


Again consider the N-point MA filter with the input/output relationship (1.16). Given a positive or
negative integer q, consider the shifted version x[n - q] of the input x[n] to the filter. Then, re-
placing x[n] by x[n - q] in (1.16) reveals that the filter response r[n] to x[n - q] is given by

1
r[n] = [x[n - q] + x[n - q - 1] + x[n - q - 2] + Á + x[n - q + N - 1]] (1.20)
N

In addition, if n is replaced by n - q in (1.16), the resulting expression for y[n - q] is equal


to the right-hand side of (1.20), and thus, y[n - q] = r[n]. Hence, the MA filter is time invariant.

In addition to the MA filter, the RC circuit and the mass–spring–damper system


defined in Section 1.4 are also time invariant, since the input/output differential equa-
tion for each of these systems is a constant-coefficient differential equation.
In this book the focus is on systems that are both linear and time invariant. The
study of a general class of such systems begins in the next chapter with time-domain
representations.

36

www.EngineeringEBooksPdf.com
Problems

1.6 CHAPTER SUMMARY


This chapter introduces the concepts of signals and systems. Both signals and systems
are broken into the categories of continuous time and discrete time. Continuous-time
signals are signals x(t) in which time t assumes values from the set of real numbers,
while discrete-time signals x[n] are defined only at integer values of the index n.
Continuous-time signals arise naturally, with common examples being voltages and
currents in circuits, velocities and positions of moving objects, flow rates and pressures
in chemical processes, and speech and ECGs in humans. Discrete-time signals are often
obtained by sampling a continuous-time signal, that is, defining the signal only at dis-
crete points in time t = nT, where T is the sampling time. Discrete-time signals also
arise “naturally,” as shown in the example given in this chapter involving the closing
price of a particular stock at the end of each trading day.
There are several common signals defined in this chapter that will be used
throughout the text. The names are the same for the continuous-time and discrete-
time versions of these signals: step function, ramp function, and sinusoidal function.
In addition, there is the unit-impulse function for continuous-time signals and the
unit-pulse function for discrete-time signals. Impulse and pulse functions are very
important for analyzing engineering systems. It will be shown in Chapter 2 that the
response of the system to the unit impulse or unit pulse is a means of characterizing
the system. The discrete-time step function, ramp function, and sinusoidal function
can be viewed as sampled versions of their continuous-time versions, but a scaled
version of the sampled ramp function is more often used, r[n] = nu[n]. It is interesting
to note that a continuous-time sinusoid cos1vt + u2 is periodic, but a discrete-time si-
nusoid cos1Vn + u2 is periodic if and only if there exists a positive integer r such that
V = 2pq/r for some integer q.
A system is a collection of one or more devices or processes that operates on an
input signal to produce an output signal. Examples of systems include electrical cir-
cuits, communication systems, signal processors, biological systems, robotic manipula-
tors, chemical processes, and manufacturing systems. There are several representations
of systems; some of them are considered as time domain, and others are considered as
frequency domain models. Time domain representations include the convolution model
and the input/output differential, or difference equation, to be studied in Chapter 2. The
frequency domain models include the Fourier transform, to be studied in Chapters 3–5,
and the transform models to be studied in Chapters 6–8.
There are several important properties of continuous-time and discrete-time sys-
tems, including linearity, time invariance, causality, and memory. Several powerful
analysis methods exist, such as the Fourier transform and transfer function approaches,
that can be used to study the behavior of systems which have these properties. The
remaining chapters in the text focus on these analysis methods.

PROBLEMS
1.1. Consider the continuous-time signals displayed in Figure P1.1.
(i) Show that each of these signals is equal to a sum of rectangular pulses pt1t2 and/or
triangular pulses 11 - 2 ƒ t ƒ /t2pt1t2.
(ii) Use MATLAB to plot the signals in Figure P1.1.

37

www.EngineeringEBooksPdf.com
Section 2.1 Input/Output Representation of Discrete-Time Systems

It turns out that we can generalize (2.2) to be a large class of causal linear time-
invariant discrete-time systems by taking the input/output representation to be
N-1
y[n] = a wix[n - i] (2.3)
i=0

where the wi (that is, w0 , w1 , w2 , Á , wN - 1) are real numbers, and are called the
weights of the linear combination given by (2.3). Note that if all the weights are equal
to 1/N, that is, wi = 1>N for i = 0, 1, 2, Á , N - 1, then (2.3) reduces to (2.2). Hence,
the N-point MA filter is an example of a system whose input/output representation can
be written in the form (2.3).

2.1.1 Exponentially Weighted Moving Average Filter


Another example of a system that can be expressed in the form (2.3) is the N-point
exponentially weighted moving average filter defined by
N-1
y[n] = a a1bix[n - i]2 (2.4)
i=0

where b is a real number with 0 6 b 6 1 and a is a positive constant given by


1 - b
a = (2.5)
1 - bN
Note that if b = 0, then a = 1, and (2.4) reduces to y[n] = x[n], in which case there is
no filtering of the input signal.
From (2.4) it is seen that the weights of the N-point exponentially weighted moving
average (EWMA) filter are given by
wi = abi, i = 0, 1, 2, Á , N - 1 (2.6)

Here the term “exponentially weighted” refers to the exponent of b in the weights given
by (2.6). Since 0 6 b 6 1, the weights given by (2.6) decrease in value as i increases in
value. For example, if N = 3 and b = 0.5, then from (2.5) it follows that

1 - 0.5 0.5
a = 3
= = 0.571
1 - 0.5 0.875

and using (2.6) gives w0 = a = 0.571, w1 = ab = 0.286, and w2 = ab2 = 0.143. Hence,
the 3-point EWMA filter with b = 0.5 is given by the input/output relationship

y[n] = 0.571x[n] + 0.286x[n - 1] + 0.143x[n - 2] (2.7)

From (2.7) it is seen that in the computation of the filter output y[n], a larger “weight”
is given to the more recent values of the input x[n], whereas in the 3-point MA filter,
the same weight is given to all the input values; that is, in the 3-point MA filter the
output is

y[n] = 0.333x[n] + 0.333x[n - 1] + 0.333x[n - 2]

46

www.EngineeringEBooksPdf.com
Chapter 2 Time-Domain Models of Systems

Due to the exponential weighting, the N-point EWMA filter given by (2.4) has
a quicker response to time variations in the filter input x[n] in comparison with
the N-point MA filter. In other words, for a fixed value of N, the time delay through
the EWMA filter is less than that of the MA filter; however, in general, the MA filter
does a better job of removing noise than the EWMA filter does. For a given value of
N, the time delay through the EWMA filter depends on the choice of b: the smaller
b is, the smaller the time delay will be. In particular, if b = 0, then as previously
noted, the input/output relationship is y[n] = x[n], and thus there is no delay through
the system in this case. In the following example, the EWMA is applied to filtering of
price data for the index fund QQQQ.

Example 2.1 EWMA Filtering of QQQQ Price Data


As in Example 1.4 in Chapter 1, the closing price c[n] of QQQQ for the 50-business-day period
from March 1, 2004, up to May 10, 2004, will be considered. The time series c[n] will be applied to
an 11-day EWMA filter with b = 0.7. The output y[n] of the filter is then computed by evaluat-
ing (2.4). To accomplish this, the weights wi = abi are computed and then are arranged in a row
vector w having the form

w = [wN - 1 wN - 2 wN - 3 Á w0]

Then y[n] is given by the MATLAB multiplication w*c(n-10:n). The MATLAB commands for
computing the filter output y[n] for 11 … n … 50 are as follows:

c=csvread('QQQQdata2.csv',1,4,[1 4 50 4]);
b=0.7;
a=(1-b)/(1-b^11);
i=1:11;
w=a*(b.^(11-i));
for n=11:50;
y(n)=w*c(n-10:n);
end;
n=11:50;
plot(n,c(n),n,c(n),’o’,n,y(n),n,y(n),’*’)
grid
xlabel('Day(n)')
ylabel('c[n] and y[n]')

The resulting MATLAB plot for the filter input c[n] and the filter output y[n] is given in
Figure 2.1, with the values of c[n] plotted using o’s and the values of y[n] plotted using *’s.
Comparing Figure 1.27 in Chapter 1 with Figure 2.1 shows that there is less time delay
through the 11-day EWMA filter with b = 0.7 than there is through the 11-day MA filter. To
see this more clearly, in Figure 2.2 the output of the 11-day MA filter is combined with the
plot of c[n] and the output of the 11-day EWMA filter. The values of the MA filter response
are plotted with +’s.

47

www.EngineeringEBooksPdf.com
Section 2.1 Input/Output Representation of Discrete-Time Systems

37.5

37

36.5

c[n] and y[n]


36

35.5

35

34.5

34
10 15 20 25 30 35 40 45 50
Day (n)

FIGURE 2.1
MATLAB plot of EWMA filter input c[n] and output y[n].

37.5

37

36.5
c[n] and filter outputs

36

35.5

35

34.5

34
10 15 20 25 30 35 40 45 50
Day (n)

FIGURE 2.2
MATLAB plot of c[n] and filter outputs.

48

www.EngineeringEBooksPdf.com
Chapter 2 Time-Domain Models of Systems

2.1.2 A General Class of Systems


The class of systems given by the input/output representation (2.3) can be generalized
further by replacing the upper index N - 1 in the summation with n; that is, the
input/output relationship is now given by
n
y[n] = a wix[n - i], n Ú 0 (2.8)
i=0

where, in general, there are an infinite number of nonzero weights w0 , w1 , w2 , Á . It


turns out that any causal linear time-invariant discrete-time system with the input x[n]
equal to zero for all n 6 0 can be expressed in the form (2.8).
A system with the input/output representation (2.8) is usually expressed in terms
of its unit-pulse response, which is defined as follows: The unit-pulse response, denoted
by h[n], is the output response of the system resulting from the application of the unit
pulse d[n]; that is, x[n] = d[n]. (Recall that d[0] = 1 and d[n] = 0 for all n Z 0.) Note
that, since d[n] = 0 for n = -1, -2, Á , by causality the unit-pulse response h[n] must
be zero for all integers n 6 0 (see Section 1.5 in Chapter 1).
To compute the unit-pulse response for a system given by (2.8), simply insert
x[n] = d[n] into (2.8), which gives
n
h[n] = a wid[n - i], n Ú 0 (2.9)
i=0

Now, since d[n - i] = 0 for all i Z n, and d[n - i] = 1 when i = n, (2.9) reduces to

h[n] = wn , n Ú 0

Hence, the value h[n] of the unit-pulse response at time n is equal to the weight wn .

Example 2.2 Unit-Pulse Responses of the MA and EWMA Filters


From the preceding development, the weights of the 11-day MA filter are given by wi = 1>11
for i = 0, 1, Á , 10, and by (2.5) and (2.6), the weights of the 11-day EWMA with b = 0.7 are
given by wi = abi = 10.3061210.72i, i = 0, 1, Á , 10. For both filters, wi = 0 for i Ú 11. Then
setting h[n] = wn , n = 0, 1, Á , 10, and h[n] = 0 for n Ú 11 and n … -1 yields the stem plots
of the unit-pulse responses for the 11-day MA and EWMA filters shown in Figure 2.3. In the
figure, h1[n] is the unit-pulse response of the 11-day MA filter and h2[n] is the unit-pulse re-
sponse of the 11-day EWMA filter with b = 0.7. Note that the unit-pulse responses of the 11-
day MA and EWMA filters are finite-duration signals; that is, h[n] is nonzero for only a finite
number of values of n.

Rewriting (2.8) in terms of the unit-pulse response h[n] gives


n
y[n] = a h[i]x[n - i], n Ú 0 (2.10)
i=0

The operation defined by the expression


n

a h[i]x[n - i]
i=0

49

www.EngineeringEBooksPdf.com
Section 2.2 Convolution of Discrete-Time Signals

0.4

0.3

h1[n]
0.2

0.1

0
5 0 5 10 15 20
n

0.4

0.3
h2[n]

0.2

0.1

0
5 0 5 10 15 20
n

FIGURE 2.3
Unit-pulse responses of 11-day MA filter, h1[n], and EWMA filter, h2[n].

is called the convolution of h[n] and x[n], and is denoted by the symbol ‘‘*”; that is,
n
h[n] * x[n] = a h[i]x[n - i]
i=0

Rewriting (2.10) in terms of the convolution symbol gives

y[n] = h[n] * x[n], n Ú 0 (2.11)

By (2.11), the output response y[n] resulting from input x[n] with x[n] = 0 for all
n 6 0 is equal to the convolution of the unit-pulse response h[n] with the input x[n].
Equation (2.11) [or (2.10)] is called the convolution representation of the system. This is
a time domain model, since the components of (2.11) are functions of the discrete-time
index n.
An interesting consequence of the convolution representation (2.10) is the result
that the system is determined completely by the unit-pulse response h[n]. In particu-
lar, if h[n] is known, the output response resulting from any input x[n] can be comput-
ed by evaluating (2.10). The evaluation of the convolution operation is studied in the
next section.

2.2 CONVOLUTION OF DISCRETE-TIME SIGNALS


In the previous section, the convolution of an input x[n] and the unit-pulse response
h[n] were defined, with both x[n] and h[n] equal to zero for all n 6 0. In this section

50

www.EngineeringEBooksPdf.com

You might also like