Exercises

ex-sp-ch07-01

Easy

Generate a signal x(t)=3cos⁑(2Ο€β‹…80 t)+sin⁑(2Ο€β‹…200 t)x(t) = 3\cos(2\pi \cdot 80\,t) + \sin(2\pi \cdot 200\,t) sampled at fs=1000f_s = 1000 Hz for 1 second. Compute the FFT, plot the magnitude spectrum for positive frequencies, and verify Parseval's theorem: βˆ‘βˆ£x[n]∣2=1Nβˆ‘βˆ£X[k]∣2\sum|x[n]|^2 = \frac{1}{N}\sum|X[k]|^2.

ex-sp-ch07-02

Easy

Construct the 16Γ—1616 \times 16 DFT matrix F16\mathbf{F}_{16} and verify: (a) F16x\mathbf{F}_{16}\mathbf{x} matches np.fft.fft(x) for a random vector, (b) 116F16\frac{1}{\sqrt{16}}\mathbf{F}_{16} is unitary.

ex-sp-ch07-03

Easy

Design a 5th-order Butterworth lowpass filter with cutoff 150 Hz for a signal sampled at 1000 Hz. Apply it to x(t)=sin⁑(2Ο€β‹…50 t)+0.5sin⁑(2Ο€β‹…300 t)x(t) = \sin(2\pi\cdot50\,t) + 0.5\sin(2\pi\cdot300\,t) and verify that the 300 Hz component is removed.

ex-sp-ch07-04

Easy

Apply a Hann window to a 256-sample sinusoid at 100 Hz (sampled at 1024 Hz) and compare the FFT with and without the window. Measure the sidelobe level in dB for both cases.

ex-sp-ch07-05

Easy

Resample a 1-second sinusoid at 50 Hz from fs=500f_s = 500 Hz to fs=800f_s = 800 Hz using both resample and resample_poly. Compute the maximum error between the two results.

ex-sp-ch07-06

Medium

Implement linear convolution via the FFT: zero-pad x[n]x[n] (length NN) and h[n]h[n] (length MM) to length β‰₯N+Mβˆ’1\ge N+M-1, multiply their FFTs, and take the inverse FFT. Verify the result matches np.convolve.

ex-sp-ch07-07

Medium

Design an equiripple bandpass FIR filter using scipy.signal.remez with passband [1000, 2000] Hz, transition bands of 200 Hz on each side, and sampling rate 8000 Hz. Use 101 taps. Plot the magnitude response and verify the passband ripple and stopband attenuation.

ex-sp-ch07-08

Medium

Compare the Welch PSD estimate with the periodogram for a signal containing three sinusoids (50, 120, 200 Hz) in white noise at SNR = 0 dB. Use segment lengths of 256, 512, and 1024 samples with 50% overlap. Which segment length gives the best trade-off between variance and resolution?

ex-sp-ch07-09

Medium

Implement a matched filter for a 13-chip Barker code [+1,+1,+1,+1,+1,βˆ’1,βˆ’1,+1,+1,βˆ’1,+1,βˆ’1,+1][+1, +1, +1, +1, +1, -1, -1, +1, +1, -1, +1, -1, +1]. Embed the code at a random position in a noise signal (SNR = βˆ’5-5 dB) and show that the matched filter detects the correct position.

ex-sp-ch07-10

Medium

Decompose a noisy signal using the DWT with the 'db4' wavelet at 5 levels. Apply soft thresholding with the universal threshold and reconstruct the denoised signal. Report the MSE improvement.

ex-sp-ch07-11

Medium

Compute the spectrogram of a signal composed of two chirps: one sweeping 100-400 Hz (0-1 s) and another sweeping 400-100 Hz (1-2 s). Use scipy.signal.spectrogram and experiment with different nperseg values (64, 256, 1024) to observe the time-frequency resolution trade-off.

ex-sp-ch07-12

Hard

Implement the overlap-add method for efficient convolution of a very long signal (N=106N = 10^6) with a short filter (M=128M = 128). Break the signal into blocks of length LL, zero-pad each block to L+Mβˆ’1L+M-1, convolve via FFT, and accumulate the overlapping tails. Verify the result matches fftconvolve and benchmark both approaches.

ex-sp-ch07-13

Hard

Design a Chebyshev Type I bandpass filter (order 6, 1 dB passband ripple) for the band [500, 1500] Hz at fs=8000f_s = 8000 Hz. Compare its magnitude response, group delay, and step response with an equivalent-order Butterworth bandpass filter.

ex-sp-ch07-14

Hard

Implement the 2D FFT of a 256Γ—256256 \times 256 grayscale image. Zero out all frequency components outside a circular region of radius RR in the frequency domain (ideal lowpass filter), then reconstruct with the inverse FFT. Show the effect for R=10,30,60,120R = 10, 30, 60, 120.

ex-sp-ch07-15

Hard

Compare wavelet denoising with Wiener filtering for a piecewise-smooth signal in white Gaussian noise at SNR = 5 dB. Use the 'sym8' wavelet with soft thresholding and a Wiener filter estimated from the noisy signal's PSD. Report the MSE for both methods.

ex-sp-ch07-16

Hard

Implement CWT-based time-frequency analysis of a signal with three components: a 50 Hz sinusoid (0-1 s), a 150 Hz sinusoid (0.5-1.5 s), and a transient Gaussian pulse at t=0.75t = 0.75 s. Compare the CWT scalogram (Morlet wavelet) with the STFT spectrogram. Discuss which method better resolves the transient.

ex-sp-ch07-17

Challenge

Implement an OFDM transmitter and receiver in Python:

  1. Generate random QPSK symbols for 64 subcarriers
  2. Apply a 64-point IFFT to create the time-domain OFDM symbol
  3. Add a cyclic prefix of length 16
  4. Pass through a multipath channel h=[1,0,0.5,0,0,0.2]h = [1, 0, 0.5, 0, 0, 0.2]
  5. Add AWGN at SNR = 20 dB
  6. Remove the cyclic prefix and apply the 64-point FFT
  7. Equalize by dividing by the channel frequency response
  8. Compute the bit error rate

Verify that the cyclic prefix eliminates inter-symbol interference.

ex-sp-ch07-18

Challenge

Implement a complete spectral analysis pipeline for a non-stationary signal:

  1. Generate a 10-second signal with three regimes:
    • 0-3 s: two sinusoids at 100 Hz and 250 Hz
    • 3-7 s: linear chirp from 100 Hz to 400 Hz
    • 7-10 s: white noise filtered through a bandpass [150, 350] Hz
  2. Compute the spectrogram, CWT scalogram, and Welch PSD for each regime
  3. Implement an automatic regime detector that identifies transitions based on spectral feature changes
  4. Compare the time-frequency resolution of the spectrogram vs CWT

Discuss which representation is best for each regime type.