AM modulation and demodulation in Python Part 2

Overview

I tried AM modulation and demodulation with Python. The demodulator is GNU Radio AM Demod.

Photo

figure_3.png

Flow graph

test16.grc.png

Sample code

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

AM modulation and demodulation in Python Part 2
AM modulation and demodulation with python
FM modulation and demodulation with Python Part 3
FM modulation and demodulation with Python Part 2
FM modulation and demodulation with Python
Stack and Queue in Python
UI Automation Part 2 in Python
Unittest and CI in Python
Transpose CSV files in Python Part 1
MIDI packages in Python midi and pretty_midi
Difference between list () and [] in Python
Difference between == and is in python
View photos in Python and html
Sorting algorithm and implementation in Python
Manipulate files and folders in Python
About dtypes in Python and Cython
Assignments and changes in Python objects
Check and move directories in Python
Ciphertext in Python: IND-CCA2 and RSA-OAEP
Hashing data in R and Python
Function synthesis and application in Python
perl objects and python class part 1.
Export and output files in Python
Reverse Hiragana and Katakana in Python2.7
Reading and writing text in Python
[GUI in Python] PyQt5-Menu and Toolbar-
Create and read messagepacks in Python
Solving AOJ's Algorithm and Introduction to Data Structures in Python -Part1-
Solving AOJ's Algorithm and Introduction to Data Structures in Python -Part2-
Solving AOJ's Algorithm and Introduction to Data Structures in Python -Part4-
Solving AOJ's Algorithm and Introduction to Data Structures in Python -Part3-
Overlapping regular expressions in Python and Java
Differences in authenticity between Python and JavaScript
Notes using cChardet and python3-chardet in Python 3.3.1.
Modules and packages in Python are "namespaces"
Avoid nested loops in PHP and Python
GUI creation in python using tkinter part 1
Differences between Ruby and Python in scope
difference between statements (statements) and expressions (expressions) in Python
Eigenvalues and eigenvectors: Linear algebra in Python <7>
Implementation module "deque" in queue and Python
Line graphs and scale lines in python
Implement FIR filters in Python and C
Differences in syntax between Python and Java
Check and receive Serial port in Python (Port check)
Search and play YouTube videos in Python
Difference between @classmethod and @staticmethod in Python
Draw a heart in Python Part 2 (SymPy)
Difference between append and + = in Python list
Difference between nonlocal and global in Python
Write O_SYNC file in C and Python
Dealing with "years and months" in Python
Read and write JSON files in Python
Easily graph data in shell and Python
Private methods and fields in python [encryption]
Find and check inverse matrix in Python
Linear Independence and Basis: Linear Algebra in Python <6>
Call sudo in Python and autofill password
Differences in multithreading between Python and Jython
Module import and exception handling in python
How to use is and == in Python