chirp, sweep하는 정형파 만들기
Sine wave의 주파수가 일정하게 변하면서 모든 주파수를 들을 수 있다.
개인적으로 고주파를 들을 때 귀가 아픈게 짜증나지만 -.-
아래 예제는
10Hz~20kHz 주파수를 일정한 크기로 만들었지만,
사람의 청각 특성 때문에 귀로 들을 때는 일정한 크기로 들리지 않는다.
여기서 만든 wav 파일로 앞으로 만들 필터를 검증하는데 이용하려고 한다.
|
import math
import wave
import struct
import scipy
import numpy as np
import matplotlib.pyplot as plt
freq = 1000.0
data_size = 20*44100
fname = "ChirpWave.wav"
frate = 44100.0
amp = 64000.0 # multiplier for amplitude
t = np.arange(0, data_size/frate, 1/frate)
y= scipy.signal.chirp(t, f0=10, f1=20000, t1=5, method='linear')
wav_file = wave.open(fname, "w")
nchannels = 1
sampwidth = 2
framerate = int(frate)
nframes = data_size
comptype = "NONE"
compname = "not compressed"
wav_file.setparams((nchannels, sampwidth, framerate, nframes,
comptype, compname))
for s in y:
# write the audio frames to file
wav_file.writeframes(struct.pack('h', int(s*amp/2)))
wav_file.close()
|
참고 :
위키백과 : http://en.wikipedia.org/wiki/Chirp
http://www.scipy.org/Cookbook/FrequencySweptDemo
http://docs.scipy.org/doc/scipy/scipy-ref.pdf