yading@10: function y=stptpeaks(x, w, N, H, t) yading@10: % Analysis/synthesis of a sound using the peaks yading@10: % of the short-time fourier transform yading@10: % x: input sound, yading@10: % w: analysis window (odd size), yading@10: % N: FFT size, yading@10: % H: hop size, yading@10: % t: threshold in negative dB, yading@10: % y: output sound yading@10: yading@10: M = length(w); % analysis window size yading@10: N2 = N/2+1; % size of positive spectrum yading@10: soundlength = length(x); % length of input sound array yading@10: hM = (M-1)/2; % half analysis window size yading@10: yading@10: pin = 1+hM; % initialize sound pointer at the middle of analysis window yading@10: pend = soundlength-hM; % last sample to start a frame yading@10: yading@10: fftbuffer = zeros(N,1); % initialize buffer for FFT yading@10: yw = zeros(M,1); % initialize output sound frame yading@10: y = zeros(soundlength,1); % initialize output array yading@10: yading@10: w = w/sum(w); % normalize analysis window yading@10: sw = hanning(M); % synthesis window yading@10: sw = sw./sum(sw); yading@10: yading@10: while pint) .* (mX(2:N2-1)>mX(3:N2)) .* (mX(2:N2-1)>mX(1:N2-2))); % peakss yading@10: pmag = mX(ploc); % magnitude of peaks yading@10: pphase = pX(ploc); % phase of peaks yading@10: num_peak=length(ploc)/2; %Just positive peaks yading@10: yading@10: axis=linspace(0,pi,N2); %Axis for the whole frequency plot yading@10: axis_peak=axis(ploc(1:num_peak));%Axis for just the peaks plot yading@10: yading@10: subplot(2,1,1); plot(axis,mX); hold on; %Magnitude plot yading@10: plot(axis_peak,pmag(1:num_peak),'rx');%Magnitude peaks yading@10: subplot(2,1,2); plot(axis,pX); hold on; %Phase plot yading@10: plot(axis_peak,pphase(1:num_peak),'rx');%Phase peaks yading@10: yading@10: pin = pin+H; % advance sound pointer yading@10: end