Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 11 of 11

Thread: FM demodulation

  1. #1
    Junior Member
    Join Date
    Sep 2018
    Posts
    4

    FM demodulation

    Hi Teensiers

    So there's a bunch of modules for FM modulation but none for demodulation. Actually none for any sort of demodulation.

    As I'm still a big noob when it comes to this topic of DSP I was wondering if anyone had suggestions or advice about this.

    What I'm working with is a direct conversion receiver with a 20khz IF pushed straight into the Teensy analog port. From spending several days reading the easiest way to do this without I/Q is to just pass the signal through a Biquad highpass filter with a ~15khz corner, which results in an AM signal.

    From there it needs to become an audio signal, but I'm not entirely sure what to do there. So far I put together the most simplistic module here https://github.com/calston/x-uhf/blo...r/AM_demod.cpp which just emulates a diode detector circuit kinda. Now I need to remove all the other frequency information, or am I lost? I guess I can just do a rolling average window and reconstruct like that or is there some fancy way people use FIR/IIR filters?

    Throwing my dead simple abs() straight out to a speaker through the DAC actually does work, the audio quality is just really crummy.

    I would really like to get a something in a single block that I can contribute back to the Audio library because the other examples of FM demodulation for Teensy I've been able to find are either built around very old versions of the library or are based on I/Q signals from off the shelf receiver hardware.

  2. #2
    Senior Member
    Join Date
    Jul 2014
    Posts
    1,820
    You could try to implement something along the line
    https://www.embedded.com/design/conf...on-algorithms-

  3. #3
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    1,788
    @WMXZ: Thank you for that link! Highly interesting!

  4. #4
    Senior Member
    Join Date
    Jul 2014
    Posts
    1,820
    Quote Originally Posted by Theremingenieur View Post
    Highly interesting!
    I must say I must get me the Book of Lyons sometimes

  5. #5
    Junior Member
    Join Date
    Sep 2018
    Posts
    4
    Thanks

    That seems to be the same problem though, unless theres an efficient way to just generate the I/Q signals from the raw input?

  6. #6
    Senior Member
    Join Date
    Jul 2014
    Posts
    1,820
    Quote Originally Posted by colinza View Post
    Thanks

    That seems to be the same problem though, unless theres an efficient way to just generate the I/Q signals from the raw input?
    A simple real to complex FFT generates I/Q signal
    have look into the thread https://forum.pjrc.com/threads/40590...Defined-Radio), maybe it helps you

  7. #7
    Senior Member DD4WH's Avatar
    Join Date
    Oct 2015
    Location
    Central Europe
    Posts
    302
    Hi Colin,

    I would recommend Whiteley (2011) and the thesis by Andras Retzler which both provide excellent explanations on FM demodulation and also ready-to-use C code!

    You will find the links here:

    https://github.com/DD4WH/Teensy-Conv...ks-&-Resources

    You can make I & Q signals out of your DC receiver signal if you multiply the signal with a local oscillator (LO) with 0 degree phase shift and with 90 degrees phase shift respectively. Then treat these signals as I & Q. For FM, just calculate the phase shift with arctan et voilá: demodulated audio. [the multiplication also translates your signal from your IF 20kHz to baseband, which makes things much easier then ! (LO frequency has to be 20kHz)]

    A coded example for FM demodulation is in the Teensy Convolution SDR code which you will also find under the link above.

    In practice, FM demodulation is a little more complex, but not complicated! However, if you would like to demodulate wideband FM radio, you need more bandwidth in your signal (at least 192kHz, so higher sample rate is needed). For narrowband FM, its perfectly OK to use the 44k1 sample rate.

    Also have a look at the Teensy SDR code by Rich Heslip, he coded a Teensy receiver for the Teensy 3.2 and by using mainly the audio lib blocks.

    A modified version of that code can be found here (however, as far as I remember, this does not have FM demodulation):

    https://github.com/DD4WH/Teensy-SDR-Rx

    Have fun with the Teensy!

    Frank DD4WH

  8. #8
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    18,153
    This will probably work well with the audio shield, but probably not so much with the analog input pins on Teensy.

    Quote Originally Posted by colinza View Post
    What I'm working with is a direct conversion receiver with a 20khz IF pushed straight into the Teensy analog port. From spending several days reading the easiest way to do this without I/Q is to just pass the signal through a Biquad highpass filter with a ~15khz corner, which results in an AM signal.
    When using the analog pins on Teensy, there's no analog low pass filtering. Unless you add an analog filter, any signal above 22 kHz will alias. Implementing a 15 kHz low pass filter with the audio library isn't going to do much good if all that higher frequency stuff has already aliased onto the lower frequency area.

    The SGTL5000 chip on the audio shield does very effectively filter away signals above about 21 kHz. NXP doesn't publish much info about this in their datasheet, but I can tell you I've personally tested with a function generator applying a full scale sine wave. It starts rapidly attenuating around 21 kHz and when you get past about 24 kHz there's almost no effect. The SGTL5000 probably has a sigma-delta converter inside. What it's oversampling ratio might be isn't documented, but 32 or 64 are probably good guesses. What sort of decimation filter is inside the SGTL5000 is also unknown. But I can tell you from experience watching numbers scrolling in the serial monitor as a sweep the signal generator, it's very effective.

  9. #9
    Junior Member
    Join Date
    Sep 2018
    Posts
    4
    Quote Originally Posted by PaulStoffregen View Post
    When using the analog pins on Teensy, there's no analog low pass filtering. Unless you add an analog filter, any signal above 22 kHz will alias. Implementing a 15 kHz low pass filter with the audio library isn't going to do much good if all that higher frequency stuff has already aliased onto the lower frequency area.
    .
    Yes I definitely did pass the input signal through a 20khz filter because there's so much other junk coming from the SA612, and then bias it up to 500mV with an opamp after decoupling.

  10. #10
    Junior Member
    Join Date
    Sep 2018
    Posts
    4
    Quote Originally Posted by DD4WH View Post
    Hi Colin,

    I would recommend Whiteley (2011) and the thesis by Andras Retzler which both provide excellent explanations on FM demodulation and also ready-to-use C code!

    You will find the links here:

    https://github.com/DD4WH/Teensy-Conv...ks-&-Resources

    You can make I & Q signals out of your DC receiver signal if you multiply the signal with a local oscillator (LO) with 0 degree phase shift and with 90 degrees phase shift respectively. Then treat these signals as I & Q. For FM, just calculate the phase shift with arctan et voilá: demodulated audio. [the multiplication also translates your signal from your IF 20kHz to baseband, which makes things much easier then ! (LO frequency has to be 20kHz)]
    Thanks very much for this Frank! Very useful info

  11. #11
    Senior Member DD4WH's Avatar
    Join Date
    Oct 2015
    Location
    Central Europe
    Posts
    302
    one more idea:

    * if you can change your hardware IF to 12kHz (1/4 of the 48ksps sample rate), things will be much easier, because you can use a very easy and light frequency translation procedure:

    https://flylib.com/books/en/2.729.1/...plication.html

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •