From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Community Documents

cancel
Showing results for 
Search instead for 
Did you mean: 

Using RTL-SDR with Labview, Appendix A: Simple FM Demodulator

Overview

 In a previous document (Using RTL-SDR with Labview Chapter 1 Labview on Windows), it was shown that a simple €20.00 dvb-t dongle can be used as a frontend to a labview based SDR system.  This document provided a library and instructions to the user that made it possible to retrieve the IQ streams from the rtl-sdr and showed a simple spectrum display of the signal received.  

After this post, there were some questions with regards to an FM demodulator to listen to FM broadcasts.  In this document, I will describe a simple, mono FM demodulator which can be used to listen to FM broadcast stations.  I will not go into detail on FM modulation.  There are many sources that can do this way better than myself.  Search on ni.com or on wikipedia for the relevant information.

Description

In order to demodulate a broadcast FM signal, it's important to understand the structure of this signal, as there is much more information contained in the FM signal than just the mono audio information.  The following image should make things clearer:

 

900px-RDS_vs_DirectBand_FM-spectrum2.svg.png

 

As you can see, the mono audio is only occupies a relatively small part of the channel bandwidth from 30Hz to 15kHz.  This is the portion that we will be focussing on.

 

As the name implies, FM, or frequency modulation, uses a baseband signal to modulate the frequency of a carrier signal.  The amplititude of the signal stays the same.  This is an advantage over amplitude modulation, where the information to be transmitted is contained within the modulated amplitude of the carrier.  If the AM signal is weakend significantly, information is lost.  Since the information for FM is contained in the zero-crossings of the signal, theoretically only a small signal level is required to reconstruct the entire baseband information.

 

The basic structure of the used demodulator is shown in the image below:

 

FM Demodulation Structure.png

 

Here is a short description of the chain:

 

  1. The signal is received from the rtl-sdr device as IQ data.  This is converted to a complex signal and the phase is extraced.
  2. The phase correction removes phase discontinuities.
  3. The key demodulation component in the chain is the phase derivative.  The phase derivative takes the phase of the signal and creates a second signal that is composed only of the changes in frequency.  This is then the demodulated signal.  
  4. The low pass filter is used to filter out frequencies above 15kHz, which do not contain the desired information.
  5. The rational resample takes the signal, which is still at the sampled rate (in the examples case 286650Hz) and resamples it to something the sound card can handle.  In this case, we are using a decimation factor of 13, which results in a 22050Hz audio stream.  Actually, I worked this out the other way around.  I wanted a 22050Hz audio stream and checked which sample rate would give me an integer decimation while keeping the RF sampling rate as low as possible.

The attached project provides an application which performs exactly these steps, allowing the user to tune to a frequency and listen to the mono part of the fm broadcast.  The demodulation is handled in a subvi, aptly named FM_Demodulation.vi, which looks like this:

 

FM Demodulation Structure.png

 

As you can see, all the steps for fm demodulation are present.  I've tried to comment the code as good as possible, and to adhere to the Labview coding guidelines.  There are some parts which could probably be further split into subvi's, but I wanted the software to be easy to read and be understandable to everyone.

 

Hardware and Software Requirements

Steps to Implement or Execute Code

  1. Open project
  2. Run app

Additional Information or References

If you have any questions, please feel free to ask.  

Comments
aaron.rice
Member
Member
on

Hello Albert,

Thank you for this excellent tutorial on the RTL-SDR.  I have been playing around with the attached Labview code and wondered if you could help me to answer something.  I am wondering why the FFT of my demodulated audio shows the noise floor moving up when the radio transmitter is powered off instead of showing the 6KHz moving down?  I have disabled AGC within the RTL-SDR and successfully prevented the same behavior in my RF spectrum FFT, but I'm not quite sure why it happens in the audio spectum.  Any ideas?

 

Thank you,

Aaron Rice

 

FFT_noiseFloor.png

aaron.rice
Member
Member
on

Sorry for the dumb question, very new to radio here.  My first intuition was that when the radio transmitter was turned off, I would see just the noise floor on the demodulated audio FFT.  After thinking it through I understand that when the radio transmitter is turned off, there is no FM modulated signal to demodulate.  At that point, the demodulated audio FFT window is just displaying garbage!

 

Best,

Aaron

Albert.lederer
Member
Member
on

Hi Aaron,

I'm really sorry I didn't reply to your comment earlier, but I didn't get notified about your first comment, so I never knew anyone had asked a question.  I usually reply so if you have another question and I don't respond two or three days later, please pn me directly... 

 

Anyway, you there aren't any stupid questions.  Regarding AGC, there are two autogain systems.  One is tuner AGC and one is the RTL AGC.  Both act according to their own devices.  So to disable autogain completely, you must turn BOTH off...  Also, you are correct, garbage in, garbage out 😉

 

If you want to see noise floor, you can use the basic demo example, as it computes an FFT of the raw data.  Also, please keep in mind that since there is no calibration available, any sort of scaling to dbm or dbuV makes little to no sense.  This means any noise floor measurements are not scaled properly.  I think I used dbFS (db Fullscale) which is easy, but stupid.  Technically, to get a good scaling, one would have to take the set gain into account and calibrate with a known source...

 

Hope this helps,

 

Albert

 

 

MassiZiane
Member
Member
on
Hello, I would like to know if i can use NooElec NESDR Mini USB RTL-SDR device in order to simulate the program ? I need an answer as soon as possible. Thank you
Albert.lederer
Member
Member
on

Hi!  From what I can see from the specs, this device should work. The chip seems to be alright.  Of course, I cannot guarantee success for a device I don't have.

joehall
Member
Member
on

I have LabView 2020 and I installed the *.vip using VIPM.  However, when I try to open the RTLSDR pallet, LabView immediately crashes and closes when I click on the pallet.  Any ideas for what might be the problem or possible workarounds?

Albert.lederer
Member
Member
on

Hi,

 

no idea.  I honestly haven't tried the VIPM library with LV2020. I'll try it out this weekend though, it's supposed to rain anyway.  If necessary, I'll rebuilt the package with the new VIPM and upload it as a new version.

yaans
Member
Member
on

Hello, I hope you could help me. I was very interested in this project of yours. So i tried to run the project to learn and study about this fm demodulator. I already follows all the steps and download all the files needed. I also bought the RTL-SDR devices. Unfortunately, when I run the FM_Demodulation.vi, there is an error that I could not understand. Would you mind explained it to me and where should I correct it? I already try my best to fixed the problem but i failed terribly. Here I attached a picture of the said error. Thank you in advanced. 

 

ScreenHunter 04.jpg

Albert.lederer
Member
Member
on

Hi,

 

you need to run the host_main.vi in order to run the software.  The FM_Demodulation is a subVI and is dependent on the setup of the main.vi...

yaans
Member
Member
on

I see, sorry for that silly mistake. Thank you so much sir!

АлексейSDR
Member
Member
on

Good day! Albert, please tell me how to get the phase difference from 3 SDR receivers at a given signal frequency?

Contributors