Skip to content Skip to navigation

OpenStax_CNX

You are here: Home » Content » Lab 2 - Discrete-Time Systems

Navigation

Lenses

What is a lens?

Definition of a lens

Lenses

A lens is a custom view of the content in the repository. You can think of it as a fancy kind of list that will let you see content through the eyes of organizations and people you trust.

What is in a lens?

Lens makers point to materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

Who can create a lens?

Any individual member, a community, or a respected organization.

What are tags? tag icon

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

This content is ...

Affiliated with (What does "Affiliated with" mean?)

This content is either by members of the organizations listed or about topics related to the organizations listed. Click each link to see a list of all content affiliated with the organization.
  • NSF Partnership display tagshide tags

    This module is included inLens: NSF Partnership in Signal Processing
    By: Sidney BurrusAs a part of collection: "Purdue Digital Signal Processing Labs (ECE 438)"

    Click the "NSF Partnership" link to see all content affiliated with them.

    Click the tag icon tag icon to display tags associated with this content.

  • Featured Content display tagshide tags

    This module is included inLens: Connexions Featured Content
    By: ConnexionsAs a part of collection: "Purdue Digital Signal Processing Labs (ECE 438)"

    Click the "Featured Content" link to see all content affiliated with them.

    Click the tag icon tag icon to display tags associated with this content.

Also in these lenses

  • UniqU content

    This module is included inLens: UniqU's lens
    By: UniqU, LLCAs a part of collection: "Purdue Digital Signal Processing Labs (ECE 438)"

    Click the "UniqU content" link to see all content selected in this lens.

  • Lens for Engineering

    This module is included inLens: Lens for Engineering
    By: Sidney Burrus

    Click the "Lens for Engineering" link to see all content selected in this lens.

Recently Viewed

This feature requires Javascript to be enabled.

Tags

(What is a tag?)

These tags come from the endorsement, affiliation, and other lenses that include this content.
 

Lab 2 - Discrete-Time Systems

Module by: Charles A. Bouman. E-mail the author

Question or Comments

Questions or comments concerning this laboratory should be directed to Prof. Charles A. Bouman, School of Electrical and Computer Engineering, Purdue University, West Lafayette IN 47907; (765) 494-0340; bouman@ecn.purdue.edu

Introduction

A discrete-time system is anything that takes a discrete-time signal as input and generates a discrete-time signal as output.1 The concept of a system is very general. It may be used to model the response of an audio equalizer or the performance of the US economy.

In electrical engineering, continuous-time signals are usually processed by electrical circuits described by differential equations. For example, any circuit of resistors, capacitors and inductors can be analyzed using mesh analysis to yield a system of differential equations. The voltages and currents in the circuit may then be computed by solving the equations.

The processing of discrete-time signals is performed by discrete-time systems. Similar to the continuous-time case, we may represent a discrete-time system either by a set of difference equations or by a block diagram of its implementation. For example, consider the following difference equation.

y ( n ) = y ( n - 1 ) + x ( n ) + x ( n - 1 ) + x ( n - 2 ) y ( n ) = y ( n - 1 ) + x ( n ) + x ( n - 1 ) + x ( n - 2 )
(1)

This equation represents a discrete-time system. It operates on the input signal x(n)x(n) to produce the output signal y(n)y(n). This system may also be defined by a system diagram as in Figure 1.

Figure 1: Diagram of a discrete-time system. (D = unit delay)
Figure 1 (dtsystem.png)

Mathematically, we use the notation y=S[x]y=S[x] to denote a discrete-time system SS with input signal x(n)x(n) and output signal y(n)y(n). Notice that the input and output to the system are the complete signals for all time n. This is important since the output at a particular time can be a function of past, present and future values of x(n)x(n).

It is usually quite straightforward to write a computer program to implement a discrete-time system from its difference equation. In fact, programmable computers are one of the easiest and most cost effective ways of implementing discrete-time systems.

While equation Equation 1 is an example of a linear time-invariant system, other discrete-time systems may be nonlinear and/or time varying. In order to understand discrete-time systems, it is important to first understand their classification into categories of linear/nonlinear, time-invariant/time-varying, causal/noncausal, memoryless/with-memory, and stable/unstable. Then it is possible to study the properties of restricted classes of systems, such as discrete-time systems which are linear, time-invariant and stable.

Background Exercises

INLAB REPORT:

Submit these background exercises with the lab report.

Example Discrete-time Systems

