Signal implementation with M ATLAB MATLAB is used frequently to simulate signals and systems. In this section, we present a few examples to illustrate the generation of different Continuous-time (CT) Signal and discrete-time (DT) signals in MATLAB. We also show how the CT and DT signals are plotted in MATLAB. In this lab contains following categories. Time domain 1. Using MATLAB for the following categories for signals: A. Continuous-time and discrete-time signals 1. Plotting a continuous-time (CT) signal 2. Plotting a discrete-time (DT) signal B. Periodic and aperiodic (or nonperiodic) signals C. Energy and power signals D. Even and odd signals. 2. Signal operations 3. Classification of systems 4. THE OUTPUT RESPONSE OF AN LTI- SYSTEM - Convolution in discrete time - Differential equations - Difference equations Frequency Domain 5. Analysis of periodic signals: the trigonometric and exponential CTFS representations. 6. Analysis of aperiodic signals: the CTFT representations. 7. Discrete Fourier transform (DFT) 8. Difference equation with z-transform Using MATLAB for the following categories for signals: A. Continuous-time and discrete-time signals 1. Plotting a continuous-time (CT) signal If a signal is defined for all values of the independent variable t, it is called a continuous-time (CT) signal. We use a set of sample values from sampling of continuous-time (CT) signal to represent the continuous time signal in a mathematical form. For example
36
Embed
Signal implementation with MATLAB - eReportz · Signal implementation with M ... In the last section when plotting sinusoidal signals ... Display x with the help of the MATLAB function
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Signal implementation with MATLAB
MATLAB is used frequently to simulate signals and systems. In this section, we
present a few examples to illustrate the generation of different Continuous-time (CT)
Signal and discrete-time (DT) signals in MATLAB. We also show how the CT and DT
signals are plotted in MATLAB.
In this lab contains following categories.
Time domain
1. Using MATLAB for the following categories for signals:
A. Continuous-time and discrete-time signals
1. Plotting a continuous-time (CT) signal
2. Plotting a discrete-time (DT) signal
B. Periodic and aperiodic (or nonperiodic) signals
C. Energy and power signals
D. Even and odd signals.
2. Signal operations
3. Classification of systems
4. THE OUTPUT RESPONSE OF AN LTI- SYSTEM - Convolution in discrete time
- Differential equations
- Difference equations
Frequency Domain
5. Analysis of periodic signals: the trigonometric and exponential
CTFS representations.
6. Analysis of aperiodic signals: the CTFT representations.
7. Discrete Fourier transform (DFT) 8. Difference equation with z-transform
Using MATLAB for the following categories for signals:
A. Continuous-time and discrete-time signals
1. Plotting a continuous-time (CT) signal
If a signal is defined for all values of the independent variable t, it is called a continuous-time
(CT) signal.
We use a set of sample values from sampling of continuous-time (CT) signal to represent the
continuous time signal in a mathematical form. For example
>> t = [-5:0.001:5]; % Set the time from -5 to 5
% with a sampling
% rate of 0.001s
>> x = 5*sin(2*pi*t1)
% compute function x1
% plot x(t)
>> plot(t,x); % plot a CT signal
>> grid on; % turn on the grid
>> xlabel(‘time (t)’); % Label the x-axis as time
>> ylabel(‘5sin(2\pi t)’); % Label the y-axis
>> title(‘Part (a)’); % Insert the title
First of all, the time value for which x (t) is to be plotted stored as element vector t. Second,
create a vector with elements corresponding time values by the expression 5*sin(2*pi*t) .
Third, by the command plot(t,x) , x is plotted versus t. The resulting plot of x(t) is shown in
the figure. Two important things to note that, in generating a MATLAB plot of a continuous-
time signal, first, to plot a continuous-time signal we use the command plot(t,x), and second ,
the increment in time step must be sufficiently small to yield a smooth plot.
Problem 1A. 1
Generate and sketch in the same figure each of the following CT signals using MATLAB. Do
not use the “for” loops in your code.
In each case, the horizontal axis t used to sketch the CT should extend only for the range
over which the three signals are defined.
(a) x1(t ) = 5 sin(2πt+5 ) cos(πt − 8) for −5 ≤ t ≤ 5;
(b) x2(t ) = 5e−0.2t sin (2πt-3 ) for −10 ≤ t ≤ 10;
(c) x3(t ) = e(j4π−0.5)t u(t+2 ) for 5 ≤ t ≤ 15.
2. Plotting a discrete-time (DT) signal
In the last section when plotting sinusoidal signals using computer tools, we are also faced
with the fact that only a discrete-time version of a continuous-time signal may be generated
and plotted. This fact holds true whether we are using MATLAB, C, Mathematica, Excel, or
any other computational tool. When we need to realize that sample spacing needs to be small
enough relative to the frequency such that when plotted by connecting the dots, the waveform
picture is not too distorted. For now we are more concerned with having a good plot
appearance relative to the expected shape
In this section, on the other hand, if a signal is defined only at discrete values of time, it is
called a discrete-time (DT) signal. We use as a set of sample values from sampling of continuous-
time (CT) signal to represent the continuous time signal in a mathematical form.
In our notation, a CT signal is denoted by x(t ) with regular parenthesis, and a DT signal is
denoted with square parenthesis ,x[k]. An important things to note that we use the command
stem(k,x) to plot a discrete-time signal.
Elementary signals
o Unit impulse function The DT impulse function, also referred to as the Kronecker delta function on the DT
unit sample function, is defined as follows:
Unlike the CT unit impulse function, the DT impulse function has no ambiguity in its
definition; it is well defined for all values of k.
o Unit step function The DT unit step function u[k] is defined as follows:
o Rectangular pulse function
The DT rectangular pulse rect(k/(2N + 1)) is defined as follows:
o Sinusoidal function The DT sinusoid is defined as follows:
,
where is the DT angular frequency. A CT sinusoidal signal x(t ) =sin( t + θ) is
always periodic, whereas its DT counterpart x[k] = sin( k +θ) is not necessarily
periodic. The DT sinusoidal signal is periodic only if the fraction /2π is a rational
number.
o DT exponential function The DT complex exponential function with radian frequency is defined as follows:
(1.39)
Case 1 Imaginary component is zero ( = 0). The signal takes the following form:
,
when the imaginary component of theDTcomplex frequency is zero. Similar to CT
exponential functions, the DT exponential functions can be classified as rising, decaying, and
constant-valued exponentials depending upon the value of σ.
Case 2 Real component is zero (σ = 0). The DT exponential function takes the
following form:
Recall that a complex-valued exponential is periodic if /2π is a rational number. An
alternative representation of the DT complex exponential function
Problem 1A. 2.1
Generate the following discrete time signals. Display the signals with the help of the
MATLAB function stem (k,x) to plot a discrete-time signal in the considered range of the k-
axis.
= 0.9⋅ , 1≤ k ≤ 10
= 0.8⋅ , - 10 ≤ k ≤10
=1.5⋅ , 300 ≤ k ≤ 350
= 4.5⋅ , - 15 ≤ k ≤ 5
Problem 1A. 2.2
Repeat Problem 1.1 for the following DT sequences:
(a) ,−10 ≤ k ≤ 20;
(b) , −5 ≤ k ≤ 25;
(c
,0 ≤ k ≤ 50.
B. Periodic and aperiodic signals
A CT signal x(t ) is said to be periodic if it satisfies the following property:
at all time t and for some positive constant T0. The smallest positive value of T0 that satisfies
the periodicity condition, Eq. (1.3), is referred to as the fundamental period of x(t ).
Likewise, a DT signal x[k] is said to be periodic if it satisfies
at all time k and for some positive constant K0. The smallest positive value of that satisfies
the periodicity condition, Eq. (1.4), is referred to as the fundamental period of x[k]. A signal
that is not periodic is called an aperiodic or non-periodic signal.
The reciprocal of the fundamental period of a signal is called the fundamental frequency.
Mathematically, the fundamental frequency is expressed as follows
, for CT signals or for DT signals
where and are, respectively, the fundamental periods of the CT and DT signals. The
frequency of a signal provides useful information regarding how fast the signal changes its
amplitude. The unit of frequency is cycles per second(c/s) or hertz (Hz).
Sometimes, we also use radians per second as a unit of frequency. Since there are 2π radians
(or 360◦) in one cycle, a frequency of hertz is equivalent to 2π radians per second. If
radians per second is used as a unit of frequency, the frequency is referred to as the angular
frequency and is given by
, for CT signals, or for DT signals
Although all CT sinusoidals are periodic, their DT counterparts θ may not always be periodic. An arbitrary DT sinusoidal sequence is periodic if is a rational number.
The term rational number is defined as a fraction of two integers. Given that the DT
sinusoidal sequence is periodic, its fundamental period is evaluated
from the relationship
As
This can be extended to include DT complex exponential signals. Collectively, we state the
following.
(1) The fundamental period of a sinusoidal signal that is evaluated by
with m set to the smallest integer that results in an integer value for .
(2) A complex exponential θ to be periodic
. The fundamental period of a complex exponential is also given by
More over we can represent a periodic signal with a sum of single-period models each of
which is shifted to be adjacent to another. That is
Where the model of one period signal starting at the arbitrary time
Likewise for a discrete time signal
Where
Problem 1B. 1
The following term is given for the impulse sequence:
The total length of the sequence is MP, with P the period. Generate a impulse sequence s(k )
with the period P = 10 and a total length of 40 values. The start index shall be k=0 and the
scaling factor Ai shall be identical 1.
Problem 1B. 2
The following MATLAB Code generates a sequence x:
x=[0;1;1;0;1;0]*ones(1,7); x=x(:);
Display x with the help of the MATLAB function stem(k,x) and create a a sum of single-
period models corresponding to the equation for the signal x .
Problem 1B. 3: Trigonometrical Sequence
a) Generate and display the following signals. Take care of the rage of the k-axis:
, −25 ≤ k ≤ 25
, −25 ≤ k ≤ 25
, 0 ≤ k ≤ 55
, 0 ≤ k ≤ 55
Question:
- Report a simple equation for x2(k) without using trigonometrical functions!
- Why are x3(k) and x4(k) not periodical sequences?
C. Energy and power signals
The energy present in a CT or DT signal within a given time interval is given by the
following:
CT signals
DT sequences
The total energy of a CT signal is its energy calculated over the interval t = [−∞,∞]. Likewise,
the total energy of a DT signal is its energy calculated over the range k = [−∞,∞]. The
expressions for the total energy are therefore given by the following:
CT signals
DT sequences
Since power is defined as energy per unit time, the average power of a CT signal x(t )over the
interval t = (−∞,∞) and of a DT signal x[k] over the range k = [−∞,∞] are expressed as
follows:
CT signals
DT sequences
Both equations are simplified considerably for periodic signals. Since a periodic signal
repeats itself, the average power is calculated from one period of the signal as follows:
CT signals
DT sequences
The symbols and are, respectively, the fundamental periods of the CT signal x(t ) and
the DT signal x[k]. To illustrate this mathematically, we introduce the notation to imply
that the integration is performed over a complete period and is independent of the lower
limit. Likewise, while computing the average power of a DT signal x[k], the upper and lower
limits of the summation can take any values as long as the duration of summation equals one
fundamental period .
A signal x(t ), or x[k], is called an energy signal if the total energy has a non-zero
finite value, 0 < < ∞. On the other hand, a signal is called a power signal if it has non-zero
finite power, i.e. 0 < < ∞. Note that a signal cannot be both energy and a power signal
simultaneously. The energy signals have zero average power whereas the power signals have
infinite total energy.
Problem 1C. 1
Determine if the DT sequence g[k] = 3 cos(πk/10) is a power or an energy signal and also
write an m-file for calculation.
D. Even and odd signals.
A CT signal (t ) is said to be an even signal if
Conversely, a CT signal (t ) is said to be an odd signal if
A DT signal is said to be an even signal if
]
Conversely, a DT signal xo[k] is said to be an odd signal if
]
The even signal property, Eq. (1.16) for CT signals or Eq. (1.18) for DT signals, implies that
an even signal is symmetric about the vertical axis (t = 0). Likewise, the odd signal property,
Eq. (1.17) for CT signals or Eq. (1.19) for DT signals, implies that an odd signal is anti-
symmetric about the vertical axis (t = 0).
Such signals are classified in the “neither odd nor even” category. Neither odd nor even
signals can be expressed as a sum of even and odd signals as follows:
where the even component is given by
while the odd component is given by
Fig. 1.7. (a) The CT signal x(t ) (b) Even component of x(t ). (c) Odd component of x(t ).
Problem 1D. 1
Determine if the following DT signals are even, odd, or neither even nor odd. In the latter
case, evaluate and sketch the even and odd components of the DT signals:
(i) x1[k] = sin(4k) + cos(2π/k3);
(ii) x2[k] = sin(πk/3000) + cos(2πk/3);
(iii) x3[k] =exp(j(7πk/4)) + cos(4πk/7 + π);
(iv) x4[k] = sin(3πk/8) cos(63πk/64);
(v) x5[k] =
2. Signal operations An important concept in signal and system analysis is the transformation of a signal.
In this section, we consider three elementary transformations that are performed on a signal
in the time domain. The transformations that we consider are time shifting, time scaling, and
time inversion.
Time shifting The time-shifting operation delays or advances forward the input signal in time.
Consider a CT signal φ(t ) obtained by shifting another signal x(t) by T time units. The time-
shifted signal φ(t ) is expressed as follows:
If T < 0 , the signal is said to be delayed in time. To obtain the time-delayed signal φ(t ) ,the
origin of the signal x(t) is shifted towards the right-hand side by duration T along the t-axis.
On the other hand, if m > 0, the signal is advanced forward in time. The time-advanced signal
φ(t ) is obtained by shifting x(t) towards the left-hand side by duration T along the t-axis.
The theory of the CT time-shifting operation can also be extended to DT sequences.
When a DT signal x[k] is shifted by m time units, the delayed signal φ[k] is expressed as
follows:
If m < 0, the signal is said to be delayed in time. To obtain the time-delayed signal φ[k], the
origin of the signal x[k] is shifted towards the right-hand side along the k-axis by m time
units.
On the other hand, if m > 0, the signal is advanced forward in time. The time-advanced
signal φ[k] is obtained by shifting x[k] towards the left-hand side along the k-axis by m time
units.
Time scaling The time-scaling operation compresses or expands the input signal in the time
domain. A CT signal x(t ) scaled by a factor c in the time domain is denoted by x(ct). If c > 1 ,
the signal is compressed by a factor of c. On the other hand, if 0 < c < 1 the signal is
expanded.
A CT signal x(t ) can be scaled to x(ct) for any value of c. For the DTFT, however, the
time-scaling factor c is limited to integer values. We discuss the time scaling of the DT
sequence in the following.
(i) Decimation If a sequence x[k] is compressed by a factor c, some data samples of x[k] are
lost. Compression (referred to as decimation for DT sequences) is, therefore, an
irreversible process in the DT domain as the original sequence x[k] cannot be
recovered precisely from the decimated sequence y[k].
(ii) Interpolation In the DT domain, expansion (also referred to as interpolation) is defined as
follows:
=
The interpolated sequence inserts (m − 1) zeros in between adjacent samples
of the DT sequence x[k]. Interpolation of the DT sequence x[k] is a reversible process
as the original sequence x[k] can be recovered from
Time inversion The time inversion (also known as time reversal or reflection) operation reflects the
input signal about the vertical axis (t = 0). When a CT signal x(t ) is time reversed, the
inverted signal is denoted by x(−t ). Likewise, when a DT signal x[k] is time-reversed, the
inverted signal is denoted by x[−k].
Problem 2.1
Write a MATLAB function mydecimate with the following format:
function [y] = mydecimate(x, M)
% MYDECIMATE: computes y[k] = x[kM]
% where
% x is a column vector containing the DT input
% signal
% M is the scaling factor greater than 1
% y is a column vector containing the DT output time
% decimated by M
In other words, mydecimate accepts an input signal x[k] and produces the signal y[k] =
x[kM].
Problem 2.2
Repeat the last problem for the transformation y[k] = x[k/N]. In other words, write a
MATLAB function myinterpolate with the following format:
function [y] = myinterpolate(x, N)
% MYINTERPOLATE: computes y[k] = x[k/N]
% where
% x is a column vector containing the DT input
% signal
% N is the scaling factor greater than 1 % y is a column vector containing the DT output
% signal time expanded by N
Use linear interpolation based on the neighboring samples to predict any required unknown
values in x[k].
Problem 2.3
Construct a DT signal given by
(i) Sketch the signal using the stem function.
(ii) Using the mydecimate (Problem 2.1) and myinterpolate (Problem 2.2)
functions, transform the signal x[k] based on the operation y[k] = x[k/5] followed by
the operation z[k] = y[5k]. What is the relationship between x[k] and z[k]?
(iii) Repeat (ii) with the order of interpolation and decimation reversed.
3. Classification of systems We classified the systems based on the following definitions.
(1) A system is linear if it satisfies the principle of superposition.
(2) A system is time-invariant if a time-shift in the input signal leads to an identical shift
in the output signal without affecting the shape of the output.
(3) A system is memoryless if its output at t = t0 depends only on the value of input at t =
t0 and no other value of the input signal.
(4) A system is causal if its output at t = t0 depends on the values of the input signal in the
past, t ≤ t0, and does not require any future value (t > t0) of the input signal.
(5) A system is invertible if its input can be completely determined by observing its
output.
(6) A system is BIBO stable if all bounded inputs lead to bounded outputs.
An important subset of systems is described by those that are both linear and time-invariant
(LTI).
We expressed the memoryless, causality, stability, and invertibility properties of an LTID
system in terms of its impulse response.
1. An LTID system will be memoryless if and only if its impulse response h[k] = 0 for k
0.
2. An LTID system will be causal if and only if its impulse response h[k] = 0 for k < 0.
3. The impulse response h[k] of a (BIBO) stable LTID system is absolutely summable,
i.e.
4. An LTID system will be invertible if there exists another LTID system with impulse
response hi[k] such that h[k] ∗ hi[k] = δ[k]. The system with the impulse response hi[k]
is the inverse system.
Problem 3
Is the following system linear? time-variant systems?
4. THE OUTPUT RESPONSE OF AN LTI- SYSTEM.
we have so far presented two approaches to calculate the output response of an LTI
system: the differential equation method and the convolution method. Both methods can be
implemented using MATLAB. However, the convolution method is more convenient for
MATLAB implementation in the discrete-time domain.
Convolution in the discrete-time domain To find the output of a discrete system y[n] to an input x[n], we need the impulse
response,h[n], for the system. h[n] is the output of the system when the input is where
is the impulse signal. Notice that we do not know the system itself (the input–output
relation) but we know that if the input is the impulse signal , the output will be the
impulse response h[n].
Now consider the shifted impulse signal to the same system as shown in
figure below.
The output will also be shifted because we are considering only linear systems.
Therefore, will produce h[n-m].
We have also seen that any discrete signal can be represented as the sum of weighted
shifted impulses (samples). We have seen that the signal x[n] can be represented as
Note that each x[m] is a sample and a constant. Also, if x[m] is multiplied by and
applied to the discrete linear time-invariant system, the output will be as
figure below
Now let us say that we were to add all the shifted weighted samples
and present this as input to the same system. The output in this case is
or ∗
The above equation is the convolution equation that, given x[n], the input to a discrete
system, and h[n], the impulse response, will give you the output y[n].This also tells you that,
given h[n] for any system, you can find y[n]for any input x[n].
We can use MATLAB to compute y[n] for any input x[n] by convolution two
sequences x[n] and h[n] with MATLAB function conv(x,h).
Problem 4.1
Consider the following finite duration signals.
1.
2.
3.
Find x1 * x2 the convolution result, for the above cases.
Differential equations In this section, we present the method for constant-coefficient differential equations
with initial conditions. MATLAB provides several M-files for solving differential equations
with known initial conditions. The list includes ode23, ode45, ode113, de15s,
ode23s, ode23t, and ode23tb. Each of these functions uses a finite-difference-based
scheme for discretizing a CT differential equation and iterates the resulting DT finite-
difference equation for the solution.
Example 1
Compute the solution y(t ) for an equation produced below for convenience:
+ 4y(t ) = 2 cos(2t )u(t ),
with initial condition y(0) = 2 for 0 ≤ t ≤ 15. Compare the computed solution with the
analytical solution.
Solution
The first step towards solving the equation is to create an M-file containing the differential
equation. We implement a version of above equation given by
+ 4y(t ) = 2 cos(2t )u(t ),
where the derivative dy/dt is the output of the M-file based on the input y and time t . Calling
the M-file myfunc1, the format for the M-file is as follows:
function [ydot] = myfunc1(t,y)
% MYFUNC1
% Computes first derivative in the differential equation given the
value of
% signal y and time t.
% Usage: ydot = myfunc1(t,y)
ydot = -4*y + 2*cos(2*t).*(t >= 0)
The above function is saved in a file named myfunc1.m and placed in a directory included
within the defined paths of the MATLAB environment. To solve the differential equation
defined in myfunc1 over the interval 0 ≤ t ≤ 15, we invoke ode23 after initializing the
input parameters in an M-file as shown:
% MATLAB program to solve Equation
+ 4y(t ) = 2 cos(2t )u(t ), in myfunc1.m
tspan = [0:0.01:15]; % duration with resolution of 0.01s.
y0 = [2]; % initial condition
[t,y] = ode23(‘myfunc1’, tspan,y0); % solve ODE using ode23
plot(t,y) % plot the result
xlabel(‘time’) % Label of X-axis
ylabel(‘Output Response y(t)’) % Label of Y-axis
The final plot for MATLAB calculation is shown in the figure below.
Compare with analytical solving
Zero-input response of the system We determine the characteristic equation for the
difference equation as
(s + 4) = 0,
which has a root at s = −4. The zero-input response of the difference equation is given by
zero input response yzi(t ) = Ae−4t ,where A is a constant. The value of A is obtained from the
initial condition y(0−) = 2 V. Substituting y(0−) = 2 V in the above equation yields A = 2.The
zero-input response is given by yzi(t ) = 2e−4t
.
Zero-state response of the system The zero-state response is calculated by solving the
difference equation with a zero initial condition, y(0−) = 0. The homogeneous component of
the zero-state response of the difference equation is similar to the zero input response and is
given by
y(h)
zs (t ) = Ce−4t ,
where C is a constant. The particular component of the zero-state response of the difference
equation for input x(t ) = sin(2t ) is of the following form:
y(p)
zs (t ) = K1 cos(2t ) + K2 sin(2t ).
Substituting the particular component in difference equation gives K1 = 0.4 and K2 = 0.2.
The overall zero-state response of the system is as follows:
zero state response yzs(t ) = Ce−4t + 0.2 sin(2t ) + 0.4 cos(2t ),
with zero initial condition, i.e. yzs(t ) = 0. Substituting the initial condition in the zero-state
response yields C = −0.4. The total response of the system is the sum of the zero-input and
zero-state responses and is given by
y(t ) = 1.6e−4t
+ 0.2 sin(2t ) + 0.4 cos(2t ).
States as the total response of a LTIC system modeled with a first-order, constant-coefficient,
linear differential equation.
Difference equations
Consider the following linear, constant-coefficient difference equation:
Which models the relationship between the input sequence x[k] and the output response y[k]
of an LTID system? The ancillary conditions y[−1], y[−2], . . . ,y[−n] are also specified. To
solve the difference equation, MATLAB provides a built-in function filter with the
syntax >> [y] = filter(B,A,X,Zi);
In terms of the difference equation the input variables B and A are defined as follows:
A = [1, , . . . , ] and B = [ , , . . . , ]
While X is the vector containing the values of the input sequence and Zi denotes the initial
conditions of the delays used to implement the difference equation. The initial conditions
used by the filter function are not the past values of the output y[k] but a modified
version of these values. The initial conditions used byMATLAB can be obtained by using
another built-in function, filtic. The calling syntax for the filtic function is as
follows: >> [Zi] = filtic(B,A,yinitial);
For an n-order difference equation, the input variable yinitial is set to
>> yinitial = [y[−1], y[−2], . . . , y[−n]] ;
Example 2
The DT sequence x[k] = 2ku[k] is applied at the input of an LTID system described by the
following difference equation:
y[k + 1] − 0.4 y[k] = x[k],
with the ancillary condition y[−1] = 4. Compute the output response y[k] of the LTID system
for 0 ≤ k ≤ 50 using MATLAB.
Solution
The MATLAB code used to solve the difference equation is listed below. The explanation
follows each instruction in the form of comments.
>> k = [0:50]; % time index k = [-1,0, 1, ...50]
>> X = 2*k.*(k>=1); % Input signal
>> A = [1 -0.4]; % Coefficients with y[k]
>> B = [0 1]; % Coefficients with x[k]
>> Zi = filtic(B,A,4); % Initial condition
>> Y = filter(B,A,X,Zi); % Calculate output
The output response is stored in the vector Y. Printing the first six values of the output
response yields
Y = [1.6 0.6400 2.2560 4.9024 7.9610 11.1844],
This corresponds to the values of the output response y[k] for the duration 0 ≤ k ≤ 5.
Comparing with the numerical solution obtained in next.
Express y[k + 1] − 0.4y[k] = x[k] as follows:
which can alternatively be expressed as
By iterating from k = 0, the output response is computed as follows:
y[0] = 0.4y[−1] = 1.6,
y[1] = 0.4y[0] + 2 × 0 = 0.64,
y[2] = 0.4y[1] + 2 × 1 = 2.256,
y[3] = 0.4y[2] + 2 × 2 = 4.902,
y[4] = 0.4y[3] + 2 × 3 = 7.961,
y[5] = 0.4y[4] + 2 × 4 = 11.184.
Additional values of the output sequence for k > 5 can be similarly evaluated from further
iterations with respect to k.
We will observe that the two results are identical.
Problem 4.2
Plot the output response y(t) from MATLAB solution in Example 1 compared with the output
response y(t) from analytical solving.
From the result of analytic solution solved Equation
+ 4y(t ) = 2 cos(2t )u(t ) ,we have
y(t ) = 1.6e−4t
+ 0.2 sin(2t ) + 0.4 cos(2t ).
Problem 4.3
The DT sequence x[k] = 0.5ku[k] is applied at the input of an LTID system described by the
following second-order difference equation:
y[k + 2] + y[k + 1] + 0.25y[k] = x[k + 2],
with ancillary conditions y[−1] = 1 and y[−2] = −2. Compute the output response y[k] of the
LTID system for 0 ≤ k ≤ 50 using MATLAB.
*A special solution of the difference equation with the starting
condition , in case of - the input sequence - being the impulse sequence ,has - the output sequence or the solutions for linear difference equations with constant
coefficients –being the form of exponential sequences , y[k] = aku[k].
Problem 4.4
Linear difference equations are describe in MATLAB by two vectors a and b including in the
filter coefficients an and bm . The coefficient a0 is usually chosen to be 1.
a) Determine the vectors a and b for the following difference equation:
y [k] + 0.9 y [k-2] = 0.3x[k] + 0.6 x [k - 1] + 0.3 x [k - 2]
b) Calculate y[k] for x[k] =δ [k] and the side conditions y[-2] = y[-1] = 0 .
c) Determine the initial 128 values of the impulse response of the filter of subsection a)
Use the MATLAB function impz() .
Frequency-domain:
5. Analysis of periodic signals : the trigonometric and exponential
CTFS representations.
In this section, we introduce frequency-domain analysis of periodic signals based on
the trigonometric and exponential CTFS representations.
Expressing a periodic signal x(t ) as a linear combination of the sinusoidal set of
functions leads to the trigonometric repre-
sentation of the CTFS. The trigonometric CTFS is defined as follows:
Where 2 / is the fundamental frequency of x(t ) and coefficients , , and are
referred to as the trigonometric CTFS coefficients. The coefficients are calculated using the
following formulas:
and
The resulting CTFS representation is referred as the exponential CTFS. The
exponential CTFS is obtained by expressing the periodic signal x(t ) as a linear combination
of complex exponentials {exp(jn t )} and is given by
where the exponential CTFS coefficients Dn are calculated using the following expression:
The plot of the magnitude |Dn| of the exponential CTFS coefficients versus the coefficient
number n is referred to as the magnitude spectrum, while the plot of the phase <Dn of the
exponential CTFS coefficients versus the coefficient number n is referred to as the phase
spectrum of the periodic signal x(t ).
Calculating the output response y(t) of an LTIC system to a periodic input x(t ). In
such cases, the output y(t) is given by
Where the transfer function is obtained from the impulse response h(t) of the LTIC
system as follows:
The above expression also defines the continuous-time Fourier transform (CTFT) for
aperiodic signals, which is covered in depth in next section.
Using MATLAB script, ictfs.m, to calculate the output response y(t) of an LTIC system
to a periodic input x(t ).
o First, we have to decide representations of CTFS weather it is the trigonometric or
exponential CTFS.
o Second, find input parameters such as - a0,an,and bn - for the trigonometric
representations of CTFS.
The coefficients are calculated using the following formulas:
and
For the exponential representations of CTFS ,we have to find input parameter,En
calculated using the following formula:
the exponential CTFS coefficients of the output y(t ) are given by
MATLAB function ictfs.m % This routine calculates a signal from its Trigonometric or Exponential % CTFS coefficients. function [x] = ictfs(w0,t,dna0,an,bn) % Input parameters: % % w0: Fundamental frequency (in rad/s) % t: time range fir signal reconstruction % dna0 : = a0 if nargin = 3, i.e., for trigonometric CTFS coefficients % = Dn if nargin = 5, i.e., for exponential CTFS coefficients % an: Coefficients for cosine functions in the CTFS % bn: Coefficients for sine functions in the CTFS % % Output Parameter: % x: Reconstructed signal % %%% Trigonometric CTFS Coefficients if nargin==5 no_coeff =min(length(an),length(bn)) ; no_coeff =min(2000,no_coeff) ; x = dna0*ones(1,length(t)) ;
for n=1:no_coeff x = x + an(n).*cos(n*w0*t) + bn(n).*sin(n*w0*t) ; end
no_coeff =length(dna0) ; % we assume that no_coeff=odd. The Do is the
centre element % The negative Dn values are given in the first half of dna0 and the % positive Dn values are given in the second half of dna0
if (rem(no_coeff,2)~=1) % fprintf(fid,'Error: length (Dn0= - must have odd length
%6d\n',length(dna0)); else end
N = (no_coeff-1)/2; no_iter =min(4000,N); % this limits the computational complexity x = dna0(N+1)*ones(1,length(t)) ; for n=1:no_iter x1 = dna0(N+1+n).*exp(j*n*w0*t); x2 = dna0(N+1-n).*exp(-j*n*w0*t); x = x + x1 + x2 ; end else end
Problem 5.1
A periodic signal is represented by the following CTFS:
(i) From the CTFS representation, determine the fundamental period T0 of x(t ).
(ii) Comment on the symmetry properties of x(t ).
(iii) Plot the function to verify if your answers to (i) and (ii) are correct .The function,
reconstructed using the first 1000 CTFS coefficients, is plotted for −1 ≤ t ≤ 1.
Hint !
o Fundamental frequency is the lowest frequency in a harmonic series.
o To plot the time interval ,−1 ≤ t ≤ 1, for the first 1000 CTFS coefficients ,we define >> t = -1:0.001:1 ;
o Compare the equation
to .
We have seen that a0 = an = 0 for all n ,and bn =
.
At last, we define initializing CTFS parameters by following.
nterms = 1000 ; w0 = 4*pi ; t = -1:0.001:1 ; % x(t ) is an odd function, then a0 = an = 0 for all n. a0=0 ; % Initializing coefficients an as a vector an = zeros(1,nterms) ;
% Initializing a vector n for coefficients bn for n = 1,3,5,7,... nnz = 1:2:nterms;