興味の無い方には全く役に立たないでしょう。
SDRによる無線処理が必要な方の為に参考資料として
Webに出しておきます。
以下『Phase Shift Keying』のサンプルコードです。
誰かの役に立てば幸いなり。
#################################
import numpy as np
from scipy import signal as sg
from scipy.fftpack import fft,ifft,fftshift,fftfreq
import matplotlib.pyplot as plt
fb = 440 #baseband
fc = 10000 #carrier
fs = 44100 #sampling freq
A = 1 #amp
t = 3 #time
alpha = np.pi/4
beta = np.pi/6
dat = np.arange(0,t,1/fs)
pt = 2*np.pi*dat
#sin(alpha)cos(beta)
sig = A * np.sin(fb * pt + alpha)
carrier = A * np.cos(fc * pt + beta)
# modulated signal
wave = A * np.cos((fc*pt) + beta + sig)
#plt.plot(sig[0:100])
#plt.plot(carrier[0:100])
#plt.plot(wave[0:100])
#plt.show()
#AWGN noise add
#Add AWGN noise to the transmitted signal
nMean = 0 #noise mean
nSigma = 0.1 #noise sigma
n = np.random.normal(nMean, nSigma, len(dat))
noisy = wave + n #noisy received signal
#plt.plot(wave[0:100])
#plt.plot(noisy[0:100])
#plt.show()
#analytic signal
asig = sg.hilbert(noisy)
# instaneous phase
phase = np.unwrap(np.angle(asig))
#demodulation
#
offset = 2 * np.pi * fc * dat + beta
want = phase - offset
#noise reduction
#low pass filter
# num must be odd number. num up more smooth
num = 7
nyq = fs/2
cutoff = (fc/2) / nyq
lpf = sg.firwin(num,cutoff)
signal = sg.lfilter(lpf,1,want)
plt.plot(signal[:300])
plt.plot(sig[:300])
plt.show()
WFM変復調。IQ復調とFIRフィルターを使用。
import numpy as np
from scipy import signal as sg
from scipy.fftpack import fft,ifft,fftshift,fftfreq
import matplotlib.pyplot as plt
fb = 440 #baseband
fc = 10000 #carrier
fs = 44100 #sampling freq
A = 1 #amp
t = 3 #time
m = 10 #Frequency shift m > 1 wideFM
dat = np.arange(0,t,1/fs)
pt = 2*np.pi*dat
#sin(alpha)cos(beta)
sig = np.sin(fb * pt)
carrier = np.cos(fc * pt)
#
wave = A * np.cos((fc*pt) + m * np.sin(fb*pt))
#plt.plot(sig[0:100])
#plt.plot(carrier[0:100])
#plt.plot(wave[0:500])
#plt.show()
#解析的信号 hilbert transform
'''
#AWGN noise add
#Add AWGN noise to the transmitted signal
nMean = 0 #noise mean
nSigma = 0.1 #noise sigma
n = np.random.normal(nMean, nSigma, len(dat))
noisy = wave + n #noisy received signal
#plt.plot(wave[0:100])
#plt.plot(noisy[0:100])
#plt.show()
'''
#analytic signal
hil = sg.hilbert(wave)
asig = wave + (hil * 1j)
Q=np.real(asig)
I=np.imag(asig)
#plt.plot(I[0:100])
#plt.plot(Q[0:100])
#plt.show()
amp = np.abs(asig)
# under the same mean
phase = np.unwrap(np.angle(asig))
freq = np.diff(phase)/(2*np.pi)*fs
#demodulation
want= np.sin(fb * pt)
# normalize
nyq = fs/2
Nf = (freq - fc)/ nyq
#low pass filter
# num must be odd number
num = 15
cutoff = (fc/2) / nyq
lpf = sg.firwin(num,cutoff)
signal = sg.lfilter(lpf,1,Nf)
# Amplitude correction
signal = (signal * 5)
plt.plot(signal[0:500])
plt.plot( want[0:500])
plt.show()