1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| from scipy.io.wavfile import read
from pylab import *
import matplotlib.pyplot as plt
import numpy as np
import scipy
# read the file
(sr, samples) = read('test.wav')
x = (np.float32(samples)/((2 ** 15)-1))
N = len(x)
x_fft = np.fft.fft(x)
# scales
J = 200
scales = np.asarray([2**(i * 0.1) for i in range(J)])
# pre-compute the Fourier transform of the Morlet wavelet
morletft = np.zeros((J, N))
for i in range(J):
morletft[i][:N/2] = sqrt(2 * pi * scales[i]) * exp(-(scales[i] * 2 * pi * scipy.array(range(N/2)) / N - 2)**2 / 2.0)
# compute the CWT
X = empty((J, N), dtype=complex128)
for i in range(J):
X[i] = np.fft.ifft(x_fft * morletft[i]) |
Partager