yading@10: function y = sinemodel(x, w, N, t) yading@10: % Analysis/synthesis of a sound using the sinusoidal model yading@10: % x: input sound, w: analysis window (odd size), N: FFT size, yading@10: % t: threshold in negative dB, y: output sound yading@10: M = length(w); % analysis window size yading@10: Ns= 1024; % FFT size for synthesis (even) yading@10: H = 256; % analysis/synthesishop size yading@10: N2= N/2+1; % size of positive spectrum yading@10: soundlength = length(x); % length of input sound array yading@10: hNs = Ns/2; % half synthesis window size yading@10: hM = (M-1)/2; % half analysis window size yading@10: pin = max(N2,1+hM); % initialize sound pointer to middle of analysis window yading@10: pend = soundlength-max(N2,hM); % last sample to start a frame yading@10: fftbuffer = zeros(N,1); % initialize buffer for FFT yading@10: y = zeros(soundlength,1); % initialize output array yading@10: w = w/sum(w); % normalize analysis window yading@10: sw = zeros(Ns,1); yading@10: ow = triang(2*H-1); % overlapping window (triangular window to avoid too much overlapping) yading@10: ovidx = Ns/2+1-H+1:Ns/2+H; % overlap indexes yading@10: sw(ovidx) = ow(1:2*H-1); yading@10: bh = blackmanharris(Ns); % synthesis window yading@10: bh = bh ./ sum(bh); % normalize synthesis window yading@10: sw(ovidx) = sw(ovidx) ./ bh(ovidx); yading@10: while pint) .* (mX(2:N2-1)>mX(3:N2)).* (mX(2:N2-1)>mX(1:N2-2))); % find peaks yading@10: [ploc,pmag,pphase] = peakinterp(mX,pX,ploc); % refine peak values yading@10: %-----synthesis-----% yading@10: plocs = (ploc-1)*Ns/N+1; % adapt peak locations to synthesis FFT yading@10: Y = genspecsines(plocs,pmag,pphase,Ns); % generate spec sines yading@10: yw = fftshift(real(ifft(Y))); % time domain of sinusoids yading@10: y(pin-hNs:pin+hNs-1) = y(pin-hNs:pin+hNs-1) + sw.*yw(1:Ns); % overlap-add yading@10: pin = pin+H; % advance the sound pointer yading@10: end