FM modulation and demodulation with Python Part 2

Overview

I tried FM modulation and demodulation with Python. Demodulation algorithm is google radio

Photo

figure_1.png

Sample code

import scipy.signal as sg
import numpy as np
import matplotlib.pyplot as plt

sample_rate = 48000.0
nsamples = 320
F_1 = 440.0
F_2 = 10000.0
F_3 = 10000.0
nyq_rate = sample_rate / 2.0
cutoff_hz = 5000.0
numtaps = 29
t = np.arange(nsamples) / sample_rate
vin = np.sin(2 * np.pi * F_1 * t) 
vfm = np.sin(2 * np.pi * F_2 * t + 6.0 * -np.cos(2 * np.pi * F_1 * t))
i1 = vfm * np.cos(2 * np.pi * F_3 * t)
q1 = vfm * np.sin(2 * np.pi * F_3 * t)
lpf = sg.firwin(numtaps, cutoff_hz / nyq_rate)
I2 = sg.lfilter(lpf, 1, i1)
Q2 = sg.lfilter(lpf, 1, q1)
pI = 0
pQ = 0
m = 0
vo = np.zeros(320)
for t in range(0, vfm.size):
   real = pI * I2[t] + pQ * Q2[t]
   imag = pI * Q2[t] - pQ * I2[t]
   sgn = 1
   circ = 0
   ang = 0
   div = 1
   if (real < 0):
      sgn = -sgn
      real = -real
      circ = np.pi
   if (imag < 0):
      sgn = -sgn
      imag = -imag
      circ = -circ
   if (real > imag):
      div = imag / real
   else:
      if (real != imag):
         ang = -np.pi / 2
         div = real / imag
         sgn = -sgn
   vo[t] = circ + sgn * (ang + div / (0.98419158358617365 + div * (0.093485702629671305 + div * 0.19556307900617517))) * 5
   pI = I2[t]
   pQ = Q2[t]
fig = plt.figure(1)
ax = fig.add_subplot(311)
ax.plot(vin[1:300])
ax = fig.add_subplot(312)
ax.plot(vfm[1:300])
ax = fig.add_subplot(313)
ax.plot(vo[1:300])
fig.set_tight_layout(True)
plt.show()



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
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 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
Fractal to make and play with Python
A memo with Python2.7 and Python3 on CentOS