Upsampling/Downsampling and Discretetime Modulation
Objective
The objective of this lab is to deepen students understanding of principles of discretetime modulation, demodulation, upsampling and down sampling.
Upsampling and Downsampling

In this part of the lab, you will experiment with up and down
sampling by a factor of 3.

First, download the file
h.mat
and type
load
h
at the Matlab prompt. This will load a variable
h
into the Matlab workspace.
 Startup Simulink and build up and down sampling models.
 Recall that down sampling requires two processing blocks: (1) modulation with a periodic impulse train {..., 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, ...} and (2) removing the zero samples.
 An easy way to modulate by the {..., 1, 0, 0, 1, 0, 0, ...} sequence is to define the sequence in the Matlab workspace and then bring it into the model using a Signal From Workspace block. Here's some code to consider.
 The Signal Operations Block Library in the DSP Blockset Library contains a Downsample block which removes zero samples. It looks like this
 Upsampling consists of two operations: (1) inserting zeros and (2) lowpass filtering to remove images.
 This Signal Operations Block Library in the DSP Blockset Library contains an Upsample block which inserts zeros. It looks like this
 You already know about designing lowpass filters using the Matlab remez function.
 The following is an example Simulink model. The upper branch does down sampling and the lower branch does up sampling.

Note: In up and down sampling, be very careful to set the sample
rates in each block. When available, set the "Sample Time" in the filter
blocks to 1. Then the filters will "inherit" their sample times from
the previous block. Otherwise, you must set the sample times explicitly.
 In this model, a few Signal To Workspace blocks have been added to capture various signals.
 In the Simulation Parameters Dialog, set the Start time to 0 and the Stop time to N1 where N is the length of the input signal h . Also, in the Solver options category, set the Type to Fixedstep.
 Run the simulation.
 Compare the spectra and timedomain sequences of the three signals: h, hpd, hdown. Write an explanation of what you see. Do the two processing blocks used for the down sampling function as expected? Turn plots like the ones shown below with your write up.
 Below are the spectra and timedomain sequences (first few samples only) computed using the Simulink model above.
 Compare the spectra and timedomain sequences of the three signals: h, hpu, hup. Write an explanation of what you see. Do the two processing blocks used for up sampling function as expected? Turn plots like the ones shown below with your write up.
 Explain how you designed the lowpass filter for upsampling. What were the edges of the transition band? What was the gain of the filter?
 Below are the spectra and timedomain sequences (first few samples only) computed using the Simulink model above.
M=3;
% Factor for up and down sampling
N = length(h);
p = zeros(N,1); % Define a vector of all zeros
p(1:M:N)=1; % Set every third sample to one
As shown above, the upsampled timedomain sequence passes through
the samples of the original signals. This is achieved using a gain
of 3 in the low pass filter. You can see the gain of three in the
frequency domain. Note that the lowpass filter will cause a delay
in the upsampled signal reltive to the original signal. In the figure
above, the delay has been removed.
Discretetime Modulation and Demodulation
 Download the file y.wav . Any multimedia equiped computer with standard software packages should be able to play this audio file. Try it. Do you recognize what the woman is reading?
 You can read the wav data into Matlab by typing:
 The spectrum of y is as shown below.
 As you can see, y contains significant frequency content all the way out to 0.5 (discretetime frequency) which corresponds to 11025/2 Hz (continuoustime frequency) half the sample rate.
 Build a Simulink model to amplitude modulate y on a cosinusoidal carrier using a carrier frequency of 0.2 (discretetime frequency) and then perform synchronous demodulation and downsampling to restore the spectrum to its original shape.
 In order to avoid aliasing, y must be upsampled before modulating it.
 Recall that in discretetime, the constraint on the carrier frequency is
 Use an upsampling factor of 3.
 What is the highest frequency (between 0.5 and 0.5) after upsampling by 3?

What is the highest frequency (between 0.5 and 0.5) in the modulated
signal?
 Will upsampling by 3 avoid aliasing in the modulated signal?
 The two steps in synchronous demodulation are: (1) modulation (multiply) by the carrier and (2) lowpass filtering to remove the double frequency components. What is the highest frequency after the modulation step but before lowpass filtering? Does aliasing occur?
 What are the transition bands edges and the gain of the lowpass filter that you used for demodulation?
 Does the demodulated and downsampled signal sound the same as the original signal? By the way, if you want to write a signal yr out to a wav file in order to listen to it, type the following at the Matlab prompt.

Turn in your answers to the questions above and figures like the
ones below showing your model and the spectra. An example of what the
spectra look like at various points appears at the bottom of this page.
 A Simulink Model of the complete system may look like this.
 The spectra of several of the intermediate signals looks like this.
[y,fs,nbits]=wavread('y.wav');
This loads three variables into you Matlab workspace:
y
is the
audio data,
fs
is the sample rate (11025 in this case), and
nbits
is
the number of bits used to represent each sample in
y
.
where these frequencies are discretetime f requencies in units of rads.
If you would rather use units that are consistent with the way that
we generate our plots, then divide the inequality above by a factor of (2
pi) leading to the following constraint on the carrier frequency.
wavwrite(yr,fs,nbits,'yr.wav');