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.
clear all; close all; % %This script plots the frequency spectrum of a wave file. %This method of plotting the frequency spectrum is modeled after the %example on 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; if rem(N, 2) % odd nfft excludes Nyquist point P(2:end) = P(2:end)*2; else P(2:end -1) = P(2:end -1)*2; end f = (0:NumUniquePts-1)*Fs/N; plot(f,P); title(sprintf('Power Spectrum of a wave file')); xlabel('Frequency Hz'); ylabel('|H(f)|'); grid; print(gcf, '-dpdf', '-r600', 'images/matlab_e52_1');