本文主要参考:Sine Sweep(正弦扫频信号)_Recoding...-CSDN博客_正弦扫频信号
Sine Sweep(正弦扫频信号)_fzh2712的专栏-CSDN博客_扫频信号
读后记录如下:
1. Sine sweep波的函数
sweep(t) = sin(2*PI*f0*(k^t-1)/log(k))
2.python代码
from math import *
import array
import matplotlib.pyplot as plt
import wave
def sinesweep(f0, f1, sweeptime, samplingrate, peak):
k = exp(log(float(f1)/f0)/sweeptime)
data_len = sweeptime * samplingrate
data = array.array('i',[0]*data_len)
dt = 1.0/samplingrate
t = 0.0
p = 2*pi*f0/log(k)
for i in range(data_len):
data[data_len-i-1] = int(peak*sin( p*(pow(k,t)-1) ))
t += dt
return data
def sindata(f0, time, samplingrate, peak):
data = [int(peak*sin(2*pi*f0*x/samplingrate)) for x in xrange(int(time*samplingrate))]
return array.array('h', data)
if 1:
SAMPLING_RATE = 44100
SWEEP_TIME = 2
F0 = 20
F1 = 20000
PEAK = 0x2000
data = sinesweep(F0, F1, SWEEP_TIME, SAMPLING_RATE, PEAK)
plt.title("sweep data")
plt.plot(data)
plt.show()
if 1 :
f = wave.open("sweep.wav","wb")
f.setnchannels(1) # mono wave
f.setsampwidth(2) # 16bit
f.setframerate(SAMPLING_RATE) #sampling rate
f.writeframes(data)
f.close()
3.运行结果
syncsweptsine方法:
github:
https://github.com/SiggiGue/syncsweptsine
安装方法:pip install git+https://github.com/SiggiGue/syncsweptsine.git
Novak, A., Lotton, P., & Simon, L. (2015). Synchronized Swept-Sine: Theory, Application, and Implementation. Journal of the Audio Engineering Society, 63(10), 786–798.doi:10.17743/jaes.2015.0071
Novák, A., Simon, L., Kadlec, F., & Lotton, P. (2010). Nonlinear System Identification Using Exponential Swept-Sine Signal. IEEE Transactions on Instrumentation and Measurement, 59(8), 2220–2229.doi:10.1109/tim.2009.2031836