ELET 3760

Digital Signal Processing

Lab #1

Using MATLAB to Create and Sample Signals

Objective:

Understand how MATLAB can be used to generate and sample continuous-time signals.

Introduction:

MATLAB is a powerful tool when it comes to analyzing signals and systems. This lab will discuss the generation of continuous-time signals, the generation of discrete-time signals and the sampling of continuous time signals at, below, and above the Nyquist rate. You will then be asked to complete an exercise illustrating these various concepts.

Discussion:

Most signals in a DSP model are discrete-time signals. However, it is common that the discrete-time signal is a sampled version of a continuous-time signal. The following MATLAB m-file illustrates the generation of a continuous-time sinusoidal signal that is the sum of two separate sinusoids. S1 is a 240 Hz sinusoid and S2 is a 360 Hz sinusoid, which are summed to create Xa. Xa is plotted along with its components S1 and S2. Note that the time step of 100 ms could easily be made smaller, say 1 ms, to more closely approximate a continuous waveform.

t = 0:100E-6:15E-3;

S1 = sin(480*pi*t);

S2 = 3*sin(720*pi*t);

Xa = S1 + S2;

plot(t,S1,'*');

hold on; plot(t,s2,'o');

hold on; plot(t,Xa);

hold off;

xlabel('time');

ylabel('amplitude');

title('Continuous Time Example');

MATLAB m-file for Continuous-Time Example

Figure 1: Continuous-Time Signal

Now let’s consider a sampled version of Xa. There are at least two ways to accomplish this in MATLAB. The first is to create an m-file that generates a discrete version of Xa given the sampling rate. The second is to create a simulink model that generates a sampled version of Xa. Both methods are illustrated below.

Assume a sampling rate of 5 kHz, which is much greater than the Nyquist rate of 720 Hz. Then x(n) = Xa(nT) where T = 1/5000 is the discrete version of the Xa. The following m-file illustrates how x(n) can be generated.

Fs = 5000; F1 = 240; F2 = 360; n = 0:1:100;

xn1 = sin(2*pi*F1/Fs*n);

xn2 = 3*sin(2*pi*F2/Fs*n);

xn = xn1 + xn2;

plot (n,xn);

hold on;

stem (n,xn);

xlabel('n');

ylabel('amplitude');

title('Discrete Time Example');

hold off;

Figure 2: Discrete Version of Xa shown in Figure 1

Understand that the only real difference in the way MATLAB calculates Xa and x(n) is in the size of the time-step. For example the following m-file will generate identical output to that shown in Figure 2.

t=0:200E-6:20E-3;

s1 = sin(480*pi*t);

s2 = 3*sin(720*pi*t);

Xa = s1 + s2;

plot(t,Xa);

hold on; stem(t,Xa);

hold off;

xlabel('time');

ylabel('amplitude');

title('Continuous Time Example');

The point being that whether a MATLAB waveform is considered continuous or discrete is very much in the way we choose to look at it, not in the way it is calculated by MATLAB.

Perhaps a better conceptual understanding is illustrated via a simulink model.

Two continuous sine waves(one of amplitude 1 and frequency 240 Hz and the other of amplitude 3 and frequency 360 Hz) are added together and then sampled at a 5 kHz via a zero-order hold. The results displayed on a scope or saved to an output file are very much the same as what is displayed in Figure 2. Figure 3 gives an example of the output from the given simulink model. Remember that the zero-order hold, samples and holds the given value until the next sample is taken, yielding the stair-step output in Figure 3.

Figure 3: Zero-order Hold Sampled System

Lab Requirements:

1.  Develop a MATLAB m-file that displays the following continuous waveform. Use a time step of 1 ms for this activity.

Xa(t) = 3Cos(600pt) + 2Cos(1800pt)

Include a listing of the m-file, and appropriately labeled output. Your plot should show each component of Xa(t) as well as the composite function.

2.  Develop a MATLAB m-file that displays a discrete version of the waveform given in Lab Requirement 1. Use a sampling frequency of 3.6 kHz. Display the discrete waveform and explain how you generated the waveform. The number of samples displayed should correspond to the same interval of time used for the plot in Lab Requirement 1.

3.  Develop a simulink model that accomplishes the same task as Lab Requirement 2. Use a zero-order hold(ZOH) to sample the continuous system at 3.6 kHz and display the stair-step output from the ZOH.

4.  Answer the following questions about the analog system in Lab Requirement 1.

  1. What is the Nyquist rate for the given signal?
  1. What is the Folding frequency if the sampling frequency is 3.6 kHz?
  1. Explain in detail what would happen if the given signal was sampled at a 1.2 kHz rate. Does aliasing occur? Include in your explanation what a reconstructed analog signal would look like if an ideal D/A converter were used. Give an analytical expression that shows what the reconstructed waveform would look like. Display this waveform on a neatly labeled plot.

5.  Include any other interesting observations you have made during this laboratory experience.