DSP Lab 3RT
DSP Lab 3RT
DSP Lab 3RT
1
expected to generate results for these tasks, and compile them into a single
electronic document (using Open Office, for example).
Your hand-in solutions can be submitted either in print form or electronically.
1. Filter out narrow-band interference: Create a corrupted signal by
adding a sinusoid with frequency ω0 = π /4:
yc = y + a0*sin(pi/4*(1:length(y))’);
where a0 is some scale factor. Since the sampling frequency 8192 Hz
corresponds to ω = 2π , the above sinusoid with angular frequency
ω0 = π /4 corresponds to a 1024 Hz interference component. You can
listen to the sample:
soundsc(yc,8192)
Use a filter design tool to find the impulse response impresp of a
bandstop filter for nulling this interference. The filtered output signal can
be calculated using
ycf = conv(yc,impresp);
which you can also listen to using the soundsc command. Note that while
this eliminates the interfering tone, it also nulls the signal in the stop band
of the filter.
The signals ycf and yc above are not the same size — what’s going on?
Hand in: Plots of a short sequence of sound data before and after the
filtering process.
2. Filter out 200 Hz interference: Create a signal corrupted by 200 Hz
interference, and make a highpass filter to remove it. This turns out to be a
very long FIR filter, or a fairly short IIR filter. You may wish to explore
both options. However, the IIR filter does not have linear phase.
Note: using a FIR filter to remove 50 Hz interference is even harder (try
it!). The reason 200 Hz was chosen in this experiment is because 50 Hz is
too low for our ears to hear (or for the soundcard to play?).
Hand in: A plot of the frequency response magnitude and phase for the
2
filter (or filters) used.
3. Downsampling: The sound clip is sampled at 8192 samples per second.
To reduce the sampling rate by a factor of 2 (to give a 4096 Hz sample),
you need to filter out all content below 4096/2 = 2048 Hz and then discard
every second sample. This cutoff frequency corresponds to
ω = π /2 in the angular frequency domain.
Use a filter design tool to find the impulse response impresp of a lowpass
filter with the required cutoff of ω = π /2. The filtered output signal can
be found using
y lp = conv(y,impresp);
and the resulting decimated signal is
yd2 = y lp(1:2:end);
The signal yd2 is now effectively sampled at 4096 Hz. You can compare
the sound of the properly downsampled version of the signal to aliased
version:
soundsc(yd2,4096) versus soundsc(y(1:2:end), 4096)
Applying the same lowpass filter as before to the downsampled data using
y lp = conv(yd2,impresp);
eliminates all frequencies below 1024 Hz (because the actual cutoff
frequency of the filter depends on the sampling rate!), so we can decimate
again by a factor of two without aliasing:
yd4 = y lp(1:2:end);
This signal is effectively sampled at 2048 Hz. You can again compare the
sound of good and bad downsampling:
soundsc(yd4, 2048) versus soundsc(y(1:4:end), 2048).
Hand in: Plots of the frequency response magnitude and phase of the
appropriate lowpass filter.
4. Upsampling: The sound clip is sampled at 8192 Hz. To convert it to a
16384 Hz signal which can be played using
3
soundsc(xxx,16384)
it needs to be upsampled by a factor of 2. Create the expanded signal yexp
by inserting zeros into the signal between the samples
yexp = zeros(2*length(y),1); yexp(1:2:end) = y;
and lowpass filter it with an appropriate impulse response impresp to
eliminate the replicas:
yu2 = conv(yexp,impresp);
You can listen to the upsampled signal yu2 (while it has more samples it
contains no more information than the original 8192 Hz sample), and you
can hear the effect of the replicas by listening to the intermediate
expanded signal yexp.
Hand in: Plots of a short sequence of signal sample values both before
and after upsampling.
5. Hardware implementation: (optional) Implement a simple filter on a
microprocessor like the STM32F. In the simplest instance you could
configure an ADC to raise an interrupt when a new input sample is
available. The ISR would then take this new value along with a ring buffer
of previous stored inputs, calculate the convolution result for the current
time instant by weighting the samples with the impulse response values,
and write the result to a DAC.