%%
[x,fs]=audioread('flute.wav');
x = x(1:2.28e5);

%%
NFFT = 256;
ax1 = subplot(211);
[S,F,T] = spectrogram(x,rectwin(NFFT),round(0.95*NFFT),NFFT*16,fs);
imagesc(T,F,20*log10(abs(S)),[-40 40]);
set(gca,'YDir','normal','YLim',[0 2000]);
colorbar;
xlabel('Time [seconds]');
ylabel('Frequency [Hz]');
title('Rectangular Window'); 
ax2 = subplot(212);
[S,F,T] = spectrogram(x,hamming(NFFT),round(0.95*NFFT),NFFT*16,fs);
imagesc(T,F,20*log10(abs(S)),[-40 40]);
set(gca,'YDir','normal','YLim',[0 2000]);
colorbar;
xlabel('Time [seconds]');
ylabel('Frequency [Hz]');
title('Hamming Window');

linkaxes([ax1 ax2]);
pause;

%%
NFFT = 1024;
ax1 = subplot(211);
[S,F,T] = spectrogram(x,rectwin(NFFT),round(0.95*NFFT),NFFT*16,fs);
imagesc(T,F,20*log10(abs(S)),[-40 40]);
set(gca,'YDir','normal','YLim',[0 2000]);
colorbar;
xlabel('Time [seconds]');
ylabel('Frequency [Hz]');
title('Rectangular Window'); 
ax2 = subplot(212);
[S,F,T] = spectrogram(x,hamming(NFFT),round(0.95*NFFT),NFFT*16,fs);
imagesc(T,F,20*log10(abs(S)),[-40 40]);
set(gca,'YDir','normal','YLim',[0 2000]);
colorbar;
xlabel('Time [seconds]');
ylabel('Frequency [Hz]');
title('Hamming Window');

linkaxes([ax1 ax2]);
