1

I am thinking of analyzing a time-series of some particular values as it were a frequency-modulated signal.

I was looking for a Python implementation of an FM demodulator. I know there is a demodulator function in Matlab and Octave; for Python I found this FreqDemod package, but it doesn't seem to do what I want to do.

Help will be appreciated.

Fabio Capezzuoli
  • 599
  • 7
  • 23
  • What are you expecting it to do? It looks like it does basic FM demodulation? – fstop_22 Feb 12 '20 at 20:53
  • I want to do FM demodulation indeed. This package I found takes the signal to demodulate not as an array but in its own special class. I don't want to bother with learning all that, i need to stay focused. – Fabio Capezzuoli Feb 12 '20 at 21:43

1 Answers1

4

Here is a Python function that does FM demodulation on complex samples.

import numpy as np

def fm_demod(x, df=1.0, fc=0.0):
    ''' Perform FM demodulation of complex carrier.

    Args:
        x (array):  FM modulated complex carrier.
        df (float): Normalized frequency deviation [Hz/V].
        fc (float): Normalized carrier frequency.

    Returns:
        Array of real modulating signal.
    '''

    # Remove carrier.
    n = np.arange(len(x))
    rx = x*np.exp(-1j*2*np.pi*fc*n)

    # Extract phase of carrier.
    phi = np.arctan2(np.imag(rx), np.real(rx))

    # Calculate frequency from phase.
    y = np.diff(np.unwrap(phi)/(2*np.pi*df))

    return y
fstop_22
  • 971
  • 5
  • 9
  • Just as a note to future readers, this function outputs to a single track of audio and is not stereo. It's definitely useful for checking if you are recording your SDR's data to a wav file correctly though. – Alexis Evelyn Mar 15 '22 at 01:47
  • What does sp means in code example ? – Denis Kotov Feb 11 '23 at 17:55
  • It is scipy package. There is an implicit import of scipy at top of file. Should probably be using numpy instead of scipy now. I have updated answer with import. – fstop_22 Feb 28 '23 at 12:02