FM modulation and demodulation with Python Part 3

Overview

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

Photo

figure_4.png

Flow graph

test17.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, 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

FM modulation and demodulation with Python Part 3
FM modulation and demodulation with Python Part 2
FM modulation and demodulation with Python
AM modulation and demodulation with python
AM modulation and demodulation in Python Part 2
Image processing with Python (Part 2)
Programming with Python and Tkinter
Encryption and decryption with Python
Studying Python with freeCodeCamp part1
Bordering images with python Part 1
Python and hardware-Using RS232C with Python-
Scraping with Selenium + Python Part 1
Studying Python with freeCodeCamp part2
Image processing with Python (Part 1)
Solving Sudoku with Python (Part 2)
Image processing with Python (Part 3)
Scraping with Selenium + Python Part 2
python with pyenv and venv
Works with Python and R
Communicate with FX-5204PS with Python and PyUSB
Shining life with Python and OpenCV
Playing handwritten numbers with python Part 1
Robot running with Arduino and python
Install Python 2.7.9 and Python 3.4.x with pip.
perl objects and python class part 2.
Neural network with OpenCV 3 and Python 3
[Python] font family and font with matplotlib
Scraping with Node, Ruby and Python
[Automation with python! ] Part 1: Setting file
Scraping with Python, Selenium and Chromedriver
Scraping with Python and Beautiful Soup
JSON encoding and decoding with python
Hadoop introduction and MapReduce with Python
[GUI with Python] PyQt5-Drag and drop-
Reading and writing NetCDF with Python
I played with PyQt5 and Python3
perl objects and python class part 1.
Reading and writing CSV with Python
Automate simple tasks with Python Part0
Multiple integrals with Python and Sympy
[Automation with python! ] Part 2: File operation
Coexistence of Python2 and 3 with CircleCI (1.0)
Easy modeling with Blender and Python
Sugoroku game and addition game with python
Excel aggregation with Python pandas Part 1
FX automatic trading system made with python and genetic algorithm Part 1
How to use Python with Jw_cad (Part 2 Command explanation and operation)
LINE BOT (Messaging API) development with API Gateway and Lambda (Python) [Part 2]
Communicate between Elixir and Python with gRPC
Data pipeline construction with Python and Luigi
Calculate and display standard weight with python
Monitor Mojo outages with Python and Skype
Play handwritten numbers with python Part 2 (identify)
[Automation] Manipulate mouse and keyboard with Python
Process Pubmed .xml data with python [Part 2]
Passwordless authentication with RDS and IAM (Python)
Automate simple tasks with Python Part1 Scraping
Python installation and package management with pip
Using Python and MeCab with Azure Databricks
POST variously with Python and receive with Flask
Capturing images with Pupil, python and OpenCV