stpt2.m
Go to the documentation of this file.
1 function y=stpt2(x,w,N,H,t)
2 %Analysis/synthesis of a sound using the peaks
3 %of the short-time Fourier transform
4 %x: input sound, w: analysis window (odd size), N: FFT size, H: hop
5 %size, t: threshold in negative dB, y: output sound
6 
7 %Internal variables
8 M=length(w);
9 N2=N/2+1;
11 hM=(M-1)/2;
12 
13 %Pointers
14 pin=1+hM;
16 
17 %Initialize buffers
19 yw=zeros(M,1);
20 y=zeros(soundlength,1);
21 
22 %Analysis/Synthesis windows
23 sw=hanning(M);
24 sw=sw./sum(sw);
25 w=w./sum(w);
26 
27 while pin<pend
28  %Analysis
29  xw=x(pin-hM:pin+hM).*w(1:M); %Frame selector
30  fftbuffer=zeros(N,1); %Zero-phase windowing
31  fftbuffer(1:(M+1)/2)=xw((M+1)/2:M);
32  fftbuffer(N-(M-1)/2+1:N)=xw(1:(M-1)/2);
33 
34  X=fft(fftbuffer); %FFT performance
35  mX=20*log10(abs(X(1:N2))); %Compute the FFT Magnitude (dB)
36  pX=angle(X(1:N2)); %Compute the FFT phase
37 
38  ploc=1+find((mX(2:N2-1)>t).*(mX(2:N2-1)>mX(3:N2)).*(mX(2:N2-1)>mX(1:N2-2))); %Peak finder above threshold (t)
39  pmag=mX(ploc); %Peak magnitude recovery
40  pphase=pX(ploc); %Peak phase recovery
41 
42  %Synthesis
43  Y=zeros(N,1); %Memory reserve
44  Y(ploc)=10.^(pmag/2).*exp(1i.*pphase); %Spectrum reconstruction from peak info
45  Y(N+2-ploc)=10.^(pmag/20).*exp(-1i.*pphase); %Spectrum reconstruction negative freq.
46  fftbuffer=real(ifft(Y)); %Compute inverse FFT
47  yw((M+1)/2:M)=fftbuffer(1:(M+1)/2); %Zero-phase windowing undo
48  yw(1:(M-1)/2)=fftbuffer(N-(M-1)/2+1:N);
49  y(pin-hM:pin+hM)=y(pin-hM:pin+hM)+H*N*sw.*yw(1:M); %overlap-add
50  pin=pin+H; %Pointer advance
51 end
52 
53 
magnitude spectrum pX
Definition: stft_peak.m:24
hM
Definition: stpt2.m:11
N, 1 zeros()
function w
Definition: stpt2.m:1
function ploc
FFT size for synthesis(even) H
FFT of current buffer mX
Definition: stft_peak.m:23
function N
Definition: stpt2.m:1
#define M(a, b)
Definition: vp3dsp.c:43
pphase
Definition: stft_peak.m:27
#define Y
Definition: vf_boxblur.c:76
end end
yw
Definition: stpt2.m:19
const char * from
function H
Definition: stpt2.m:1
Plot spectral magnitude
soundlength
Definition: stpt2.m:10
Discrete Time axis x
function y
Definition: stpt2.m:1
int size
clear max peak[Mmag2, Mloc2]
Definition: extra/TWM.m:16
MIPS optimizations info
Definition: mips.txt:2
Initialize buffers fftbuffer
Definition: stpt2.m:18
pend
Definition: stpt2.m:15
use a maximum of peaks[f0, f0error]
Sampled sinusoid X
MUSIC TECHNOLOGY GROUP UNIVERSITAT POMPEU FABRA Free Non Commercial Binary License Agreement UNIVERSITAT POMPEU OR INDICATING ACCEPTANCE BY SELECTING THE ACCEPT BUTTON ON ANY DOWNLOAD OR INSTALL YOU ACCEPT THE TERMS OF THE LICENSE SUMMARY TABLE Software MELODIA Melody Extraction vamp plug in Licensor Music Technology Group Universitat Pompeu Plaça de la Spain Permitted purposes Non commercial internal research and validation and educational purposes only All commercial uses in a production either internal or are prohibited by this license and require an additional commercial exploitation license TERMS AND CONDITIONS SOFTWARE Software means the software programs identified herein in binary any other machine readable any updates or error corrections provided by and any user programming guides and other documentation provided to you by UPF under this Agreement LICENSE Subject to the terms and conditions of this UPF grants you a royalty non non non limited for the specified duration in to reproduce and use internally Software complete and unmodified for the purposes indicated in the Summary Table CONDITIONS The Software is confidential and copyrighted You may make one backup copy Unless enforcement is prohibited by applicable law and other than as expressly provided in the Table above
Pointers pin
Definition: stpt2.m:14
sound(x3, Fs)
1i.*Xphase exp()
N2
Definition: stpt2.m:9
synthesis window for stochastic i
function pmag
fftbuffer, N fft()
Analysis Synthesis windows sw
Definition: stpt2.m:23
1:W2 xw()
function t
Definition: stpt2.m:1
static uint32_t inverse(uint32_t v)
find multiplicative inverse modulo 2 ^ 32
Definition: asfcrypt.c:35
const char int length
Definition: avisynth_c.h:668