help expand use the
lookforcommand to find a Matlab command for a given task.
(a) The problem concerns a five-tap (or five-coefficient) discrete-time averaging filter.
The five-tap discrete-time averaging filter, with input x[n] and output y[n], is described by
y[n] = 1/5 x[n] + 1/5 x[n-1] + 1/5 x[n-2] + 1/5 x[n-3] + 1/5 x[n-4]Five taps means five terms. To compute the current output y[n], we average the current input value x[n] and the previous four input values.
(c) The discrete-time analogy to integration is summation. For the discrete-time integrator, the relationship between the input x[n] and output y[n] for n ≥ 0 becomes
n ---| \ y[n] = | x[m] / ---| m = 0The above equation is not terribly efficient as the amount of memory to store previous input values grows without bound as n increases. A computationally efficient version of the equation is given below:
(b) The Matlab command
plotspec is defined by the Matlab
file plotspec.m that comes with the JSK book.
plotspec function takes the time-domain signal and the
sampling time as arguments, and plots the time-domain waveform and
the magnitude of its Fourier transform.
The Fourier transform give the average frequency content in the
time-domain signal, and does not indicate at what times the frequencies occur.
plotspec command will accept the vector of
amplitude values in the time domain and a sampling period Ts.
It will plot the signal in the continuous-time domain (top plot)
and in the frequency domain (bottom plot).
The time-domain plot assumes that the time-domain signal starts
at t = 0.
The magnitude response will be plotted over the frequencies
-1/2 fs to 1/2 fs, where
fs is the sampling rate.
Matlab has its own
plotspec function that takes
three arguments and plots a time-frequency signal representation
called a spectrogram.
This is a very different function from the
in the JSK textbook.
To access the functions provided by the Matlab files that accompany Software Receiver Design textbook, the directory containing the Matlab files would need to placed first on the Matlab search path. Please see the Matlab hints for more information.
%%% Generate chirp signal with frequency %%% increasing from f0 to (f0 + fstep time) over time seconds time = 10; f0 = 20; fstep = 420; fs = 44100; Ts = 1 / fs; %%% Add code here to define chirp signal y = cos( angle(t) ) sound(y, fs)
(d) Please create a new plot window to plot the spectrogram by using the Matlab command
figure;The spectrogram will be hard to follow if it appears in the plot window used by the JSK plotspec command. Here is an example use of the spectrogram function:
spectrogram(y, hamming(256), 128, 256, fs, 'yaxis');The fourth argument indicates the number of points in the fast Fourier transform, and this can be any positive integer. It does not have to be a power of two. The third argument is how much shift is applied to the the previous block of samples to find the current block. The second argument indicates any weighting of the data in block of samples before the fast Fourier transform is applied.
A Hamming window has finite duration, and is even symmetric about the midpoint with endpoints having value 0.08. The amplitude values of the causal Hamming window of length N samples is defined as
w[n] = 0.54 - 0.46 cos(2 pi n / (N - 1))for n = 0, 1, ..., N-1. One can plot a 256-point Hamming window in Matlab by evaluating the command
(a) Mean squared error (MSE) is a measure of signal quality between signals x[n] and y[n]:
M-1 2 MSE = Sum (x[n] - y[n]) n=0where M is the number of samples to be compared.
In computing the mean squared error between the message signal
at the transmitter (
basebandInput) and the message
signal decoded at the receiver (
one also has to take into account the delay in the transmitter
The only delay is in the lowpass filter used in the receiver.
The group delay through a finite impulse response filter whose N coefficients are even symmetric about the midpoint of the filter's impulse response is (N-1)/2. We'll derive this formula in lecture 5 slides. In order for the group delay to be an integer, N must be odd.
We can force the filter length to be odd by replacing
FIRlength = floor(fs/f1);with
%%% Use an odd-length FIR filter FIRlength = floor(fs/f1); if 2*floor(FIRlength/2) == FIRlength FIRlength = FIRlength - 1; endTo implement the group delay GD, we'll need to remove the first GD samples from
basebandOutputand the last GD samples from
(b) You're asked to use a squaring block followed by a lowpass filter to realize downconversion. An advantage of using the squaring block is that the receiver would not need to know the carrier frequency to perform downconversion. The baseband bandwidth in the receiver will be larger than that of downconversion by sinusoidal amplitude demodulation. You'll need to modify the following Matlab code accordingly:
FIRlength = floor(fs/f1);You will also need to adjust the gain in the receiver.
Please read the comments in upconvertGong.m.
More information about using a squaring block in downconversion is available on slides 5-8 and 5-9 by Prof. Stephen Tretter.