How to Plot fft of ascii values in MATLAB? -
i have ascii file containing 2048 x , y value pairs. want know how plot fft of y in matlab. writing following matlab code not able find appropriate result.
how can this? have tried:
i = load('data1.asc'); = 1:2048 y = i(:,2); end plot(x) fs = 40000; t = 1/fs; l = 2000; nfft = 2^nextpow2(l); y = abs(fft(y,nfft))/l; f = fs/2*linspace(0,1,nfft/2+1); figure, plot(f,2*abs(y(1:nfft/2+1))) axis([0 40000 0 40]) xlabel('frequency (hz)') ylabel('|y(f)|')
instead of diving straight matlab's fft routine should instead consider using periodogram function. when people "fft" usual mean psd or periodogram, i.e. plot of power spectral density using suitably windowed , ffted sample. periodogram function in matlab takes care of details of you, i.e. applying window function, calculating fft, deriving magnitude fft output, appropriate scaling of axes, , plotting if required.
note: periodogram
in matlab signal processing toolbox - if not have access can either consider using octave (free matlab clone) has periodogram
clone, otherwise need put various building blocks yourself:
- window function
- fft
- calculate magnitude
- take scare of scaling of freq , magnitude values
- plot psd
Comments
Post a Comment