tomwalters@0
|
1 % tool
|
tomwalters@0
|
2 %
|
tomwalters@0
|
3 % INPUT VALUES:
|
tomwalters@0
|
4 %
|
tomwalters@0
|
5 % RETURN VALUE:
|
tomwalters@0
|
6 %
|
tomwalters@0
|
7 %
|
bleeck@3
|
8 % This external file is included as part of the 'aim-mat' distribution package
|
bleeck@3
|
9 % (c) 2011, University of Southampton
|
bleeck@3
|
10 % Maintained by Stefan Bleeck (bleeck@gmail.com)
|
bleeck@3
|
11 % download of current version is on the soundsoftware site:
|
bleeck@3
|
12 % http://code.soundsoftware.ac.uk/projects/aimmat
|
bleeck@3
|
13 % documentation and everything is on http://www.acousticscale.org
|
bleeck@3
|
14
|
tomwalters@0
|
15
|
tomwalters@0
|
16 function plotfft(name)
|
tomwalters@0
|
17 % usage: plotfft('ghfgghfh.wav')
|
tomwalters@0
|
18
|
tomwalters@0
|
19 [y,Fs,bits]=wavread(name);
|
tomwalters@0
|
20
|
tomwalters@0
|
21 Fn=Fs/2; % Nyquist frequency
|
tomwalters@0
|
22 t=0:1/Fs:length(y)/Fs; % time vector sampled at Fs Hz,
|
tomwalters@0
|
23
|
tomwalters@0
|
24 % Next highest power of 2 greater than or equal to length(y)
|
tomwalters@0
|
25 NFFT=2.^(ceil(log(length(y))/log(2)));
|
tomwalters@0
|
26 % Take fft, padding with zeros, length(FFTX)==NFFT
|
tomwalters@0
|
27 FFTX=fft(y,NFFT);
|
tomwalters@0
|
28 NumUniquePts = ceil((NFFT+1)/2);
|
tomwalters@0
|
29 % fft is symmetric, throw away second half
|
tomwalters@0
|
30 FFTX=FFTX(1:NumUniquePts);
|
tomwalters@0
|
31 MX=abs(FFTX); % Take magnitude of X
|
tomwalters@0
|
32 % Multiply by 2 to take into account the fact that we threw out
|
tomwalters@0
|
33 % second half of FFTX above
|
tomwalters@0
|
34 MX=MX*2;
|
tomwalters@0
|
35 MX(1)=MX(1)/2; % Account for endpoint uniqueness
|
tomwalters@0
|
36 MX(length(MX))=MX(length(MX))/2; % We know NFFT is even
|
tomwalters@0
|
37 % Scale the FFT so that it is not a function of the length of y.
|
tomwalters@0
|
38 MX=MX/length(y); %
|
tomwalters@0
|
39 f=(0:NumUniquePts-1)*2*Fn/NFFT;plot(f,MX);
|
tomwalters@0
|
40 plot(f,MX);
|
tomwalters@0
|
41 xlabel('Frequency [Hz]');
|
tomwalters@0
|
42 ylabel('Magnitude'); |