diff wave2fft2wave.m @ 5:840a4c453edc

wav -> fft -> wav
author emmanouilb <emmanouil.benetos.1@city.ac.uk>
date Sat, 20 Apr 2013 14:04:20 +0100
parents
children 8428a0ebd45f
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/wave2fft2wave.m	Sat Apr 20 14:04:20 2013 +0100
@@ -0,0 +1,39 @@
+%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
+
+%wavwrite(y,44100,'test.wav');
\ No newline at end of file