Skip to content

Instantly share code, notes, and snippets.

@dhda
dhda / plotFFT.m
Created March 13, 2012 03:47
Matlab FFT plotting function
function [f, X, peaks, locs] = plotFFT( t, x, p )
Fs = 1 / mean(abs(t(2:end) - t(1:end-1)));
%n = 2^nextpow2(length(x));
n = length(x);
X = fft(x-mean(x), n) / length(x);
f = 0.5*Fs * linspace(0, 1, ceil(0.5*n+1));
X = X(1:ceil(0.5*n+1));
mX = abs(X);