[x,fs] = wavread('Alison.wav');


t=1:length(x);

% A: Time waveform
figure
subplot(3,1,1);
plot(t,x);
axis tight;
xlabel('Time(samples)');
ylabel('Amplitude');

% B: Narrowband Spectrum
f = linspace(1,8000);
window = round(0.02*fs);
noverlap = round(0.97*window);

subplot(3,1,2);
spectrogram(x,window,noverlap,f,fs,'yaxis');
xlabel('Time (sec)');
ylabel('Frequency (Hz)');

% C: Wideband Spectrum
window = round(0.02*fs/4);
noverlap = round(0.9*window);

subplot(3,1,3)
spectrogram(x,window,noverlap,f,fs,'yaxis');
xlabel('Time (sec)');
ylabel('Frequency (Hz)');

% D: Magnitude and Phase Spectra at sample 3500 "A"

NT = 512;      %frame size
N1 = 3500;
s = x( (N1-(NT/2)) : (N1+(NT/2)-1) );
s = s.*hamming(NT);
fss = fft(s);
fss = fss(1:NT/2);
hz = (fs/2)*linspace(1,NT,NT/2);

figure
subplot(3,1,1), plot(s);
axis tight;
xlabel('Time(samples)');
ylabel('Amplitude');

subplot(3,1,2), plot(hz, 20*log10(abs(fss)));
axis tight;
xlabel('Frequency(hertz)');
ylabel('Amplitude(DB SPL)');

subplot(3,1,3), plot(hz, angle(fss));
axis tight;
xlabel('Frequency(hertz)');
ylabel('Phase(radians)');

% D: Magnitude and Phase Spectra at sample 21100 "E"

NT = 512;      %frame size
N1 = 21100;
s = x( (N1-(NT/2)) : (N1+(NT/2)-1) );
s = s.*hamming(NT);
fss = fft(s);
fss = fss(1:NT/2);
hz = (fs/2)*linspace(1,NT,NT/2);

figure
subplot(3,1,1), plot(s);
axis tight;
xlabel('Time(samples)');
ylabel('Amplitude');

subplot(3,1,2), plot(hz, 20*log10(abs(fss)));
axis tight;
xlabel('Frequency(hertz)');
ylabel('Amplitude(DB SPL)');

subplot(3,1,3), plot(hz, angle(fss));
axis tight;
xlabel('Frequency(hertz)');
ylabel('Phase(radians)');
