LoginSignup
0
1

More than 5 years have passed since last update.

python3でAM復調

Last updated at Posted at 2017-05-29

概要

python3で、AM復調やってみた。
AM信号は、5000Hzの搬送波、wavファイル。
復調アルゴリズムは、IQ復調。

AM信号

復調後の音声

サンプルコード

import numpy as np
import scipy.signal as sg
import wave
from scipy import fromstring, int16
from struct import pack

wavfile = "sHlM0.wav"
wr = wave.open(wavfile, "rb")
print (wr.getparams())
sample_rate = wr.getframerate()
para = wr.getparams()
wlen = wr.getnframes()
data = wr.readframes(wr.getnframes())
num_data = fromstring(data, dtype = int16)
left = num_data[::2]
right = num_data[1::2]
wr.close()
left = left
right = right
t = np.arange(wlen) / sample_rate
F_4KHz = 4000.
i1 = left * np.cos(t * 2 * np.pi * F_4KHz)
q1 = left * np.sin(t * 2 * np.pi * F_4KHz)
nyq_rate = sample_rate / 2.
cutoff_hz = 1000.0
lpf = sg.firwin(29, cutoff_hz / nyq_rate)
i2 = sg.lfilter(lpf, 1, i1)
q2 = sg.lfilter(lpf, 1, q1)
o = np.sqrt(i2 * i2 + q2 * q2) * 30
write_wave = wave.Wave_write("am7.wav")
write_wave.setparams(para)
for i in range(0, wlen):
    wvData = pack('h', int(o[i]))
    write_wave.writeframes(wvData)
    wvData = pack('h', int(o[i]))
    write_wave.writeframes(wvData)
write_wave.close()
print ("ok")

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1