For the simulation of the narrowband interferer, please use a chirp signal from 1000 Hz to 1100 Hz. In improvesnr.m, replace the line
n=0.25*randn(1, time/Ts );with
t = Ts : Ts : time; f0 = 1000; chirpBW = 100; n = cos(2*pi*f0*t + pi*(chirpBW/time)*(t.^2));By starting at t=Ts and ending at t=time, we ensure that signal n would have the same number of samples as signal x.
In part (c), please design the second-order IIR notch filter by manually placing poles and zeros, and manually determining the gain. Explain how you made these choices. More information is below.
Here's how to connect the poles p0 and p1, zeros z0 and z1, and gain C of the transfer function with the feedback coefficients a1 and a2 and feedforward coefficients b0, b1 and b2:
-1 -1 -1 -2 (1 - z0 z )(1 - z1 z ) 1 - (z0 + z1) z + z0 z1 z H(z) = C ------------------------ = C ------------------------------ -1 -1 -1 -2 (1 - p0 z )(1 - p1 z ) 1 - (p0 + p1) z + p0 p1 zSo, using the notation of lecture slide 6-15 on biquads,
b0 = C b1 = -C (z0 + z1) b2 = C z0 z1 a1 = p0 + p1 a2 = - p0 p1Please note that the Matlab
filter
and
freqz
commands represent an infinite impulse
response filter using
a1 = -(p0 + p1) a2 = p0 p1Here's the code for a notch filter at notch frequency of pi/4 rad/sample from Lecture 6:
zeroAngle = pi/4; z0 = exp(j*zeroAngle); z1 = exp(-j*zeroAngle); numer = [1 -(z0+z1) z0*z1]; r = 0.9; poleAngle = pi/4; p0 = r * exp(j*poleAngle); p1 = r * exp(-j*poleAngle); denom = [1 -(p0+p1) p0*p1]; %%% Normalize the DC response to 1 in linear units %%% by setting H(z) evaluated at z = 1 to be 1 C = (denom * [1 1 1]') / (numer * [1 1 1]'); freqz(C*numer, denom);You'll need to connect continuous-time notch frequency fnotch and the sampling rate fs to the discrete-time frequency wnotch. Then, set
zeroAngle = wnotch; poleAngle = wnotch;
Notes on the notch filter for this problem from fall 2019.
A QAM receiver must track the carrier frequency and carrier phase to recover the transmitted messages. This problem asks you to explore the degradation in the received messages if the carrier frequency has been perfectly tracked in the receiver but the carrier phase tracking has a slight error in it.
In this problem, there are two baseband message signals m1(t) and m2(t). Please use different baseband message signals.
The second message signal should have about the same average power as the first message signal. To compute the average power, one can compute the instantaneous power by squaring the absolute value of each amplitude and then computing the average of the instantaneous power calculations. The Matlab code would be
averagePower = sum(abs(signal) .^ 2) / length(signal);
To create the second message signal, you could take the first message signal and change a parameter value of the ramp component or the sinusoidal component.
It simplifies the solution if you use the same linear phase lowpass FIR filter for the two demodulating filters in the receiver. The demodulating filters are designed to give a passband frequency of 500 Hz and a stopband frequency of 1000 Hz.
With phase error, energy in transmitted message signal #1 will leak into received message signal #2, and vice-versa, which is known as cross-interference. Let's do the math. Assuming that there is a phase error of theta at the receiver, we can derive the upper output s1(t) using the trigonometric identities in JSK on page 404.
s1(t) = LPF{ m1(t) cos(2 pi fc t) cos(2 pi fc t + theta) - m2(t) sin(2 pi fc t) cos(2 pi fc t + theta) } s1(t) = LPF{ 1/2 m1(t) ( cos(theta) + cos(4 pi fc t + theta ) ) - 1/2 m2(t) ( sin(-theta) + sin(4 pi fc t + theta ) ) } s1(t) = 1/2 cos(theta) m1(t) + 1/2 sin(theta) m2(t)When theta = 0, i.e. when there is no phase error,
s1(t) = 1/2 m1(t)which recovers the in-phase component up to a scalar gain.
The lowpass filter in the equations above was assumed to be ideal with no delay. In practice, the input signal experiences delay through the filter by the time it reaches the output. The code in AM.m uses an FIR filter of order 100, which has 101 coefficients and a group delay of 50 samples.
Implement the lowpass filter by using the convolution command
conv
.
Then, discard the first 50 samples and the last 50 samples from
the result to remove the leading and trailing effects due to
convolving two finite length signals.
We had seen these effects during the convolution demo.
In the receiver in Figure 5.10, the term sin(2 pi fc t) should be -sin(2 pi fc t) to match the negation of the lower path in the transmitter.
Connections to lecture. We discussed sinusoidal modulation and demodulation on lecture slides 1-6 through 1-9 for two-sided signals. Consider a two-sided baseband signal x1(t) with bandwidth w1 modulated by cos(wc t) which gives y(t) = x1(t) cos(wc t) as a two-sided signal. The spectrum Y(w) is bandpass over w in [wc - w1, wc + w1] and [-wc - w1, -wc + w1] and has bandwidth 2 w1 as shown on lecture slide 1-6. For demodulation back to baseband, we'll multiply y(t) by cos(wc t) and apply a lowpass filter. In modulating y(t) by cos(wc t), we’ll get a combination of a baseband component for w in [-w1, w1] and a bandpass component for w in [2wc - w1, 2wc + w1] and [-2wc - w1, -2wc + w1] as shown on lecture slide 1-7.
Applying a lowpass filter with a passband frequency of w1 will extract the baseband component and attenuate/reduce the bandpass component. Here are several lowpass filtering approaches. Lecture slide 1-7 applies an ideal IIR filter whose frequency response is a rectangular pulse for w in [-w1, w1] and whose impulse response is a two-sided sinc pulse. Although not implementable, it is useful as a starting point. A practical demodulating filter could be an FIR or IIR filter with a stopband frequency between 1.1 w1 and 2wc - w1.
Message bandwidth. The message bandwidth is not explicitly given. By using plotspec(m1, Ts) in Matlab, the magnitude of the frequency content of message #1 using contains one large DC component plus a smaller peak at 20 Hz plus slowly decaying magnitude values that follow a 1/f shape. The carrier frequency is 1000 Hz. The demodulating filter is a linear phase FIR filter designed using the Parks-McCellan algorithm (firpm command) using a passband frequency of 500 Hz and stopband frequency of 1000 Hz. From the demodulating filter specifications, one can infer the message bandwidth to be 500 Hz, and the stopband frequency is twice the message bandwidth.
In the pull-down menu in filterDesigner (formerly fdatool) for choosing a filter structure, SOS means second-order sections, i.e. a cascade of biquads.
IIR filter design algorithms return poles, zeros, and gain(s). The design algorithms are based on closed-form formulas and are incredibly accurate, including determining the minimum filter order. Even so, the IIR filter structure chosen for the implementation of the filter can alter the pole locations, which can sometimes lead to a bounded-input bounded-output unstable filter or otherwise cause the filter implementation to miss the original specifications.
Please check the filter design and implementation to make sure that it meets specifications.
Once you've designed your filter in filterDesigner (formerly fdatool) in Matlab, you can export the filter coefficients to use in Matlab commands. In the Design Filter View of filterDesigner, the upper left window has the text "Current Filter Information". Below this text, you can right click on the text "Structure" and pick either cascade of biquads or single section.
Cascade of biquads. If you leave the filter as a cascade of biquads, then for each biquad, expand the factored form of the transfer function and report the feedforward coefficients (b0, b1 and b2) and the feedback coefficients (a1 and a2). Here's how to connect the poles, zeros and gain with the coefficients using the transfer function using the notation on lecture slide 6-15 for the unfactored form (on the right):
-1 -1 -1 -2 (1 - z0 z )(1 - z1 z ) 1 - (z0 + z1) z + z0 z1 z H(z) = C ------------------------ = C ------------------------------ -1 -1 -1 -2 (1 - p0 z )(1 - p1 z ) 1 - (p0 + p1) z + p0 p1 zSo,
b0 = C b1 = -C (z0 + z1) b2 = C z0 z1 a1 = p0 + p1 a2 = - p0 p1Please note that the Matlab
filter
and
freqz
commands represent an infinite impulse
response filter using
a1 = -(p0 + p1) a2 = p0 p1
One could also use a cascade of first-order sections. In each first-order section, the pole and zero would be complex-valued, which increases the computational complexity for addition and multiplication over real-valued coefficients and data. Multiplication of two complex numbers takes 4 real multiplications and 2 real additions, and the addition of two complex numbers of 2 real additions. That is, a cascade of two first-order sections with complex-valued coefficients would have four times the computational complexity and twice the memory usage vs. a second-order section (biquad) with real-valued coefficients and data.
Single section. Under the "Edit" menu, you can convert an IIR filter design to a single section by choosing "Convert to Single Section". Then, under the File menu, you can click "Export". The "Export" command will by default export the filter coefficients to the Matlab workspace. The numerator coefficients will be in the Num vector, and the denominator coefficients will be in the Den vector. Then, in Matlab, you can type Num to see the numerator coefficients, and type Den to see the denominator coefficients. Moreover, you can apply the filter to a signal in Matlab using
outputSignal = filter(Num, Den, inputSignal);When converting an IIR filter design from a cascade of biquads to a single section, the IIR filter might become BIBO unstable: IIR Filter Structure. For example, if you convert the Butterworth filter design from part (a) into a single section, many of the poles will move outside of the unit circle. You can see this by choosing "Pole/Zero Plot" under the "Analysis" menu. One pole located on or outside of the unit circle is enough to have BIBO instability.
(c) The total number of instruction cycles for an IIR filter on a particular processor would depend on the IIR filter structure. Appendix N Computational Complexity of Implementing a Tapped Delay Line on the C6700 DSP explains the number of instruction cycles on the TMS320C6748 processor in lab. For an FIR filter of N coefficients, it takes N+28 instruction cycles. An IIR filter of order M has M feedback coefficients and M+1 feedforward coefficients, for a total of 2M+1 coefficients. Hence, an IIR filter would take 2M+29 instruction cycles, and a IIR biquad filter (second-order section) would take 33 instruction cycles. The top of the handout has a link to a video presentation for the handout.