function powerspec(t,v) N = length(v); T = t(end); p = abs(fft(v))/(N/2); p = p(1:N/2).^2; % positive half only freq = [0:N/2-1]/T; % frequency range in Hz plot(freq,p); %semilogy(freq,p)