Problem: download a wav file and display the frequency spectrum of the audio
signal using FFT. The Matlab example was based on Matheworks tech note
1702.
clearall;closeall;%%Thisscript plots the frequency spectrum of a wave file.%Thismethod of plotting the frequency spectrum is modeled after the%exampleon Mathworks website tech note 1702[data,Fs]=audioread('stereol.wav');[nSamples,nChannels]=size(data);waveFileLength=nSamples/Fs;N= 2^(nextpow2(length(data(:,1))));Y=fft(data(:,1),N);NumUniquePts=ceil((N+1)/2);Y= Y(1:NumUniquePts);P=abs(Y);P= P/length(data(:,1));P= P.^2;ifrem(N,2)%odd nfft excludes Nyquist pointP(2:end)= P(2:end)*2;elseP(2:end-1) = P(2:end-1)*2;endf= (0:NumUniquePts-1)*Fs/N;plot(f,P);title(sprintf('PowerSpectrum of a wave file'));xlabel('FrequencyHz');ylabel('|H(f)|');grid;print(gcf,'-dpdf','-r600','images/matlab_e52_1');