%%
Fs = 11025;

yPlay = .3*randn( 10*Fs, 1 );
% yPlay = chirp((0:10*Fs)/Fs, 200, 10, 2500);

sound( yPlay, Fs )
y = wavrecord( 10*Fs, Fs );

[ w, f, t, p ] = spectrogram(y,round(0.1*Fs),round(0.05*Fs),[],Fs);
figure, imagesc( t, f, (p).^.25 ), set( gca, 'ydir', 'normal' )
figure, plot( f, mean(sqrt(p),2) )

%%
am = mean( sqrt(p),2 );
figure
plot( f, am )
[ cX, cY, BOTAO ] = ginput( 3 );

%
for qp = 1 : 3
    [ valor_minimo, ind_f_pico_atu ] = min( abs(f-cX(qp)) );
    f_p = f( ind_f_pico_atu+(-2:2) );
    am_p = am( ind_f_pico_atu+(-2:2) );
    
    PAj = polyfit( f_p, am_p, 2 );
    cXaj(qp,1) = -PAj(2)/(2*PAj(1));
%     figure, plot( f_p, am_p, '.', ...
%         f_p(1):.01:f_p(end), polyval( PAj, f_p(1):.01:f_p(end) ), '-r' )
end

[ cX cXaj ]