Discrete-time digital systems are often used in place of analog processing systems. Common examples are the replacement of photographs with digital images, and conventional NTSC TV with direct broadcast digital TV. These digital systems can provide higher quality and/or lower cost through the use of standardized, high-volume digital processors.

The following two continuous-time systems are commonly used in electrical engineering:

differentiator: y ( t ) = d d t x ( t ) integrator: y ( t ) = - t x ( τ ) d τ differentiator: y ( t ) = d d t x ( t ) integrator: y ( t ) = - t x ( τ ) d τ
(2)

For each of these two systems, do the following:

  • i.: Formulate a discrete-time system that approximates the continuous-time function.
  • ii.: Write down the difference equation that describes your discrete-time system. Your difference equation should be in closed form, i.e. no summations.
  • iii.: Draw a block diagram of your discrete-time system as in Figure 1.

Stock Market Example

One reason that digital signal processing (DSP) techniques are so powerful is that they can be used for very different kinds of signals. While most continuous-time systems only process voltage and current signals, a computer can process discrete-time signals which are essentially just sequences of numbers. Therefore DSP may be used in a very wide range of applications. Let's look at an example.

A stockbroker wants to see whether the average value of a certain stock is increasing or decreasing. To do this, the daily fluctuations of the stock values must be eliminated. A popular business magazine recommends three possible methods for computing this average.

avgvalue(today) = 1 3 value(today)+value(yesterday)+value(2 days ago) avgvalue(today) = 1 3 value(today)+value(yesterday)+value(2 days ago)
(3)
avgvalue(today) = 0 . 8 * avgvalue(yesterday) + 0 . 2 * (value(today)) avgvalue(today) = 0 . 8 * avgvalue(yesterday) + 0 . 2 * (value(today))
(4)
avgvalue(today) = avgvalue(yesterday) + 1 3 (value(today)-(value(3 days ago)) avgvalue(today) = avgvalue(yesterday) + 1 3 (value(today)-(value(3 days ago))
(5)

Do the following:

  • For each of the these three methods: 1) write a difference equation, 2) draw a system diagram, and 3) calculate the impulse response.
  • Explain why methods Equation 3 and Equation 5 are known as moving averages.

Example Discrete-Time Systems

Write two Matlab functions that will apply the differentiator and integrator systems, designed in the "Example Discrete-time Systems" section, to arbitrary input signals. Then apply the differentiator and integrator to the following two signals for -10n20-10n20.

  • δ ( n ) - δ ( n - 5 ) δ ( n ) - δ ( n - 5 )
  • u(n)-u(n-(N+1)) u(n)-u(n-(N+1)) with N=10 N=10

Hint: To compute the function u(n)u(n) for -10n20-10n20, first set n = -10:20, and then use the Boolean expression u = (n>=0).

For each of the four cases, use the subplot and stem commands to plot each input and output signal on a single figure.

INLAB REPORT:

Submit printouts of your Matlab code and hardcopies containing the input and output signals. Discuss the stability of these systems.

Difference Equations

In this section, we will study the effect of two discrete-time filters. The first filter, y=S1[x]y=S1[x], obeys the difference equation

y ( n ) = x ( n ) - x ( n - 1 ) y ( n ) = x ( n ) - x ( n - 1 )
(6)

and the second filter, y=S2[x]y=S2[x], obeys the difference equation

y ( n ) = 1 2 y ( n - 1 ) + x ( n ) y ( n ) = 1 2 y ( n - 1 ) + x ( n )
(7)

Write Matlab functions to implement each of these filters.

Note:

In Matlab, when implementing a difference equation using a loop structure, it is very good practice to pre-define your output vector before entering into the loop. Otherwise, Matlab has to resize the output vector at each iteration. For example, say you are using a FOR loop to filter the signal x(n)x(n), yielding an output y(n)y(n). You can pre-define the output vector by issuing the command y=zeros(1,N) before entering the loop, where N is the final length of y. For long signals, this speeds up the computation dramatically.

Now use these functions to calculate the impulse response of each of the following 5 systems: S1S1, S2S2, S1(S2)S1(S2) (i.e., the series connection with S1S1 following S2S2), S2(S1)S2(S1) (i.e., the series connection with S2S2 following S1S1), and S1+S2S1+S2.

INLAB REPORT:

For each of the five systems, draw and submit a system diagram (use only delays, multiplications and additions as in Figure 1). Also submit plots of each impulse response. Discuss your observations.

Audio Filtering

For this section download the music.au file. For help on how to play audio signals click here.

