tomwalters@0: % tool tomwalters@0: % tomwalters@0: % INPUT VALUES: tomwalters@0: % tomwalters@0: % RETURN VALUE: tomwalters@0: % tomwalters@0: % bleeck@3: % This external file is included as part of the 'aim-mat' distribution package bleeck@3: % (c) 2011, University of Southampton bleeck@3: % Maintained by Stefan Bleeck (bleeck@gmail.com) bleeck@3: % download of current version is on the soundsoftware site: bleeck@3: % http://code.soundsoftware.ac.uk/projects/aimmat bleeck@3: % documentation and everything is on http://www.acousticscale.org bleeck@3: tomwalters@0: tomwalters@0: function plotfft(name) tomwalters@0: % usage: plotfft('ghfgghfh.wav') tomwalters@0: tomwalters@0: [y,Fs,bits]=wavread(name); tomwalters@0: tomwalters@0: Fn=Fs/2; % Nyquist frequency tomwalters@0: t=0:1/Fs:length(y)/Fs; % time vector sampled at Fs Hz, tomwalters@0: tomwalters@0: % Next highest power of 2 greater than or equal to length(y) tomwalters@0: NFFT=2.^(ceil(log(length(y))/log(2))); tomwalters@0: % Take fft, padding with zeros, length(FFTX)==NFFT tomwalters@0: FFTX=fft(y,NFFT); tomwalters@0: NumUniquePts = ceil((NFFT+1)/2); tomwalters@0: % fft is symmetric, throw away second half tomwalters@0: FFTX=FFTX(1:NumUniquePts); tomwalters@0: MX=abs(FFTX); % Take magnitude of X tomwalters@0: % Multiply by 2 to take into account the fact that we threw out tomwalters@0: % second half of FFTX above tomwalters@0: MX=MX*2; tomwalters@0: MX(1)=MX(1)/2; % Account for endpoint uniqueness tomwalters@0: MX(length(MX))=MX(length(MX))/2; % We know NFFT is even tomwalters@0: % Scale the FFT so that it is not a function of the length of y. tomwalters@0: MX=MX/length(y); % tomwalters@0: f=(0:NumUniquePts-1)*2*Fn/NFFT;plot(f,MX); tomwalters@0: plot(f,MX); tomwalters@0: xlabel('Frequency [Hz]'); tomwalters@0: ylabel('Magnitude');