This is an old revision of the document!
| Chapter | Modulo | Course Topic | MATLAB Topic | created |
|---|---|---|---|---|
| Ch 1 | MT380.UY1 | Signals | ||
| MT380.UY1.1.1 | Types of Signals | |||
| MT380.UY1.2.1 | Signal Transformations | Array Operations, plot , Graph Annotation , Figures | yes | |
| MT380.UY1.3.1 | Waveform Properties | |||
| MT380.UY1.4.1 | Nonperiodic Waveforms | |||
| MT380.UY1.5.1 | Signal Power and Energy | sum | yes | |
| Ch 2 | MT380.UY2 | LTI Systems | ||
| MT380.UY2.1.1 | LTI Systems | |||
| MT380.UY2.2.1 | Impulse Response | |||
| MT380.UY2.3.0 | Convolution Aid | yes | ||
| MT380.UY2.3.1 | Convolution with function files | Function Files, For-loop | yes | |
| MT380.UY2.3.2 | Convolution with arrays | For-loop, Zeros | yes | |
| MT380.UY2.4.1 | Graphical Convolution | |||
| MT380.UY2.5.1 | Convolution Properties | Review | yes | |
| MT380.UY2.6.1 | Causality & BIBO Stability | |||
| MT380.UY2.7.1 | LTI Sinusoidal Response | |||
| MT380.UY2.8.0 | Imp.Resp. of 2nd Ord LCCDEs Aid | yes | ||
| MT380.UY2.8.1 | Imp.Resp. of 2nd Ord LCCDEs | Roots | yes | |
| MT380.UY2.9.1 | Car Suspension | Review | yes | |
| Ch 3 | MT380.UY3 | Laplace Transform | ||
| MT380.UY3.0 | Laplace Transform Aid | yes | ||
| MT380.UY3.1.1 | Def. of the (Uni) L-Transform | |||
| MT380.UY3.2.1 | Poles and Zeros | Mesh | yes | |
| MT380.UY3.3.1 | Properties of the L-Transform | |||
| MT380.UY3.4.1 | Circuit Analysis Example | |||
| MT380.UY3.5.1 | Partial Fraction Expansion | |||
| MT380.UY3.6.1 | Transfer Function | |||
| MT380.UY3.7.1 | Poles and System Stability | |||
| MT380.UY3.8.1 | Invertible Systems | |||
| Ch 4 | MT380.UY4 | App. of the L-Transform | ||
| MT380.UY4.1.1 | s-Domain Circuit Elem. Models | |||
| MT380.UY4.2.1 | s-Domain Circuit Analysis | |||
| MT380.UY4.5.1 | Op-Amp Circuits | Review | yes | |
| Ch 5 | MT380.UY5 | Fourier Analysis Techniques | ||
| MT380.UY5.4.1 | Fourier Series Coefficients | For-loop | yes | |
| MT380.UY5.7.1 | Fourier Transform | |||
| MT380.UY5.8.1 | Fourier Transform Properties | |||
| MT380.UY5.9.1 | Parseval's Thrm for Fourier T. | |||
| MT380.UY5.10.1 | Additional Attributes | |||
| MT380.UY5.11.1 | Phasor v. Laplace v. Fourier | |||
| MT380.UY5.12.1 | Circuit Analysis with Fourier | Review | yes | |
| MT380.UY5.13.1 | The Importance of Phase Info. | |||
| Ch 6 | MT380.UY6 | Apps of the Fourier Trans. | ||
| MT380.UY6.1.1 | Signal Filtering | |||
| MT380.UY6.3.1 | Active Filters | |||
| MT380.UY6.8.1 | Butterworth Filters | Review | yes | |
| MT380.UY6.12.1 | Sampling Theorem | fopen, fscanf, fclose, Interpolate, sound | yes | |
| Ch 7 | MT380.UY7 | Discrete-Time Signals and Syst | ||
| MT380.UY7.1.1 | Discrete Notation and Property | |||
| MT380.UY7.2.1 | D-Time Signal Functions | rat | yes | |
| MT380.UY7.3.1 | D-Time LTI Systems | |||
| MT380.UY7.4.1 | Properties of D-T LTI Sys. | |||
| MT380.UY7.5.1 | D-Time Convolution | |||
| MT380.UY7.6.1 | Z-Transform | |||
| MT380.UY7.7.1 | Properties of Z-Transform | |||
| MT380.UY7.8.1 | Inverse Z-Transform | |||
| MT380.UY7.9.1 | Solving Diff Eq. with Int. Cond. | |||
| MT380.UY7.10.1 | System Transfer Function | |||
| MT380.UY7.11.1 | BIBO Stability | |||
| MT380.UY7.12.1 | System Frequency Response | |||
| MT380.UY7.13.1 | D-Time Fourier Series | Review | yes | |
| MT380.UY7.14.1 | D-Time Fourier Transform | |||
| MT380.UY7.15.1 | Discrete Fourier Transform | |||
| MT380.UY7.16.1 | Fast Fourier Transform |
Signal Transformations
Objective: Help student gain a visual understanding of several basic
signal transformations.
Commands: array operations, plot, labels, figure.
Background Information: In MATLAB and other programming environments
continuous signals cannot be represented by vectors or arrays, since
these are inherently discrete. However, it is possible to approximate a
continuous signal by taking samples of the signal, where the time
interval between samples is small enough that the signal exhibits only
small changes in amplitude between adjacent samples. For example,
consider the signal x(t) = exp(-0.5*t)*u(t). This signal "turns on"
at t = 0, and then exponentially decays towards 0 with an initial slope
of -0.5 (at t = 0). Given this initial slope, the time interval between
samples should be significantly less than 0.5. A nice choice might be
100 times smaller, although this will clearly depend on the application.
Exercise: Consider the signal x(t) = sin(2*pi/4*t).
This is a continuous signal, "turning on" at time t = negative infinity and
continuing towards t = positive infinity. Clearly we can't plot this signal
for all time in Matlab. In this exercise, you should limit
your time axis from -6 s to 6 s, and use a sampling period (interval
between time points) of 0.01 s.
First, set up a vector t holding your time values, and create the signal
x(t) = sin(2*pi/4*t). This can be done with the following code:
t_start = -6;
t_end = 6;
t_interval = 0.01;
t = t_start:t_interval:t_end;
x = sin(2*pi/4*t);
Then do the following:
(1) Plot the signal x(t)
(2) Create the following transformations of the signal x(t), and
plot each of them in the same figure but different plots using
the subplot command:
(a) y1(t) = x(2*t)
(b) y2(t) = x(0.5*t)
(c) y3(t) = x(t-1)
(d) y4(t) = x(-t)
(e) y5(t) = x(4-2*t)
Give each plot a title to distinguish the original signal from its
transformations.
(3) Answer the following questions:
(a) Explain the behavior you observe in 2(a) and 2(b).
(b) Explain in words how the signal x(t) is transformed in 2(e).
Signal Power and Energy
Objective: Help students gain a better understanding of the relation
between frequency, total energy, and average power for sinusoidal signals
of limited time duration.
Commands: sum
Exercise: For this exercise use the function x(t) = cos(2*pi*f*t)(u(t) - u(t-6)); with t
representing time, and f representing frequency in hz.
a) Create four signals with different frequencies, f = [1 10 50 1000].
ex, y1 = cos(2*pi*f(1)*t)(u(t) - u(t-6))
b) Use the sum command to calculate the total energy and average power of
each signal.
c) Create two plots that graph frequency vs total energy
and frequency vs average power
d) What impact does frequency have on the total energy and average power
of a sinusoidal signal?
A document to help gain an intuition behind convolution. convolutionguide.docx
The file below work together to create a MATLAB gui that simulates convolution
Please do not modify the following two files.
convolutiongui.m
convolutiongui.fig
You can modify the following three function files to change your signals x(t) and h(t)
x_t_gui.m This file modifies the signal x(t)
h_t_gui.m This file modifies the signal h(t)
time_parameters_gui.m This file returns the time parameters used for x(t) and h(t)
MT380_UY2_3_1_Convolution Function File
Objective: Create a function file in matlab that can approximate
continuous time convolution.
Commands: function file.
Background Information: The convolution formula is
y(t) = integral (x(tau)*h(t-tau)dtau, 0, t). To implement convolution
using MATLAB we will have to approximate it since t cannot be continuous.
Exercise: You will create three different function files. One function
file will contain a function for x(t), another for h(t), and the last
function file will be your convolution function file. The parameters for
the function files of x(t) and h(t) should only have one parameter for
time (s).
The headers for the two function files should look something like the ones below.
function [x] = x_t(t)
function [h] = h_t(t)
They take in one value representing one instance in time, and return only
value; the function evaluated at one value of t.
The convolution function file header should look like the one below.
function [y] = convolution(t_array, dtau)
This function will take in an entire array representing time, and dtau
which represents the time step between values of tau and call the
functions x_t and h_t in order to perform the convolution integral.
Once you have created the three function files put the following function
in both function files x_t and h_t.
if t < 0 || t > 4
x = 0;
else
x = 1;
end
Convolve them together using the convolution function file that you created
by creating an appropriate time array and an appropriate value of dtau.
graph it and verify that the graph matches what you expect x_t*h_t to be.
MT380.UY2.3.2 Convolution of two arrays
Objective: Understand the mechanics of convolution in order to create a
function that will approximate continuous time convolution.
Commands: for-loop, zeros, functions
Exercise: Create a function that can approximate continuous convolution.
The functions parameters should consist of two arrays representing signals,
x(t) and h(t), and a time_interval that represents the time increments in an array that
represents time. ex: t = 0:time_interval:5. Your time interval will serve
as dtau in y(t) = integral (x(tau)*h(t-tau)dtau, -inf, +inf).
The function declaration should look like
function [y] = convolution(x, h, time_interval).
with x, and h representing two signals.
a) To test your function let x(t) = h(t) = u(t)-u(t-4) and convolve the
two signals together.
b) Plot the computed signal.
Some helpful information is below.
Convolution is defined as
y(t) = integral (x(tau)*h(t-tau)dtau, -inf, +inf)
Working with causal signals, convolution can be rewritten as
y(t) = integral (x(tau)*h(t-tau)dtau, 0, t) with 0 being the lower bound
of integration and t being the upper bound of integration.
In order to do Convolution in MATLAB the formula has to change since
MATLAB can only approximate a continuous signal. Time is lost and is
replaced by indexing.
For example consider the code:
t= 0:.1:1-.1; t(s) = [0 .1 .2 .3 .4 .5 .6 .7 .8 .9];
x = sin(pi/0.2*t); x = [0 1 0 1 0 1 0 1 0 1]
sin(pi/o.2*t(2)) = x(2)
To visually demonstrate this consider the two arrays below.
let t = [0 1 2 3 ] then t(1) represents 0s
let x(t) = [1 2 3 4] then x(1) = 1 at t = 0s
let h(t) = [3 2 1 0] then h(4) = 0 at t = 3s
let y(t) = [3 8 14 20 11 4 0] then y(1) = 3 at t = 0s
Because indexing in MATLAB begins with 1 instead of 0, the convolution
formula needs to be adapted for proper indexing.
y(index) = integral (x(tau)*h(index-tau)dtau, 1, index)
tau cannot start at 0 since x(0) does not exist in MATLAB. This means
that tau must start at 1. However, that creates a problem since both
index and tau starts at 1. Thus h( (index = 1) - (tau =1 ) ) = h(0) is out of
range. To fix this, the equation needs to be adapted even further.
y(index) = integral (x(tau)*h(index+1 - tau)dtau, 1, index)
Below is an example of this equation. Assume that dtau = 1.
at index < 1 y(index <1) = integral (x(tau)*h(index+1<2-tau)dtau, 1, index)
|
|
x[tau] | 1 2 3 4
h[index-tau] 1 2 3 |
-------------------------------------------------------------
tau -4 -3 -2 -1 0 1 2 3 4 5 6
During this period, the two signals do not come in contact with
each other, thus y[index <1] must be zero. This is the property of a causal
signal convolved with a causal system.
at index = 1 y(1) = integral (x(tau)*h(2-tau)dtau, 1, index)
|
|
x[tau] | 1 2 3 4
h[index-tau] 1 2 | 3
-------------------------------------------------------------
tau -3 -2 -1 0 1 2 3 4 5 6
At index = 1, and with tau ranging from 1 to index, the two signals only
have non-zero values at tau = 1. This indicates that y(1) = 1*3.
at index = 2 y(2) = integral (x(tau)*h(3-tau)dtau, 1, index)
|
|
x[tau] | 1 2 3 4
h[t-tau] 1 | 2 3
-------------------------------------------------------------
tau -3 -2 -1 0 1 2 3 4 5 6
At index = 2, and with tau ranging from 1 to index, the two signals both have non-zero
values when tau = 1, and 2. This indicates that y(2) = 1*2 + 3*2. This is
because y(t) depends on the integration (summation in discrete time) of
the two signals being multiplied together.
at index = 3 y(3) = integral (x(tau)*h(4-tau)dtau, 1, index)
|
|
x[tau] | 1 2 3 4
h[t-tau] | 1 2 3
-------------------------------------------------------------
tau -4 -3 -2 -1 0 1 2 3 4 5 6
At index = 3, and with tau ranging from 1 to index, the two signals both have non-zero
values when tau = 1,2, and 3. This indicates that y(3) = 1*1 + 2*2 + 3*3.
at index = 4 y(4) = integral (x(tau)*h(5-tau)dtau, 1, index)
|
|
x[tau] | 1 2 3 4
h[t-tau] | 1 2 3
-------------------------------------------------------------
tau -4 -3 -2 -1 0 1 2 3 4 5 6
At index = 4, and with tau ranging from 1 to index, the two signals both have non-zero
values when tau = 2,3 and 4. This indicates that y(4) = 2*1 + 3*2 + 4*3.
at index = 5 y(5) = integral (x(tau)*h(6-tau)dtau, 1, index)
|
|
x[tau] | 1 2 3 4
h[t-tau] | 1 2 3
-------------------------------------------------------------
tau -4 -3 -2 -1 0 1 2 3 4 5 6
At index = 5, and with tau ranging from 1 to index, the two signals both have non-zero
values when tau = 3 and 4. This indicates that y(5) = 3*1 + 2*4.
at index = 6 y(6) = integral (x(tau)*h(7-tau)dtau, 1, index)
|
|
x[tau ] | 1 2 3 4
h[t-tau] | 1 2 3
-------------------------------------------------------------
tau -4 -3 -2 -1 0 1 2 3 4 5 6
At index = 6, and with tau ranging from 1 to index, the two signals both have non-zero
values when tau = 4. This indicates that y(6) = 4*1.
at index > 6 y(index>6) = integral (x(tau)*h(index+1>7-tau)dtau, 1, index)
|
|
x[tau] | 1 2 3 4
h[t-tau] | 1 2 3
------------------------------------------------------------------
tau -4 -3 -2 -1 0 1 2 3 4 5 6 7
At index > 6, and with tau ranging from 1 to index, the two signals only have non-zero
values. This indicates that y(>6) = 0.
Because of the time reversal, we need to ensure that MATLAB doesn't try
to index a part of an array that is out of bounds. There are many ways of
doing this. The easiest for most people will be an if-statement that
checks to see if the index is out of bounds. Another way of doing this is
by zero padding. Zero padding is when you concatenate an array with zeros
to ensure that MATLAB doesn't index out of bounds.
UY2_5_1 Convolution Properties
Objective: Gain a visual understanding of the following convolution
properties: Commutative, Associative, Distributive, Causal*Causal,
Time-shift, Width, and Area.
Commands: subplot, figure.
Exercise: Use the following functions in this exercise:
x1(t) = 2u(t) - 2u(t-2)
x2(t) = 2r(t) -4r(t-1) + 2r(t-2)
x3(t) = 2u(t) - 3u(t-1) + 3u(t-t) -2u(t-4)
x4(t) = r(t)u(t)u(-(t-1))
x5(t) = u(t) - u(t-4)
Create two figures. In one figure plot each signal in its own subplot.
In the other figure, plot the results to parts a to e.
The '*' symbol denotes convolution.
a) Compute y1(t) = x2(t)*x3(t) and y2(t) = x3(t)*x2(t)
You should have four subplots in this first figure.
What is the difference between y1(t) and y2(t)? If there
is no difference, state that.
b) Compute y3(t) = [x2(t)*x3(t)]*x4(t) and y4(t) = x2(t)*[x3(t)*x4(t)]
What is the difference between y3(t) and y4(t)?
If there is no difference, state that.
c) Compute y5(t) = x3(t)*[x1(t) + x2(t)] and y6(t) = x3(t)*x1(t) + x3(t)*x2(t)
What is the difference between y5(t) and y6(t)?
If there is no difference, state that.
d) Compute y7(t) = x2(t-1)*x3(t-2). Compare y7(t) with the answer in part a.
What is the delay in y(t), and how does it relate to the delay in the two
signals x2(t-1) and x3(t-2)?
e) Compute y8(t) = x1(t)*x5(t). How does the area of y8(t) relate to the
areas of x1(t) and x5(t).
Use the previous plots created to answer the following questions.
What is the relation between the width of the convolved signal (y1(t)-y8(t)) and the
width of the signals that were convolved (x1(t)-x5(t)).
Signals x1(t)-x5(t) are all causal signals. If you convolved any two or
more signals together, the output signal must also be (causal /
non-causal)
Differential Equations-Euler's Method differential_equations_eulersmethod.docx
UY2_8_1 Impulse Response of 2nd Order LCCDEs
Objectives: Become familiar with Euler's method for solving 1st order
differential equations; the effect of overdamped, critically damped, and
underdamped systems to a sinusoidal frequency; and approximating
derivations in matlab.
Commands: review roots.
Exercise: Use the figure below for this problem. The value of the
capacitor is 2e-3F, the value of the inductor is 1H, and the resistor
will take on four different values R = [1,10,20,40].
The input signal is
Vs = | cos(2*pi*f*t) for 0 <= t < 1(s)
| 0 for 1(s) <= t <= 3(s)
and f represents the frequency in Hz, and is 22 Hz.
This frequency is close to the resonate frequency of
the system.
Vout is Vo.
You will create an impulse response of the system for every value of R.
When you plot, create four different figures for each different
resistor value. in each figure, create subplots: 1 for h1(t), 1 for
h2(t), 1 for hc(t), 1 for h(t), and 1 for h(t)*Vs (Convolution)
When you are creating the impulse responses you will have to create a
time array for each of them. t = 0:time_interval:time_end. For the
time_interval use 2/1000, and for time_end use 5*tau. The behavior of
the impulse response can be captured in a time duration of 5*tau. The
value of tau will change depending on the value of R. Remember, tau is
the real part of the root of the characteristic equation.
Begin by creating your 2nd order differential equation based on the image
provided.
a) Split the second order differential equation into to coupled
first-order equations. Use Euler's method to approximate h1(t) and
h2(t). Compare them to the analytical solutions provided in the book by
plotting them. Remember to do this for each value of R
- analytic approach. Used for comparison
- h1A = exp(p(1).*t);
- h2A = exp(p(2).*t);
b) Convolve your h1(t) and h2(t) to get hc(t). Compare it to the
analytical solution provided in the book by plotting them.
- analytical solution to hc
- hcA = (1/(p(1)-p(2)))*(exp(p(1).*tc)-exp(p(2).*tc));
- tc is the time array for hcA
c) Approximate the derivative of hc to get h(t). Compare it to the
analytical solution provided in the book by plotting them.
- analytical solution
- hA = (1/(p(1)-p(2)))*(p(1)*exp(p(1).*tc)-p(2)*exp(p(2).*tc));
d) Convolve your four h(t)s, one for each resistor value, with the input
signal and plot them.
e) Questions:
1) How close of an approximation is Euler's method, and for what value
of R is the approximation the worse and why?
2) Using the graph that shows Vout, look at the time after the input signal
stops (t = 1s). What is the relationship between the value of R and
Vout after (t = 1s). Why does it behave like this?
For further exploration, change the resonate frequency of the input
signal and see what happens.
For help with this assignment see the document Differential Equations-Euler's Method
Euler's method 2nd order Objective: Use Euler's method for solving 2nd order differential equations to approximate the displacement of a car as it drives over a pot hole. Exercise: You are driving a car at 10m/s when you run over a pot hole that is 0.2 meters deep and 0.5 meters wide. The car weighs 1800 kg (450 kg per wheel), and the suspension system has a spring constant of 10^5 N/m and a Viscous damper of 5*10^3 Ns/m. a) Use Euler's method to plot the path of the car starting from when it first hits the pothole. Hint- you will need the cart to start at level ground. b) compare the results from part a with the analytical solution. Look at table 2-3 on page 71 and the example of driving over a pothole on page 72 to compute the analytical solution. Plot it on the same graph used in part a. c) Compare and contrast the two plots
S Domain Graph
Objective: Learn how to plot the magnitude and phase of a Laplace transform
in order to gain a visual understanding of the s-domain
Functions: review mesh-grid and mesh
Exercise: Apply the Laplace transform to the function
exp(-0.9*t)*cos(2*pi*2*t). Evaluate the Laplace transform at different
values of s. s can be split into its real part and its imaginary part;
s = sigma + j*omega. Let the values of sigma range from -3:.02:3; and the
values of omega range from 2*pi*(-3:.02:3;). s represents all possible
combinations of sigma and j*omega. In this case s should be 301x301
matrix since both arrays of sigma and omega contain 301 elements.
a) Evaluate the Laplace transform at every value of s.
b) calculate the magnitude and phase of the Laplace transform at every
value of s.
c) use mesh grid to plot the magnitude and phase calculated in part b.
The x-axis should be sigma, the y-axis omega, and z-axis the magnitude or
phase. In the graph represent the y-axis in (hz) and not omega. The
command should look like this. mesh(sigma,omega/2/pi,Xs_magnitude);
d) By looking at the graph, determine where the poles and zeros are. Are
they where they should be?
Op-amp circuit
Objective: Graph the s-domain transfer function of an op-amp circuit to
gain a visual understanding. Also, create a bode plot of the s-domain transfer function
with sigma = 0 to introduce students to the Fourier domain.
Functions to learn: none
Exercise: Using the figure associated with the problem, solve for the
op-amp's transfer function H(s).
The values are shown below
L = 10e-2; % inductor
C = 10e-6; % capacitor
R1 = 10;
R2 = 2000;
a)Evaluate H(s) at all possible combinations of s with
s = sigma + j*omega, sigma = -20:1:20, and omega = 2*pi*(-1000:10:1000).
b) graph the magnitude of H(s) with the frequency axis in units of Hz.
c) where are the zeros ?
d) Evaluate H(s) with sigma = 0, and omega = 2*pi*(-1000:10:1000). Graph
the magnitude in terms of decibels, dB = 20log(Vo/Vin); and with the frequency
axis in units of Hz. Also, graph the phase in terms of degrees on the
same plot.
e) In part d you plotted the bode plot of the Op-Amp. This is to
introduce you into the Fourier domain
UY5_4_1_ComputationOfFourierSeriesCoefficients Objective: Use MATLAB to calculate the Fourier series coefficients of a continuous signal. Functions: review for-loops Exercise: Assume that the figure associated with this problem is continuous over all time. a)Use MATLAB to find the Fourier series coefficients for 100 harmonic signals, or n = 100 according to equation 5.26a that's located in the book. b)Use the Fourier series coefficients found in part a to calculate the 100 harmonic signals which the original signal is composed of. c)Sum up all of the harmonic signals found in part b to get an approximate signal of the original signal. Plot the approximate and original signals on the same graph for one period. d)Plot the amplitude spectrum and phase spectrum of the signal. You do not need to show all 100 frequencies in this graph, but about 20. e)The approximate signal does not perfectly with the original signal. Why is this? Does increasing or decreasing the number of harmonics fix the strange offset? Hint. Gibbs phenomenon.
UY5_12_1_Circuit Analysis Fourier Transform
Objective: Use Fourier analysis to calculate the output to a system when
stimulated.
Exercise: This problem is based off of problem 5.61 that is in the book.
You will still need to do part a by hand. The book will direct you to the
needed figures.
a) Derive the impulse function for the circuit.
b) Create a function file that models the impulse function obtained in
part a.
c) Create another function file that models the input signal. Remember
that A = 5mA and T = 3.
d) Using the functions obtained in part b and c find and plot Vout. Hint
convolve the functions.
e) Take a moment to appreciate how much easier that problem became by using MATLAB
compared to if you had to convolve the two functions by hand.
UY6_3_1_Active Filters
Objective: model a second order butterworth filter using an approximated
impulse response in order to see its effectiveness in filtering signals
functions: review roots
Exercise: This exercise will be broken down into several parts
part 1) in this first part you will create a low pass filter based on a
second order butterworth filter. Create it in a function file that
takes in two parameters (corner frequency in Hz and time interval/step).
ex. functionName(fc , time_interval). The function file will return
the impulse response h(t) in an array. Make the time length of the
impulse response at least 10*tau; usually 5 tau is sufficient but
let's be extra precise.
a) look at table 6-3 on page 285 in your book. This will help you
find the coefficients for your transfer function. Look at example
6-10 in the book if you need more help. When designing this
transfer function, H(jw), make sure you have a dc gain of 1.
b) look at section 2-7.3 in your book to remember how to turn a
transfer function into a second order differential equation.
c) review section 2-8 to transform your second order differential
equation into an impulse response, h(t).
If done correctly, you only need to pass the function file fc and
the time_interval and the function file will return an array
representing h(t).
part 2) Now that you have constructed your filter it's time to test it.
a) create a low pass filter with an fc of 400 Hz using part 1 of
the assignment. Use an appropriate time interval. time_interval
<< tau. and time_interval << 1/largest(f), look at part b for
largest 4)
b) create three different signals of the form x = 5*cos(2*pi*f*t).
the three signals will have different frequencies: f1 = 100, f2
= 400, f3 = 4000 Hz. When creating these signals, use the same
time_interval in part a) but have the time array last for 1 s.
c) Convolve each signal with h(t) to simulate filtering.
y = x(t)*h(t), * denotes convolution.
d) plot h(t), and the three filtered signals.
part 3) You will now analyse the plots to verify that your filter is
working.
a) you designed your filter with an fc of 400 Hz and a dc gain of
1. Verify that the filtered signal with f1 = 100 Hz still has a max
amplitude of 5.
b) Now look at the filtered signal with f2 = 400 Hz. Since the
signal has the same frequency as the corner frequency what should
its amplitude approximately be?
d) Looking at the last signal with f3 = 4000 Hz ignore the first
part of the filtered signal that has an amplitude twice the value
that the rest of the signal has, remember that this is just an
approximation. f3 is ten times the frequency of f2, and you are
using a second order filter. How much smaller should the
amplitude of the signal with a freq(f3) be compared to the
signal(f2)?
UY6_12_1 Sampling Theorem With Noise
Objective: This exercise will expose students to the process of sampling
data, and the effects of aliasing.
Functions: fopen, fscan, fclose, interp, and sound.
Caution: The command 'sound' will clip at +/- 1V. Before playing any
array using the sound command, make sure that every value is within the
range. You should not have to worry about it in this lab, but it is good
to verify so that you develop the habit. You can easily verify the max
and min value in your workspace by specifying it to show those values, or
you can do it by inspection of the graphs that you will plot.
Exercise: For this exercise you will be given a file to read in. You will
take the file and read it in. This file contains an array of
data that represents sound. You will filter, sample, and filter
again to gain an idea on the effects of aliasing.
This problem is broken down into 7 parts to help simplify and
organize it. Some of the descriptions will be long, but read
them because they will help save you time.
Part 1) Get Data From the File
You will use the command fopen to read in the file
'PianoDataWithNoise.txt'. Everything in the file represents data used
in generating the sound; just open up the file in notepad to see its format.
The file is long and its length is 5512500 which
represents 5 seconds of data. i.e. 1102500 elements represents 1
second. When you read in the file, the format of the file is
exponential notation. After you read the file, make sure you
close it.
Reading the file will take MATLAB about 15 seconds, but it only
needs to read it in once. After you have the file's content
stored in a variable, comment it out so it doesn't read it every
time you run the program. The variable will remain in the
workspace unless you clear it.
Part 2) Creating the filter.
Before you sample a signal you always want to filter it with a
lowpass filter. In modulo MT380.UY6.8.1 you created a function
file that generates a second order filter. Create a filter with a
corner frequency of 500 Hz. Remember that the samples per second
is 1102500, and the time interval/step used for creating the
filter is 1/1102500.
Part 3) Filter Data
a) You will have two arrays of data. One array will not be
pre-filtered and the other array will be filtered.
Use the filter created in part 2 to filter the data obtained in
part 1, and store the data in another array.
b) Plot the non-pre-filtered data (NPFD) and the pre-filtered data (PFD) as a
function of time.
I have given you a function file called fft_plot. If you have not
downloaded it from the wiki page, download it now. This function
will plot the frequency magnitude spectrum. It takes in two
parameters: the array containing the data, and the number of
samples that represent a second. Ex fft_plot(NPFD, 1102500). Use
this function to plot the frequency magnitude of NPFD and PFD.
Magnify the plots so you can see the frequencies between 0 and
1500 Hz. Notice that each signal has a frequency at 1200 and 1500
Hz; However, the PFD frequency at 100 and 1500 Hz is much smaller
because of the filter. These frequencies represents possible
noise that can get into your system. Even though the noise shows
up in the PFD signal, it is negligibly small, and can be
ignored. Also, other than the noise, the other frequencies are
about 500 Hz or below.
Part 4) Sample Data
a) The data that you have been given represents a continuous signal.
In this part you will simulate sampling a continuous signal.
Sample the NPFD signal at 1050 samples/second, and sample the PFD
at 1050 sample/second and 500 samples/second. At this point you
should have three different data arrays.
1) a pre-filtered signal sampled at 1050 samples/s or Hz
2) a pre-filtered signal sampled at 500 samples/s or Hz
3) a non pre-filtered signal sampled at 1050 sample/s or Hz
b) These three signals will need to be modified in order to be
played using the sound command because the sound card can only
play data at specific frequencies, and they are
8000,11025, 22050, 44100, 48000, and 96000 Hz.
To do this, you will need to interpolate the signals using the
interp command. The signals sampled at 1050 Hz will need to be
interpolated to have 22050 samples/s and the signal sampled at
500 Hz will need to be interpolated to have 8000 samples/s.
Interpolating a signal does not change the frequencies.
c) After you have interpolated it, plot all three signals as a
function of time, and plot their frequency magnitude spectrum using
the fft_plot function file provided. Compare and contrasts these
plots to the plots created in part.
d) Questions
1) After sampling the NPFD at 1050, what frequencies did the
noise alias to?
2) Why are some of the aliased frequencies attenuated?
3) Why does the PFD signal sampled at 1050 Hz not suffer from
aliasing?
4) Why did the PFD signal sampled at 500 Hz become really
distorted?
Part 5) Create Filters for sampled data
For the signals sampled at 1050 Hz, create a filter will a cut
off frequency of 500 Hz. For the signal sampled at 500 Hz, create
a filter with a cut off frequency of 250 Hz using the filter
function file you created in modulo MT380.UY6.8.1.
Part 6) Filter the sampled data
a) Filter the sampled data with their corresponding filters.
b) Plot each signal as a function of time, and plot their frequency magnitude
using the fft_plot function file provided. Remember to pass in the
correct samples/s for each signal.
c) Questions
1) Why is it important to filter after sampling data?
2) If you have a Nyquist sampling rate of 1000 Hz, what should
the maximum corner frequency of the low pass filter be and why?
Part 7) Play the data
a) You now get to play your data using the sound command. Remember
to make sure that all values in any signal array is within
+/- 1.
b) Play all signals with there corresponding frequencies. The
signals sampled at 1050 Hz should be played at 22050 Hz, and the signal
sampled at 500 Hz should be played at 8000 Hz
c) Compare your results with the sound files provided on the wiki
page.
d) Questions
1) You should hear a low hum in the NPFD signal. It is most
apparent at the beginning of the sound file. Why is it
important to pre-filter before sampling.
2) You signal sampled at 500 Hz doesn't resemble the original
sound. Why is it important to sample at a frequency greater
than the Nyquist sampling rate?
This file was sampled at 1050 samples/sec, then filtered again with fc of 500 Hz.
You should be able to hear a low buz that is not in the original file
This file was first filtered with fc of 500 Hz, sampled at 1050 samples/sec, then filtered again with fc of 500 Hz.
This file should sound similar to the original just quieter due to filtering
This file was first filtered with fc of 500 Hz, sampled at 500 samples/sec, then filtered again with fc of 250 Hz.
This file shows the effects of aliasing.
MT380.UY7.2.1 Discrete Time Signal Functions
Objective: gain a visual understanding of the fundamental period.
Functions: rat
Exercise: Consider the causal signal x = cos(2*pi*f*t) with f = 5 Hz.
a) Calculate the period of the signal.
b) Write a function file that can calculate the fundamental
period of a sampled signal for any period (To) and sample rate
(Ts). This function must be able to indicate if a fundamental
period does not exist. For example, in my program, if the
fundamental period does not exist i return a 0. Hint: for
this function file, consider using the rat command.
c) You will sample signal x at the following three sample rates
(Ts):0.035, 0.25, 0.01, and .01/pi. Using the function file created
in part b, determine the fundamental period of signal x
sampled at the three different sample rates. For example, if
I were to sample signal x at a sample rate of 0.077 my fundamental
period would be 200 samples.
d) Sample the signal x at the indicated sample rates for the duration of 1
fundamental period. Continuing my example, my time duration would
be (No*Ts) or 15.4 seconds. You should have three sampled
signals of different time duration
e) Approximate three continuous time signals (x) by sampling at a
very high frequency and with a time duration equal to the fundamental
period of all three sampling rates.Continuing my example, I
would create a signal that approximates a continuous signal
that begins at t = 0s and ends at t = 15.4s.
f) Plot each sampled signal x with its corresponding continuous
approximated signal. See solution graphs for a visual
understanding. If the fundamental period does not exist, do
not plot the data points, just indicate it in the plot's
title.
g) Questions:
1) For each sampled signal, how many periods of the
continuous approximated signal fit within one fundamental
period of the sampled signal?
2) How do the numbers obtained in part 1 relate to the book
equation 7.21 (No = k*(To/Ts))
MT380_UY7_13_1_DiscreteTimeFourierSeries
Objective: Create a Program that simulates the Discrete-Time Fourier
Series of a sampled signal.
Commands: none
Exercise: The file, signal.txt, contains one period of a sampled periodic
signal.
a)Open the file, import the data, and plot the original signal.
b) Find the expansion coefficients of the given signal.
c) Plot the magnitude line spectrum and phase line spectrum of
the imported signal using the expansion coefficients
obtained in part b
d) Reconstruct the original signal using the expansion
coefficients and plot it.
e) Question: What is the highest frequency in the signal?