Learn about compression and expansion operations on discrete-time signals.
Learn about downsampling and upsampling operations on discrete-time signals.
Observe the effects of compression and expansion in the time and frequency domains.
Gain some experience designing filters and applying them to signals.
Mathematical Background
In class we have derived formulas for sampling and reconstruction and downsampling and upsampling. These derivations and visualizations are available in these slides. (See also these slides.) Here are slide summaries (math and diagrams) for the four operations.
Note the strong resemblance between these formulas. There are two main differences.
The first difference is explicit: the summation limits in CT sampling formulas are infinite, the summation limits in DT downsampling are finite, and the sample interval [seconds] is replaced by the downsample interval [samples].
The second difference is implicit: is aperiodic whereas is periodic with period 1.
The formulas for reconstruction and upsampling are summarized here.
Reconstruction at :
Upsampling at :
Note the strong resemblance between these formulas. The main difference is the periodic nature of the discrete-time spectra.
Sample Rate Conversion
A sample rate conversion system is shown below. It consists of an upsampling stage (consisting of a -fold expander followed by a low pass filter) in series cascade with a downsampling stage (consisting of a low pass filter followed by a -fold compressor). The low pass filters of the upsampling and downsampling stages have been combined into a single low pass filter with frequency response . The cutoff frequency of this filter is the minimum of and .
Observation 1: If the input to this system is sampled at a rate of samples/second, then the output will have a sample rate of . By a suitable selection of and (which must positive integers), the sample rate may be changed by any rational factor (at least in theory).
Observation 2: Now suppose the input is where . After -fold expansion, the frequency moves to . It survives the low pass filter and then maps to after -fold compression so the output signal is .
Observation 3: Notice that the scale factor for frequency mapping is the reciprocal of the scale factor for sample rate mapping. This is as it must be because the actual frequency of the signal at the input is Hz, and the actual frequency of the signal at the output is Hz, which his the same frequency at input as at output.
Multistage Sample Rate Conversion
Design a system that converts a signal with sample rate S/s to a signal with a sample rate of S/s. Using the sample rate conversion system from above we have:
Solving for we obtain
Using and in a single sample rate conversion stage is challenging for several reasons. First the filtering operation must be performed at times the input sample rate. That's a massive computational load. Furthermore, the filter design specification has an impossibly tight specification which would require an extremely long filter. Attempting to change the sample rate using a single stage results in a very complex problem. The numbers and may be factored into products of small primes suggesting that the sample rate may be converted using a series of five stages with rather low complexity. The assignment is to implement these five sample rate conversion stages. For each stage, use the low pass filter with the trapazoidally shaped magnitude response that we used in CA2.
Illustration
The figures below illustrate the signal spectrum for each of the five stages. In each figure, there are five subplots as follows.
Spectrum of the signal input to that stage.
Spectrum of the upsampled signal along with the magnitude response of the low pass filter.
Spectrum of the signal at the output of the low pass filter.
Spectrum of the aliased signal (aliasing formula = replication).
Spectrum of the signal output from that stage (downsampling formula = frequency scaling).
Note: In each figure, the title shows the upsampling factor , the downsampling factor , the pass band and stop band edge frequencies and .
Note: In the example below, I assumed that the input signal had a triangular shaped spectrum.
Stage 1: U=2, D=1
Stage 2: U=2, D=3
Stage 3: U=4, D=3
Stage 4: U=4, D=7
Stage 5: U=5, D=7
Notice the small amount of aliasing present in the final stage. This occurs because the low pass filter had a stop band edge frequency of , but to avoid aliasing it should have been . This would be a small change to make. Aliasing was avoided in all prior stages.
I performed five stages of sample rate conversion on an audio signal sampled at S/s resulting an an audio signal sampled at S/s. The spectral plots are shown below in dB scaling.
Stage 1: U=2, D=1
Stage 2: U=2, D=3
Stage 3: U=4, D=3
Stage 4: U=4, D=7
Stage 5: U=5, D=7
Designing Filters
The tricky part of sample rate conversion is designing the filters. Let's figure this out.
There are three frequencies that we have to keep track of in each stage of sample rate conversion. These are as follows.
the pass band edge frequency in the input signal for that stage. Frequencies in the band must be protected from aliasing and should be free attenuation free.
is the maximum frequency in the input signal for that stage. Frequencies in the band can be attenuated. These are "don't care" frequencies. We have to keep track of because we want to avoid aliasing, and if aliasing is going to occur, then it will happen due to energy in the signal at frequencies up to .
is the stop band frequency of the low pass filter . This frequency will be chosen either to remove images resulting from -fold expansion in which case , or it will be chosen to suppress aliasing before -fold compression in which case . In general, we will let
Consider a general sample rate conversion stage with -fold expansion and -fold compression. The -fold expander maps the following critical frequencies:
The filter is designed to pass frequencies below and stop frequencies above , where is chosen to suppress either images or aliasing. The maximum frequency at the output of the filter is either or , whichever is smaller,
Finally, after -fold compression the output pass and maximum frequencies are given by:
Let's apply these ideas to our problem. First we have to make some design decisions. Note that the final sample rate is 8000 S/s and the highest frequency that can be represented at 8000 S/s is half the sample rate or 4000 Hz. We have to provide a transition band for filtering and I'm willing to allow some attenuation of signals above 3800 Hz. I'm going to design the processing to preserve all frequencies below 3800 Hz as alias free and attenuation free. This will be the passband edge frequency throughout all the processing stages. At the input, the normalized version of 3800 Hz is cycles/sample. The maximum frequency at the input is half the sample rate, so cycles/sample.
Next consider the first stage with parameters . First map the critical frequencies corresponding to fold expansion.
We can see that the filter should have a passbands edge frequency of 0.1723 cycles/sample and a stop band edge frequency of 0.25 cycles/sample. The filter is designed to reject images.
The critical frequencies in the filter output are
Finally, after fold compression, the critical frequencies at the output of this stage are the same
Now we are ready to apply these principles to the subsequent stages.
Assignment
Draw a block diagram of the five stage sample rate conversion system that converts from S/s to S/s.
Label the block diagram to indicate the sample rate at the output of each block in the system diagram.
Suppose the input signal contains a signal at normalized frequency Hz. Label the block digram to indicate the frequency of this signal at the output of each block in the system diagram.
Write a Matlab function that performs one stage of sample rate conversion (SRC). The signature of the function should be:
xxxxxxxxxx
[y,fp,fm,Fs] = src(x,fp,fm,U,D,Fs)
where is the input signal, is the pass band edge frequency for the input signal, is the maximum frequency in the input signal, and are the upsampling and downsampling factors, is the input sample rate, and is the output signal. Note that are all input and output variables. The output frequencies should be scaled by the input frequencies and the output sample rate should be scaled by the input sample rate.
Your function should design and do all the processing for the sample rate conversion for that one stage.
Your function should make plots like those shown above.
Call your function five times to perform the five stage sample rate conversion on this audio file.
Turn in your plots of the signal spectra for each stage.
Turn in a table showing the calculation of the critical frequencies and for each stage.
Include a spectrogram plot of the input signal and the final output signal.