Frequency Modulation (FM) Demodulation Lab

Objectives

  1. Learn about FM and FM demodulation.
  2. Learn about instantaneous frequency.
  3. Practice designing filters and applying them to signals.
  4. Practice using multi-rate processing (downsampling).

 

Introduction to FM and FM Demodulation

Let x(t) be the real-valued message signal which could represent speech or music. Frequency modulation (FM) encodes the message into the instantaneous frequency of the modulated/transmitted (TX) signal yTX(t) which has the form

φ(t)=2πFct+2πktx(τ)dτ,yTX(t)=cos(φ(t))=cos(2πFct+2πktx(τ)dτ),

where Fc is the carrier frequency and k is a constant. The function φ(t) is the phase function. The instantaneous frequency Fi(t) of any sinusoidal wave is the derivative of its phase function

Fi(t)=12πdφ(t)dt=Fc+kx(t).

We see that for FM, the instantaneous frequency is a constant (the carrier frequency Fc) plus a scaled version of the message x(t).

A radio antenna will pick up all the FM signals that are transmitted in the area. The received signal (RX) has the form

yRX(t)=mAmcos(2πFc,mt+2πktxm(τ)dτ+θm).

Each received FM signal will have a different amplitude Am, phase θm, carrier frequency Fc,m, and message xm(t). In the United States, carrier frequencies start at 88.1 MHz and end at 107.9 MHz with 200 kHz spacing, which provides 100 unique FM stations. FM carrier frequencies are 88.1, 88.3, 88.5, 88.7, 88.9, 89.1, ..., 107.5, 107.7, 107.9 MHz. Notice that all valid carrier frequencies end in odd-tenths. This page shows the FM spectrum on the USU campus (at the moment I recorded it). Because each FM broadcaster in any given area uses a different carrier frequency, the signal you want to listen to can be isolated from the others using a bandpass selection filter. The isolated signal of interest has the form

Acos(2πFct+2πktx(τ)dτ+θ),

where the subscripts have been dropped. This signal is mixed with cos and sin at the carrier frequency Fc to bring the signal to baseband. This is an application of the frequency-shifting property of the DTFT. If we treat the cos and sin branches of the receiver as the real and imaginary parts of a complex-valued signal, that signal takes the form

y(t)=Aexp(j2πktx(τ)dτ+jθ).

This is called the "complex-baseband" form or "complex envelope" because the signal is expressed as a complex exponential signal and the carrier frequency has been removed, i.e. it is centered at zero frequency also known as baseband, zero frequency, or DC. We can use the complex-baseband form to discuss demodulation which is the process of recovering x(t).

How can x(t) be extracted from inside the complex-exponential and the integral? Let's try taking the derivative of y(t). This requires use of the chain rule and Leibniz integral rule. The answer is

dy(t)dt=Aexp(j2πktx(τ)dτ+jθ)j2πkx(t).

The derivative brings x(t) out side both the exponential function and the integral. The message x(t) now acts like amplitude modulation. The complex exponential can be canceled by multiplying by the conjugage of y(t)

z(t)=y(t)dy(t)dt=jA22πkx(t).

Finally, if we take the imaginary part of z(t), we recover a scaled version of x(t) which was our goal.

In summary, the sequency of operations in receiving and demodulating FM are as follows.

  1. Mix the signal of interest to baseband by multiplying by exp(j2πFct).
  2. Apply a low-pass filter to isolate the signal of interest and remove all the other signals resulting in the complex-baseband signal.
  3. Differentiate the complex-baseband signal (using a differentiating filter) and multiply by the conjugate of the complex-baseband signal.
  4. Take the imaginary part resulting in an audio signal.

All of these steps may be performed in about five lines of Matlab code. Along the way, the sample rate must be reduced so that the samples can be fed to a sound card. This involves downsampling which we stuied in a previous lab assignment.

 

Let's Do It!

  1. Download the signal fm_rds_2400k_complex2. This file is almost 400 MB. (Special thanks to John E. Post for the data and his article entitled "FM RECEPTION WITH THE GNU RADIO COMPANION" which gives a lot of good information about FM and includes links at the end of the article to other reference material.)

  2. Read some of the signal into into the Matlab workspace. Here's a few things to keep in mind from the datafile web page.

    1. The sample rate of the data is Fs=2.4 MS/s.
    2. The data was captured with a receiver tuned to 106.7 MHz as it's center frequency.
    3. GnuRadio software was used in the data capture. GnuRadio stores the in-phase (real) and quadrature (imaginary) samples in interleaved order using 32-bit floating point type.
  1. When you meet a new signal, it's a good idea to visualize it in the time domain, frequency domain, and/or in time-frequency space using a spectrogram. In this part, make two spectral plots of the given signal. In one plot, use a true scaled frequency axis. In the second plot, use a normalized frequency axis. Here is some basic Matlab code showing how to do this and the plots follow.

These spectral plots reveal that there are actually two FM signals picked up in the 2.4 MHz bandwidth of the received signal. The red-lines mark the carrier frequencies which are 106.7 MHz and 107.5 MHz. We can see that each of the FM signals has a bandwidth of 200 kHz centered on the carrier frequency.

