I tried FM modulation and demodulation with Python. The demodulator is GNU Radio FM Demod.
from gnuradio import analog
from gnuradio import audio
from gnuradio import blocks
from gnuradio import eng_notation
from gnuradio import filter
from gnuradio import gr
from gnuradio.eng_option import eng_option
from gnuradio.filter import firdes
from optparse import OptionParser
import sys
import scipy
import numpy as np
import scipy.signal as sg
import pylab
class radio(gr.top_block):
def __init__(self, vfm):
gr.top_block.__init__(self)
self.samp_rate = samp_rate = 32000
self.blocks_vector_source_x_0 = blocks.vector_source_f(vfm.tolist(), False, 1, [])
self.hilbert_fc_0 = filter.hilbert_fc(65, firdes.WIN_HAMMING, 6.76)
self.blocks_vector_sink_x_0 = blocks.vector_sink_f(1)
self.analog_fm_demod_cf_0 = analog.fm_demod_cf(channel_rate=samp_rate, audio_decim=1, deviation=75000, audio_pass=15000, audio_stop=16000, gain=1.0, tau=75e-6, )
self.connect((self.hilbert_fc_0, 0), (self.analog_fm_demod_cf_0, 0))
self.connect((self.analog_fm_demod_cf_0, 0), (self.blocks_vector_sink_x_0, 0))
self.connect((self.blocks_vector_source_x_0, 0), (self.hilbert_fc_0, 0))
def main():
sample_rate = 32000.
nsamples = 320
F_1 = 440.
A_1 = 1.0
F_2 = 10000.
A_2 = 6.0
t = np.arange(nsamples) / sample_rate
vin = A_1 * np.sin(2 * np.pi * F_1 * t)
vfm = A_1 * np.sin(2 * np.pi * F_2 * t + A_2 * -np.cos(2 * np.pi * F_1 * t))
put = radio(vfm)
put.run()
data = scipy.array(put.blocks_vector_sink_x_0.data())
f1 = pylab.figure(1, figsize = (12, 10), facecolor = 'w')
s1 = f1.add_subplot(2, 2, 1)
s1.plot(vin)
s3 = f1.add_subplot(2, 2, 2)
s3.plot(vfm)
s4 = f1.add_subplot(2, 2, 3)
s4.plot(data)
pylab.show()
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
pass
Recommended Posts