annotate wave2fft2wave.m @ 13:844d341cf643 tip

Back up before ISMIR
author Yading Song <yading.song@eecs.qmul.ac.uk>
date Thu, 31 Oct 2013 13:17:06 +0000
parents 8428a0ebd45f
children
rev   line source
emmanouil@5 1 %function [y,yh,ys,fr0] = wave2fft2wave(x,fs,w,N,t,nH,minf0,maxf0,f0et,maxhd,stocf)
emmanouil@5 2 function [y] = wave2fft2wave(x,w,N)
emmanouil@5 3 %e.g. y = wave2fft2wave(x,hamming(2025),4096);
emmanouil@5 4
emmanouil@5 5
emmanouil@5 6 M = length(w); % analysis window size
emmanouil@5 7 Ns = 1024; % FFT size for synthesis
emmanouil@5 8 H = 256; % hop size for analysis and synthesis
emmanouil@5 9 soundlength = length(x); % length of input sound array
emmanouil@5 10 hNs = Ns/2; % half synthesis window size
emmanouil@5 11 hM = (M-1)/2; % half analysis window size
emmanouil@5 12 pin = max(hNs+1,1+hM); % initialize sound pointer to middle of analysis window
emmanouil@5 13 pend = soundlength-max(hM,hNs); % last sample to start a frame
emmanouil@5 14 fftbuffer = zeros(N,1); % initialize buffer for FFT
emmanouil@5 15 y = zeros(soundlength+Ns/2,1); % output sine component
emmanouil@5 16 w = w/sum(w); % normalize analysis window
emmanouil@5 17 sw = zeros(Ns,1);
emmanouil@5 18 ow = triang(2*H-1); % overlapping window
emmanouil@5 19 ovidx = Ns/2+1-H+1:Ns/2+H; % overlap indexes
emmanouil@5 20 sw(ovidx) = ow(1:2*H-1);
emmanouil@5 21 bh = blackmanharris(Ns); % synthesis window
emmanouil@5 22 bh = bh ./ sum(bh); % normalize synthesis window
emmanouil@5 23 sw(ovidx) = sw(ovidx) ./ bh(ovidx);
emmanouil@5 24
emmanouil@5 25
emmanouil@5 26 while pin<pend
emmanouil@5 27
emmanouil@5 28 xw = x(pin-hM:pin+hM).*w(1:M); % window the input sound
emmanouil@5 29 fftbuffer(1:(M+1)/2) = xw((M+1)/2:M); % zero-phase window in fftbuffer
emmanouil@5 30 fftbuffer(N-(M-1)/2+1:N) = xw(1:(M-1)/2);
emmanouil@5 31 X = fft(fftbuffer); % compute the FFT
emmanouil@5 32 ri= pin-hNs; % input sound pointer for residual analysis
emmanouil@5 33 yw = ifft(X);
emmanouil@5 34 y(ri:ri+Ns-1) = y(ri:ri+Ns-1)+yw(1:Ns).*sw;
emmanouil@5 35 pin = pin+H;
emmanouil@5 36
emmanouil@5 37 end
emmanouil@5 38
emmanouil@6 39 y = (max(x)/max(y))*y; % scale y to original amplitude
emmanouil@6 40
emmanouil@5 41 %wavwrite(y,44100,'test.wav');