annotate extra/peakseaker.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 6840f77b83aa
children
rev   line source
yading@10 1 function y=peaks(x,w,N,H,t)
yading@10 2 %Analysis/sysntesis of a sound using the peaks
yading@10 3 %of the short-time fourier transform
yading@10 4 %x: input sound
yading@10 5 %w: analysis window (odd size)
yading@10 6 %N: FFT size
yading@10 7 %H: hop size
yading@10 8 %t: treshold in negative dB
yading@10 9 %y: output sound
yading@10 10
yading@10 11 %Internal variables
yading@10 12 M=length(w);
yading@10 13 N2=N/2+1;
yading@10 14 soundlength=length(x);
yading@10 15 hM=(M-1)/2;
yading@10 16
yading@10 17 %Pointers
yading@10 18 pin=1+hM;
yading@10 19 pend=soundlength-hM;
yading@10 20
yading@10 21 %Initialize buffers
yading@10 22 fftbuffer=zeros(N,1);
yading@10 23 yw=zeros(M,1);
yading@10 24 y=zeros(soundlength,1);
yading@10 25
yading@10 26 while pin<pend
yading@10 27 xw=x(pin-hM:pin+hM).*w(1:M); %Frame selector
yading@10 28 fftbuffer=zeros(N,1); %Zero-phase windowing
yading@10 29 fftbuffer(1:(M+1)/2)=xw((M+1)/2:M);
yading@10 30 fftbuffer(N-(M-1)/2+1:N)=xw(1:(M-1)/2);
yading@10 31
yading@10 32 X=fft(fftbuffer); %FFT Performance
yading@10 33 mX=20*log10(abs(X(1:N2))); %Compute FFT Magnitude
yading@10 34 pX=phase(X(1:N2)); %Compute FFT Phase
yading@10 35
yading@10 36 ploc=1+find((mX(2:N2-1)>t).*(mX(2:N2-1)>mX(3:N2)).*(mX(2:N2-1)>mX(1:N2-2))); %Peak search (levels above threshold)
yading@10 37 pmag=mX(ploc); %Find the peak magnitude
yading@10 38 pphase=pX(ploc); %Find the peak phase
yading@10 39 posipeak=length(ploc)/2; %Just positive peaks
yading@10 40
yading@10 41 axis=linspace(0,pi,abs(N2)); %Axis for the whole frequency plotting
yading@10 42 axis_peak=axis(ploc(1:num_peak));%Axis for just the peaks plotting
yading@10 43
yading@10 44 subplot(2,1,1); plot(axis,mX); hold off ; %Magnitude plotting
yading@10 45 plot(axis_peak,pmag(1:posipeak),'rx');%Magnitude peaks plot red x’s
yading@10 46 subplot(2,1,2); plot(axis,pX); hold off ;%Phase plotting
yading@10 47 plot(axis_peak,pphase(1:posipeak),'rx');%Phase peaks plot red x’s
yading@10 48
yading@10 49 pin=pin+H; %Advance the pointer
yading@10 50 end