Python: FM Demod Implementation

Question:

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.

Asked By: Fabio Capezzuoli

||

Answers:

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
Answered By: fstop_22