Example #1
0
from smst.models import dft

(fs, x) = audio.read_wav('../../../sounds/oboe-A4.wav')
M = 601
w = np.blackman(M)
N = 1024
hN = N / 2
Ns = 512
hNs = Ns / 2
H = Ns / 4
pin = 5000
t = -70
x1 = x[pin:pin + w.size]
mX, pX = dft.from_audio(x1, w, N)
ploc = peaks.find_peaks(mX, t)
iploc, ipmag, ipphase = peaks.interpolate_peaks(mX, pX, ploc)
freqs = iploc * fs / N
Y = synth.spectrum_for_sinusoids(freqs, ipmag, ipphase, Ns, fs)
mY = 20 * np.log10(abs(Y[:hNs]))
pY = np.unwrap(np.angle(Y[:hNs]))
y = fftshift(ifft(Y)) * sum(blackmanharris(Ns))
sw = np.zeros(Ns)
ow = triang(2 * H);
sw[hNs - H:hNs + H] = ow
bh = blackmanharris(Ns)
bh = bh / sum(bh)
sw[hNs - H:hNs + H] = sw[hNs - H:hNs + H] / bh[hNs - H:hNs + H]

plt.figure(1, figsize=(9, 6))

plt.subplot(3, 1, 1)
Example #2
0
import numpy as np

from smst.utils import audio, peaks
from smst.models import dft

(fs, x) = audio.read_wav('../../../sounds/sine-440-490.wav')
w = np.hamming(3529)
N = 32768
hN = N / 2
t = -20
pin = 4850
x1 = x[pin:pin + w.size]
mX1, pX1 = dft.from_audio(x1, w, N)
ploc = peaks.find_peaks(mX1, t)
pmag = mX1[ploc]
iploc, ipmag, ipphase = peaks.interpolate_peaks(mX1, pX1, ploc)

plt.figure(1, figsize=(9, 6))
plt.subplot(311)
plt.plot(fs * np.arange(pX1.size) / float(N), pX1, 'c', lw=1.5)
plt.plot(fs * iploc / N,
         ipphase,
         marker='x',
         color='b',
         alpha=1,
         linestyle='',
         markeredgewidth=1.5)
plt.axis([200, 1000, -2, 8])
plt.title('pX + peaks (sine-440-490.wav)')

(fs, x) = audio.read_wav('../../../sounds/vibraphone-C6.wav')