70 likes | 844 Views
FFT Examples with Matlab. Guofeng Deng. Matlab Program. X = wavread('sound1.wav'); Fs = 22050; % sampling rate is 22050 Hz N = length(X); if mod(N,2) == 1 N = N-1; end; X = X(1:N); T = N/Fs; % T is the complete sample length in seconds
E N D
FFT Examples with Matlab Guofeng Deng
Matlab Program • X = wavread('sound1.wav'); • Fs = 22050; % sampling rate is 22050 Hz • N = length(X); • if mod(N,2) == 1 • N = N-1; • end; • X = X(1:N); • T = N/Fs; % T is the complete sample length in seconds • fund = 1/T; % the fundamental or lowest frequency • Y = fft(X); • Pyy = Y.*conj(Y)/N; • f = fund*[0:1:N/2-1]; • time = 1/Fs:1/Fs:T; • % raw data • figure(1); • plot(time,X); • title('Original WAV Signal'); • xlabel('time (seconds)'); • % fft result • figure(2); • plot(f,Pyy(1:N/2)); • title('Frequency content of WAV'); • xlabel('Frequency (Hz)'); • % close-up • figure(3); • plot(f(50:2000),Pyy(50:2000)); • title('Frequency content of WAV'); • xlabel('frequency (Hz)');