##ThinkDSP
This notebook contains solutions to exercises in Chapter 11: Modulation and sampling
Copyright 2015 Allen Downey
Exercise: As we have seen, if you sample a signal at too low a framerate, frequencies above the folding frequency get aliased. Once that happens, it is no longer possible to filter out these components, because they are indistinguishable from lower frequencies.
It is a good idea to filter out these frequencies before sampling; a low-pass filter used for this purpose is called an ``anti-aliasing filter''.
Returning to the drum solo example, apply a low-pass filter before sampling, then apply the low-pass filter again to remove the spectral copies introduced by sampling. The result should be identical to the filtered signal.
Solution: I'll load the drum solo again.
This signal is sampled at 44100 Hz. Here's what it sounds like.
And here's the spectrum:
I'll reduce the sampling rate by a factor of 3 (but you can change this to try other values):
Before sampling we apply an anti-aliasing filter to remove frequencies above the new folding frequency, which is framerate/2
:
Here's what it sounds like after filtering (still pretty good).
Here's the function that simulates the sampling process:
The result contains copies of the spectrum near 20 kHz; they are not very noticeable:
But they show up when we plot the spectrum:
We can get rid of the spectral copies by applying the anti-aliasing filter again:
We just lost half the energy in the spectrum, but we can scale the result to get it back:
Now the difference between the spectrum before and after sampling should be small.
After filtering and scaling, we can convert back to a wave:
And the difference between the interpolated wave and the filtered wave should be small.
Multiplying by impulses
makes 4 shifted copies of the original spectrum. One of them wraps around from the negative end of the spectrum to the positive, which is why there are 5 peaks in the spectrum off the sampled wave.