Sample Rate Conversion

Objectives

  1. Learn about compression and expansion operations on discrete-time signals.
  2. Learn about downsampling and upsampling operations on discrete-time signals.
  3. Observe the effects of compression and expansion in the time and frequency domains.
  4. 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.

We summarize these formulas here.

Sampling at Fs=1T:

Y(F)=1Tk=X(FkT)(CT aliasing formula)Z(f)=1Tk=X(fkT)(CT sampling formula)

Downsampling at fs=1D:

Y(f)=1Dk=0D1X(fkD)(DT aliasing formula)Z(f)=1Dk=0D1X(fkD)(DT sampling formula)

Note the strong resemblance between these formulas. There are two main differences.

  1. 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 T [seconds] is replaced by the downsample interval D [samples].
  2. The second difference is implicit: X(F) is aperiodic whereas X(f) is periodic with period 1.

The formulas for reconstruction and upsampling are summarized here.

Reconstruction at Fs=1T:

Y(F)=X(FT)(scale frequency axis)Z(F)={X(FT),|F|12T0,12T<|F|.(LPF to remove images)

Upsampling at fs=1U:

Y(f)=X(fU)(scale frequency axis)Z(f)={X(fU),|f|12U0,12U<|f|12.(LPF to remove images)

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 U-fold expander followed by a low pass filter) in series cascade with a downsampling stage (consisting of a low pass filter followed by a D-fold compressor). The low pass filters of the upsampling and downsampling stages have been combined into a single low pass filter with frequency response H(f). The cutoff frequency of this filter is the minimum of 12U and 12D.

Sample rate conversion system

Observation 1: If the input x[n] to this system is sampled at a rate of Fs samples/second, then the output y[n] will have a sample rate of UDFs. By a suitable selection of U and D (which must positive integers), the sample rate may be changed by any rational factor (at least in theory).

Fs(input sample rate)UDFs(output sample rate)

Observation 2: Now suppose the input is x[n]=cos(2πf0n) where f0<min(12U,12D). After U-fold expansion, the frequency moves to f0/U. It survives the low pass filter and then maps to DUf0 after D-fold compression so the output signal is y[n]=cos(2πDUf0n).

f0(input frequency)DUf0(output frequency)

Observation 3: Notice that the scale factor DU for frequency mapping is the reciprocal of the scale factor UD for sample rate mapping. This is as it must be because the actual frequency of the signal at the input is F0=f0Fs Hz, and the actual frequency of the signal at the output is F0=(DUf0)(UDFs)=f0Fs Hz, which his the same frequency at input as at output.

 

Multistage Sample Rate Conversion

Design a system that converts a signal x[n] with sample rate Fx=11025 S/s to a signal y[n] with a sample rate of Fy=8000 S/s. Using the sample rate conversion system from above we have:

Fy=8000=UDFx=UD11025.

Solving for D/U we obtain

DU=110258000=441320=33772222225=1232347475.

Using U=320 and D=441 in a single sample rate conversion stage is challenging for several reasons. First the filtering operation must be performed at U=320 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 441 and 320 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.

  1. Spectrum of the signal input to that stage.
  2. Spectrum of the upsampled signal along with the magnitude response of the low pass filter.
  3. Spectrum of the signal at the output of the low pass filter.
  4. Spectrum of the aliased signal (aliasing formula = replication).
  5. Spectrum of the signal output from that stage (downsampling formula = frequency scaling).

Note: In each figure, the title shows the upsampling factor U, the downsampling factor D, the pass band and stop band edge frequencies fp and fs.

Note: In the example below, I assumed that the input signal had a triangular shaped spectrum.

Stage 1: U=2, D=1

Stage 1 sample rate conversion

Stage 2: U=2, D=3

Stage 2 sample rate conversion

Stage 3: U=4, D=3

Stage 3 sample rate conversion

Stage 4: U=4, D=7

Stage 4 sample rate conversion

Stage 5: U=5, D=7

Stage 5 sample rate conversion

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 fs=0.101562, but to avoid aliasing it should have been fs=12D=114=0.0714. 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 11025 S/s resulting an an audio signal sampled at 8000 S/s. The spectral plots are shown below in dB scaling.

Stage 1: U=2, D=1

Stage 1 sample rate conversion

Stage 2: U=2, D=3

Stage 2 sample rate conversion

Stage 3: U=4, D=3

Stage 3 sample rate conversion

Stage 4: U=4, D=7

Stage 4 sample rate conversion

Stage 5: U=5, D=7

Stage 5 sample rate conversion

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.

fs=min(1fmU,12D).

Consider a general sample rate conversion stage with U-fold expansion and D-fold compression. The U-fold expander maps the following critical frequencies:

fpfp=fpUfmfm=fmU11U(center frequency of first image)(1fm)fs=1fmU(lowest frequency in first image)fs=12D(lowest frequency in aliasing band)

The filter H(f) is designed to pass frequencies below fp and stop frequencies above fs, where fs is chosen to suppress either images or aliasing. The maximum frequency at the output of the filter is either fm or fs, whichever is smaller,

fm=min(fmU,12D).

Finally, after D-fold compression the output pass and maximum frequencies are given by:

fp=Dfp=DUfp,fm=Dfm=min(DUfm,12).

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 fp=3800/11025=0.3447 cycles/sample. The maximum frequency at the input is half the sample rate, so fm=0.5 cycles/sample.

Next consider the first stage with parameters U=2,D=1. First map the critical frequencies corresponding to U=2 fold expansion.

fp=0.3447fp=fpU=0.1723fm=0.5fm=fmU=0.2511U=0.5(center frequency of first image)(1fm)=0.5fs=1fmU=0.25(lowest frequency in first image)fs=12D=0.5(lowest frequency in aliasing band)

We can see that the filter H(f) 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

fp=0.1723,fm=0.25.

Finally, after D=1 fold compression, the critical frequencies at the output of this stage are the same

fp=0.1723,fm=0.25.

Now we are ready to apply these principles to the subsequent stages.

 

Assignment

  1. Draw a block diagram of the five stage sample rate conversion system that converts from Fx=11025 S/s to Fy=8000 S/s.
  2. Label the block diagram to indicate the sample rate at the output of each block in the system diagram.
  3. Suppose the input signal contains a signal at normalized frequency f0=1000 Hz. Label the block digram to indicate the frequency of this signal at the output of each block in the system diagram.
  4. Write a Matlab function that performs one stage of sample rate conversion (SRC). The signature of the function should be:

where x is the input signal, fp is the pass band edge frequency for the input signal, fmax is the maximum frequency in the input signal, U and D are the upsampling and downsampling factors, Fs is the input sample rate, and y is the output signal. Note that fp,fm,Fs are all input and output variables. The output frequencies should be scaled D/U by the input frequencies and the output sample rate Fs should be scaled U/D 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.

  1. Call your function five times to perform the five stage sample rate conversion on this audio file.
  2. Turn in your plots of the signal spectra for each stage.
  3. Turn in a table showing the calculation of the critical frequencies fp,fm and fs for each stage.
  4. Include a spectrogram plot of the input signal and the final output signal.
  5. Turn in your code.