The lower spectral plot uses normalized frequency to show where the signals actually are in the data. This plot shows that one of the FM signals is already at baseband (zero frequency) while the other one is at (107.5 - 106.7)/2.4 = 0.8/2.4 = 1/3 = 0.3333 cycles/sample.

  1. We will demodulate the signal that appears at baseband. If we wanted to demodulate another signal, we just have to move it to baseband by mixing with (multiplication by) a complex exponential exp(j2πfΔn), where fΔ is the desired amount of shift. A property of the DTFT predicts that mixing with a complex exponential signal causes a frequency shift, and the pictures below indicate that is exactly what happens when fΔ=1/3. Notice that the signal at 107.5 MHz now appears at baseband. Try this yourself and make spectral plots of the frequency shifted spectra.

  1. The first step in demodulating an FM signal is to isolate it from other signals that may be present. To accomplish this, we will use a low pass filter. The filter should pass the signal of interest which extends to Fpass=100 kHz above the carrier and stop other signals. Let's let Fstop=150 kHz. Normalize these frequencies by the sample rate Fs=2.4 MHz and design a trapazoidal filter with a Hamming window. Then apply it to the signal. When I did this, I obtained the following plots which show (upper) the spectrum of the original signal and the magnitude response of the LPF. The lower plot shows the spectrum of the filtered signal which contains the FM signal of interest and the other FM signal has been removed.

  1. All that empty spectral space indicates that the signal is now oversampled and may be compressed/decimated without loosing any information. Compressing/decimating the signal will expand it in the frequency domain. How much can the signal be expanded in the frequency domain? The highest frequency in the filtered signal is about 200 kHz and the highest frequency representable is 1.2 MHz which is half the sample rate 2.4 MHz. Taking the ratio gives 1.2 MHz/200 kHz = 6. We can decimate the signal as follows.

Perform these steps and then make spectral plots of the signal before and after compression/decimation. Use a normalized frequency axis. Here's what I got.

The compression step is not absolutely necessary but it reduces the amount of data for subsequent processing. Thus compression when possible makes for efficient processing. The sample rate has to be reduced at some point because the result of demodulation is audio data and most sound cards require sample rate below 100 kS/s. Compressing by a factor of D=6 leads to a sample rate of 2.4e6/6 = 400 kS/s. Some additional compression will be needed in a later step.

Before proceeding any further it's worth pausing to look at the spectrogram of the signal before the compression step. A short segment of that spectrogram is shown below. Remember that a spectrogram, when viewed as an image, shows how the frequency of the signal varies over time. Also remember that in FM, the message x(t) is encoded in the frequency of the signal. Therefore, by looking at the spectrogram, you can actually see the message signal x(t)! Demodulation is the process of extracting what we can already see in the spectrogram.

  1. The next step in FM democulation is differentiating the signal. There's two things that we need to keep in mind: (1) we differentiate the signal using a filter, and (2) that derivative filter causes a delay. The delay is not bad, but remember that the next step is to multiply the output of the derivative filter by the conjugate of the input of the derivative filter. Remember the step z(t)=y(t)(dy(t)/dt). It's vitally important that we keep our signals time aligned. If the derivative signal dy(t)/dt has been delayed by the action of filtering, then we must also delay y(t) by the same amount. If we do this, then the signals will be time aligned and everything will work out. So we are going to design two filters: (1) a derivative filter, and (2) an all pass filter having the same delay as the derivative filter. Let's start with the derivative filter.

Recall the following property of the continuous-time Fourier transform.

x(t)X(F)dx(t)dtj2πFX(F)

In other words, a filter that differentiates a signal has frequency response given by H(F)=j2πF. There's really no such thing as a derivative on a discrete-time signal, but we can design a filter having a frequency response given by H(f)=j2πf. The impulse response of such a filter is

h[n]={0,n=0,(1)nn,n0.

Derive this result and include this in your report. Here are a few ideas to get started. We want to perform a differentiation operation using a filter. The filtering property of the CTFT is:

h(t)x(t)=dx(t)dtH(F)X(F)=j2πFX(F).

So we see that if we let H(F)=j2πF, then the result of convolution will be the derivative. Now there is no such thing as a derivative in discrete time, but taking inspiration from the continuous time case, we can design a discrete-time filter with frequency response H(f)=j2πf for 12f<12. The impulse response of this filter is given by

h[n]=1212H(f)ej2πfndf=j2π1212fej2πfndf.

Now use integration by parts to find h[n].

This IIR filter is not causal or stable, but we can build a causal, stable, FIR approximation by truncating this impulse response and delaying it. See the Matlab code below which also includes a Hamming window.

Make a plot of the magnitude responses of the derivative and delay filters. Also make a plot of the impulse responses. Note that the magnitude response of the derivative filter is |H(f)|=2π|f|, i.e. it is an absolute value function.

  1. Demodulate the FM signal using the Matlab code below

The demodulated signal has several components as shown in the figure below.

Demodulated FM signal spectrum.

We want to extract just the left+right audio between 0 and 15 kHz using a low pass filter. Design a trapazoidal LPF. Make sure the filter passes the signal of interest and rejects everything at and above 19 kHz.

Apply the filter to the demodulated signal. Make two spectral plots. In the first one, show the spectrum of the demodulated FM signal and the magnitude response of your LPF. In the second plot, show the spectrum of the filtered signal. Here are my plots.

  1. All that empty spectral space indicates that the filtered signal can be compressed/decimated without loss of information. As noted earlier, compression in the time domain causes expansion in the frequency domain. How much can the signal spectrum be expanded? The highest frequency is about 20 kHz and the higest representable frequency is 200 kHz which is half the sample rate. The ratio is 200 kHz / 20 kHz = 10. Thus we can compress/decimate the signal by a factor of D=10. This reduces the sample rate to 400 kS/s / 10 = 40 kS/s. This is a low enough sample rate that we can pass the samples to an audio soundcard.

Compress the signal and make spectral plots before and after compression.

  1. Take the imaginary part of the compressed signal and listen to it. Can you hear the message? Describe what you hear?
  2. The given signal contains two FM signals. Shift the other signal to baseband and repeat the processing steps. Listen to that signal. Describe what you hear?

 

Report

Your report should include the code, plots, and derivation from the steps listed above.