I tried AM modulation and demodulation with Python. The demodulator is GNU Radio AM 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, vam):
gr.top_block.__init__(self)
self.samp_rate = samp_rate = 32000
self.blocks_vector_source_x_0 = blocks.vector_source_f(vam.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_am_demod_cf_0 = analog.am_demod_cf(channel_rate=32000, audio_decim=1, audio_pass=8000, audio_stop=8100,)
self.connect((self.hilbert_fc_0, 0), (self.analog_am_demod_cf_0, 0))
self.connect((self.blocks_vector_source_x_0, 0), (self.hilbert_fc_0, 0))
self.connect((self.analog_am_demod_cf_0, 0), (self.blocks_vector_sink_x_0, 0))
def main():
sample_rate = 32000.
nsamples = 320
F_1 = 1000.
A_1 = 1.0
F_2 = 10000.
A_2 = 0.5
t = np.arange(nsamples) / sample_rate
vin = A_1 * np.sin(2 * np.pi * F_1 * t)
vam = (A_1 * np.sin(2 * np.pi * F_1 * t) + 1.0) * A_2 * np.sin(2 * np.pi * F_2 * t)
put = radio(vam)
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(vam)
s4 = f1.add_subplot(2, 2, 3)
s4.plot(data)
pylab.show()
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
pass
Recommended Posts