%% Historico de Comandos da 9a aula
mkdir aula_9
cd aula_9\
what
home
doc fft
X = randn(10,1);
Y = fft(X)
mean(X)
X = randn(9,1);
Y = fft(X)
edit new_fft
X = randn(9,1);
[ W, f ] = new_fft(X)
X = randn(10,1);
[ W,f] = new_fft(X)
figure, plot( f(f>0), abs(W(f>0)) )

%%
X = randn( 1e4,1 );
[ W,f] = new_fft(X);
figure, plot( f(f>0), abs(W(f>0)) )

X2 = diff(X);
[ W2,f2] = new_fft(X2);
figure, plot( f2(f2>0), abs(W2(f2>0)), '.' )

X3 = cumsum(X);
[ W3,f3] = new_fft(X3);
figure, plot( f3(f3>0), abs(W3(f3>0)), '.' )
figure, semilogy( f3(f3>0), abs(W3(f3>0)), '.' )
figure, loglog( f3(f3>0), abs(W3(f3>0)), '.' )

%%
help wavrecord
clear
load handel
whos
sound( y, Fs )
[ W, f ] = new_fft(y, Fs);
figure, plot( f(f>0), abs(W(f>0)), '.-' )
help spectrogram
[ w, f, t, p ] = spectrogram(y,round(0.1*Fs),round(0.05*Fs),[],Fs);
whos
f(1:4)
figure, imagesc( t, f, p )
figure, imagesc( t, f, abs(p) )
figure, imagesc( t, f, sqrt(p) )
figure, imagesc( t, f, log(p) )
figure, imagesc( t, f, log(p) ), set( gca, 'ydir', 'normal' )
whos
figure, plot( f, mean(p,2) )
[ W,f] = new_fft(y, Fs);
figure, plot( f(f>0), abs(W(f>0)), '.-' )

%%
clear
home
help wavrecord
Fs = 11025;
y = wavrecord( 10*Fs, Fs );
[ w, f, t, p ] = spectrogram(y,round(0.1*Fs),round(0.05*Fs),[],Fs);
figure, plot( y )
figure, imagesc( t, f, log(p) ), set( gca, 'ydir', 'normal' )
figure, imagesc( t, f, sqrt(p) ), set( gca, 'ydir', 'normal' )
figure, plot( f, mean(sqrt(p),2) )
help ginput
[ fpico, nada ] = ginput
figure, plot( fpico, '*' )


%%
home
clear
yPlay = .5*randn( 10*Fs, 1 );
sound( yPlay, Fs )
y = wavrecord( 10*Fs, Fs );
[ w, f, t, p ] = spectrogram(y,round(0.1*Fs),round(0.05*Fs),[],Fs);
figure, plot( yPlay )
figure, imagesc( t, f, (p).^.25 ), set( gca, 'ydir', 'normal' )
figure, imagesc( t, f, log(p) ), set( gca, 'ydir', 'normal' )

%%
home
clear
help chirp
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, plot( yPlay )
figure, imagesc( t, f, (p).^.25 ), set( gca, 'ydir', 'normal' )
figure, imagesc( t, f, log(p) ), set( gca, 'ydir', 'normal' )