Use the command auread to load the file music.au into Matlab. Then use the Matlab function sound to listen to the signal.

Next filter the audio signal with each of the two systems S1S1 and S2S2 from the previous section. Listen to the two filtered signals.

INLAB REPORT:

How do the filters change the sound of the audio signals? Explain your observations.

Inverse Systems

Consider the system y=S2[x]y=S2[x] from the "Difference Equations" section. Find a difference equation for a new system y=S3[x]y=S3[x] such that δ=S3[S2[δ]]δ=S3[S2[δ]] where δδ denotes the discrete-time impulse function δ(n)δ(n). Since both systems S2S2 and S3S3 are LTI, the time-invariance and superposition properties can be used to obtain x=S3[S2[x]]x=S3[S2[x]] for any discrete-time signal xx. We say that the systems S3S3 and S2S2 are inverse filters because they cancel out the effects of each other.

Hint: The system y=S3[x]y=S3[x] can be described by the difference equation

y ( n ) = a x ( n ) + b x ( n - 1 ) y ( n ) = a x ( n ) + b x ( n - 1 )
(8)

where aa and bb are constants.

Write a Matlab function y = S3(x) which implements the system S3S3. Then obtain the impulse response of both S3S3 and S3[S2[δ]]S3[S2[δ]].

INLAB REPORT:

Draw a system diagram for the system S3S3, and submit plots of the impulse responses for S3S3 and S3(S2)S3(S2).

System Tests

For this section download the zip file bbox.zip.

Often it is necessary to determine if a system is linear and/or time-invariant. If the inner workings of a system are not known, this task is impossible because the linearity and time-invariance properties must hold true for all possible inputs signals. However, it is possible to show that a system is non-linear or time-varying because only a single instance must be found where the properties are violated.

The zip file bbox.zip contains three "black-box" systems in the files bbox1.p, bbox2.p, and bbox3.p. These files work as Matlab functions, with the syntax y=bboxN(x), where x and y are the input and the output signals, and N = 1, 2 or 3. Exactly one of these systems is non-linear, and exactly one of them is time-varying. Your task is to find the non-linear system and the time-varying system.

Hints:

  1. You should try a variety of input signals until you find a counter-example.
  2. When testing for time-invariance, you need to look at the responses to a signal and to its delayed version. Since all your signals in MATLAB have finite duration, you should be very careful about shifting signals. In particular, if you want to shift a signal xx by MM samples to the left, xx should start with at least MM zeros. If you want to shift xx by MM samples to the right, xx should end with at least MM zeros.
  3. When testing for linearity, you may find that simple inputs such as the unit impulse do not accomplish the task. In this case, you should try something more complicated like a sinusoid or a random signal generated with the random command.

INLAB REPORT:

State which system is non-linear, and which system is time-varying. Submit plots of input/output signal pairs that support your conclusions. Indicate on the plots why they support your conclusions.

Stock Market Example

For this section download stockrates.mat. For help on loading Matlab files click here.

Load stockrates.mat into Matlab. This file contains a vector, called rate, of daily stock market exchange rates for a publicly traded stock.

Apply filters Equation 4 and Equation 5 from the "Stock Market Example" section of the background exercises to smooth the stock values. When you apply the filter of Equation 4 you will need to initialize the value of avgvalue(yesterday)avgvalue(yesterday). Use an initial value of 0. Similarly, in Equation 5, set the initial values of the "value" vector to 0 (for the days prior to the start of data collection). Use the subplot command to plot the original stock values, the result of filtering with Equation 4, and the result of filtering with Equation 5.

INLAB REPORT:

Submit your plots of the original and filtered exchange-rates. Discuss the advantages and disadvantages of the two filters. Can you suggest a better method for initializing the filter outputs?

Footnotes

  1. A more general behavioral view of systems is anything that imposes constraints on a set of signals.

Content actions

Download module as:

Add module to:

My Favorites (?)

'My Favorites' is a special kind of lens which you can use to bookmark modules and collections. 'My Favorites' can only be seen by you, and collections saved in 'My Favorites' can remember the last module you were on. You need an account to use 'My Favorites'.

| A lens I own (?)

Definition of a lens

Lenses

A lens is a custom view of the content in the repository. You can think of it as a fancy kind of list that will let you see content through the eyes of organizations and people you trust.

What is in a lens?

Lens makers point to materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

Who can create a lens?

Any individual member, a community, or a respected organization.

What are tags? tag icon

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

| External bookmarks