Lab1-Intro to Matlab with DSP

Electrical Engineering Technology
Department of Applied Engineering & Technology
California University of Pennsylvania
EET 460: Digital Signal Processing
Lab No.1
Name : ---------------------------------------------------------- : Date: ---------------------------
Name : ---------------------------------------------------------- : Date: ---------------------------
Name : ---------------------------------------------------------- : Date: ---------------------------
Deliverables:
- Completed lab
- Clearly and concisely answered questions
- Professionally organized results.
- Submit your results in to the designated Dropbox on D2L
Introduction to Matlab ® and Simulink ® – Basic DSP Introduction
Objective: The objective of this exercise is to gain familiarity with some basic features of Matlab as it
pertains to signal processing and discretization.
Student Learning Outcomes:
Students will demonstrate the ability to:
- Use advanced software to solve technical problems
- Use analytical skills to analyze results
- Understand and explain basic signal sampling principles.
Introduction
This lab presents 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. At the conclusion if the
lab, students are to complete an exercise illustrating these various concepts.
Discussion and Explanation:
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. Signal x1 is a
200 Hz sinusoid and signal x2 is a 300 Hz sinusoid, which are summed to create the sum signal, x. Signal
x is plotted along with its components x1 and x2. The time step chosen is 100s. This time step could
easily be made smaller, say 1 s, to more closely approximate a continuous waveform.
Procedure:
1- Create a folder in your network drive to be used for this course. Make sure to save files in this
designated folder and name files appropriately.
2- Open Matlab and set the path in Matlab to this folder as follows:
-Files>>Set Path>>Add folder. Navigate to the folder and then click save. You should see that path
added to the top of the search path menu. From now on, avoide using file names that conflict twith
Matlab preassigned names.
Continuous-Time Signal
Create a new scrip: Files>>New Script. Then save the file as LAB1CT.m in the folder you created above.
Note, CT stands for Continuous –Time. Type the code blow and insert the plot result below the code.
< Insert plot here>
Sampled Signal
Consider a sampled version of x. 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 x given the sampling rate. The second is to
create a Simulink model that generates a sampled version of x. Both methods are illustrated below.
Assume a sampling rate of 5 kHz, which is much greater than the Nyquist rate of 900 Hz. Then x(n) =
X(nT) where T = 1/5000 is the discrete version of the X. The following m-file illustrates how x(n) can be
generated.
Type the Code below and insert the resulting sampled signal. Save the code as Lab1ST.m
< Insert the resulting plot here>
Generation of Sampled Signal using Simulink
In the Matlab command window, type Simulink
Create a new model: Files>>New Model
Using the library browser in Simulink, build the model shown
Scope
x1
Zero-Order
Hold
results
To Workspace
x2
-Change the default frequencies for the two sine wave generators to be 200 and 450 HZ.
- Change the sample time in the ZOH to be 1/fs = 1/5000Hz = 0.0002;
- save the model as Lab1STmodel
- Right click the configuration parameters in the Simulink mode as shown.
- double click on the “Workspace” block, rename it to Results and change the “Save format” from
“Struct” to “Array.”
- Save the file
- In Matlab Command window, type clear all to clear all the variables.
in Simulink, run the program. Then open the Scope, and right click in it to auto scale. Then enlarge the
view
- Notice the sampled – time signal. (STILL analog)
Lab Requirements:
1. Develop a MATLAB m-file that displays the following continuous waveform. Use a time step of 1
s for this part
X(t) = 3sin(500t) + 2sin(2000t)
Include a listing of the m-file, and appropriately labeled output. Your plot should show each
component of x(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 4 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 zeroorder hold(ZOH) to sample the continuous system at 4kHz and display the stair-step output from
the ZOH.
4. Answer the following questions about the analog system in Lab Requirement 1.
a. What are the Nyquist frequency and the Nyquist rate for the given signal?
b. What is the Folding frequency if the sampling frequency is 4 kHz?
c. Explain in detail what would happen if the given signal was sampled at a 1.6 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.