view 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
line wrap: on
line source
%function [y,yh,ys,fr0] = wave2fft2wave(x,fs,w,N,t,nH,minf0,maxf0,f0et,maxhd,stocf)
function [y] = wave2fft2wave(x,w,N)
%e.g. y = wave2fft2wave(x,hamming(2025),4096);


M = length(w);   % analysis window size
Ns = 1024;                               % FFT size for synthesis
H = 256;                                 % hop size for analysis and synthesis
soundlength = length(x);                 % length of input sound array
hNs = Ns/2;                              % half synthesis window size
hM = (M-1)/2;                            % half analysis window size
pin = max(hNs+1,1+hM);   % initialize sound pointer to middle of analysis window
pend = soundlength-max(hM,hNs);          % last sample to start a frame
fftbuffer = zeros(N,1);                  % initialize buffer for FFT
y = zeros(soundlength+Ns/2,1);           % output sine component
w = w/sum(w);                            % normalize analysis window
sw = zeros(Ns,1);
ow = triang(2*H-1);                      % overlapping window
ovidx = Ns/2+1-H+1:Ns/2+H;               % overlap indexes
sw(ovidx) = ow(1:2*H-1);
bh = blackmanharris(Ns);                 % synthesis window
bh = bh ./ sum(bh);                      % normalize synthesis window
sw(ovidx) = sw(ovidx) ./ bh(ovidx);


while pin<pend
    
    xw = x(pin-hM:pin+hM).*w(1:M);         % window the input sound
    fftbuffer(1:(M+1)/2) = xw((M+1)/2:M);  % zero-phase window in fftbuffer
    fftbuffer(N-(M-1)/2+1:N) = xw(1:(M-1)/2);
    X = fft(fftbuffer);                    % compute the FFT
    ri= pin-hNs;                           % input sound pointer for residual analysis
    yw = ifft(X);    
    y(ri:ri+Ns-1) = y(ri:ri+Ns-1)+yw(1:Ns).*sw;
    pin = pin+H;     
    
end

y = (max(x)/max(y))*y; % scale y to original amplitude

%wavwrite(y,44100,'test.wav');