forked from MTG/sms-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
540 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
Fabià Serra Arrizabalaga | ||
Xavier Serra | ||
Fabià Serra Arrizabalaga | ||
Sankalp Gulati |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified
BIN
-12.1 KB
(98%)
lectures/7-Sinusoidal-plus-residual-model/Sinusoidal-plus-residual-model.odp
Binary file not shown.
Binary file modified
BIN
+621 KB
(280%)
lectures/7-Sinusoidal-plus-residual-model/Stochastic-model.odp
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions
41
lectures/7-Sinusoidal-plus-residual-model/plots-code/LPC.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
from scipy.signal import hamming, hanning, triang, blackmanharris, resample | ||
import math | ||
import sys, os, time | ||
from scipy.fftpack import fft, ifft | ||
import essentia.standard as ess | ||
|
||
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../../software/utilFunctions/')) | ||
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../../software/models/')) | ||
import waveIO as WIO | ||
|
||
|
||
lpc = ess.LPC(order=14) | ||
N= 512 | ||
(fs, x) = WIO.wavread('../../../sounds/soprano-E4.wav') | ||
first = 20000 | ||
last = first+N | ||
x1 = x[first:last] | ||
X = fft(hamming(N)*x1) | ||
mX = 20 * np.log10(abs(X[:N/2])) | ||
|
||
coeff = lpc(x1) | ||
Y = fft(coeff[0], N) | ||
mY = 20 * np.log10(abs(Y[:N/2])) | ||
|
||
|
||
plt.figure(1) | ||
plt.subplot(2,1,1) | ||
plt.plot(np.arange(first, last)/float(fs), x[first:last], 'b') | ||
plt.axis([first/float(fs), last/float(fs), min(x[first:last]), max(x[first:last])]) | ||
plt.title('x (soprano-E4.wav)') | ||
|
||
plt.subplot(2,1,2) | ||
plt.plot(np.arange(0, fs/2.0, fs/float(N)), mX-max(mX), 'r', label="mX") | ||
plt.plot(np.arange(0, fs/2.0, fs/float(N)), -mY-max(-mY)-3, 'k', label="mY") | ||
plt.legend() | ||
plt.axis([0, fs/2, -60, 3]) | ||
plt.title('magnitude spectrum and LPC approximation') | ||
|
||
plt.show() |
Binary file added
BIN
+89.4 KB
lectures/7-Sinusoidal-plus-residual-model/plots-code/envelope-approx.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
60 changes: 60 additions & 0 deletions
60
lectures/7-Sinusoidal-plus-residual-model/plots-code/envelope-approx.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
from scipy.signal import hamming, hanning, triang, blackmanharris, resample | ||
import math | ||
import sys, os, time | ||
from scipy.fftpack import fft, ifft | ||
|
||
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../../software/utilFunctions/')) | ||
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../../software/models/')) | ||
import waveIO as WIO | ||
import dftAnal | ||
|
||
def stochasticModelFrame(x, w, N, stocf) : | ||
# x: input array sound, w: analysis window, N: FFT size, | ||
# stocf: decimation factor of mag spectrum for stochastic analysis | ||
hN = N/2 # size of positive spectrum | ||
hM = (w.size)/2 # half analysis window size | ||
pin = hM # initialize sound pointer in middle of analysis window | ||
fftbuffer = np.zeros(N) # initialize buffer for FFT | ||
yw = np.zeros(w.size) # initialize output sound frame | ||
w = w / sum(w) # normalize analysis window | ||
#-----analysis----- | ||
xw = x[pin-hM:pin+hM] * w # window the input sound | ||
X = fft(xw) # compute FFT | ||
mX = 20 * np.log10( abs(X[:hN]) ) # magnitude spectrum of positive frequencies | ||
mXenv = resample(np.maximum(-200, mX), mX.size*stocf) # decimate the mag spectrum | ||
pX = np.angle(X[:hN]) | ||
#-----synthesis----- | ||
mY = resample(mXenv, hN) # interpolate to original size | ||
pY = 2*np.pi*np.random.rand(hN) # generate phase random values | ||
Y = np.zeros(N, dtype = complex) | ||
Y[:hN] = 10**(mY/20) * np.exp(1j*pY) # generate positive freq. | ||
Y[hN+1:] = 10**(mY[:0:-1]/20) * np.exp(-1j*pY[:0:-1]) # generate negative freq. | ||
fftbuffer = np.real( ifft(Y) ) # inverse FFT | ||
y = fftbuffer*N/2 | ||
return mX, pX, mY, pY, y | ||
|
||
|
||
# example call of stochasticModel function | ||
if __name__ == '__main__': | ||
(fs, x) = WIO.wavread('../../../sounds/ocean.wav') | ||
w = np.hanning(512) | ||
N = 512 | ||
stocf = .1 | ||
envSize = (N * stocf) // 2 | ||
maxFreq = 10000.0 | ||
lastbin = N*maxFreq/fs | ||
first = 4000 | ||
last = first+w.size | ||
mX, pX = dftAnal.dftAnal(x[first:last], w, N) | ||
mXenv = resample(np.maximum(-200, mX), envSize) | ||
mY = resample(mXenv, N/2) | ||
plt.figure(1) | ||
plt.plot(float(fs)*np.arange(0, N/2)/N, mX, 'r', label=r'$a$') | ||
plt.plot(float(fs/2.0)*np.arange(0, envSize)/envSize, mXenv, color='k', label=r'$\tilde a$') | ||
plt.plot(float(fs)*np.arange(0, N/2)/N, mY, 'g', label=r'$b$') | ||
plt.legend() | ||
plt.axis([0, maxFreq, -80, max(mX)+3]) | ||
plt.title('envelope approximation') | ||
plt.show() |
Binary file added
BIN
+369 KB
lectures/7-Sinusoidal-plus-residual-model/plots-code/stochasticModelAnalSynth.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 50 additions & 0 deletions
50
lectures/7-Sinusoidal-plus-residual-model/plots-code/stochasticModelAnalSynth.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
from scipy.signal import hamming, hanning, resample | ||
from scipy.fftpack import fft, ifft | ||
import time | ||
import sys, os | ||
|
||
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../../software/utilFunctions/')) | ||
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../../software/models/')) | ||
|
||
import waveIO as WIO | ||
import stochasticModelAnal, stochasticModel,stftAnal | ||
|
||
(fs, x) = WIO.wavread('../../../sounds/ocean.wav') | ||
w = np.hamming(512) | ||
N = 512 | ||
H = 256 | ||
stocf = .1 | ||
mXenv = stochasticModelAnal.stochasticModelAnal(x, w, N, H, stocf) | ||
y = stochasticModel.stochasticModel(x, w, N, H, stocf) | ||
mX, pX = stftAnal.stftAnal(x, fs, w, N, H) | ||
|
||
|
||
plt.figure(1) | ||
plt.subplot(411) | ||
plt.plot(np.arange(x.size)/float(fs), x,'b') | ||
plt.title('input sound x=wavread(ocean.wav)') | ||
plt.axis([0,x.size/float(fs),min(x),max(x)]) | ||
|
||
plt.subplot(412) | ||
numFrames = int(mX[:,0].size) | ||
frmTime = H*np.arange(numFrames)/float(fs) | ||
binFreq = np.arange(N/2)*float(fs)/N | ||
plt.pcolormesh(frmTime, binFreq, np.transpose(mX)) | ||
plt.title('magnitude spectrogram; M=512, N=512, H=256') | ||
plt.autoscale(tight=True) | ||
|
||
plt.subplot(413) | ||
numFrames = int(mXenv[:,0].size) | ||
frmTime = H*np.arange(numFrames)/float(fs) | ||
binFreq = np.arange(stocf*N/2)*float(fs)/(stocf*N) | ||
plt.pcolormesh(frmTime, binFreq, np.transpose(mXenv)) | ||
plt.title('stochastic approximation; stocf=.1') | ||
plt.autoscale(tight=True) | ||
|
||
plt.subplot(414) | ||
plt.plot(np.arange(x.size)/float(fs), y,'b') | ||
plt.title('y') | ||
plt.axis([0,y.size/float(fs),min(y),max(y)]) | ||
plt.show() |
Binary file modified
BIN
+30.9 KB
(120%)
lectures/7-Sinusoidal-plus-residual-model/plots-code/stochasticModelFrame.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+15 KB
(110%)
lectures/7-Sinusoidal-plus-residual-model/plots-code/stochasticSynthesisFrame.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.