%program for calculation spectr with Matlab fft function
%Copyright BVV 26.4 2000 e-mail root@krascience.rssi.ru
function [a,b,om]=spectr(f,T,N)
s=size(f);
N1=max(s);
if N1~=N
error('size of first argument for spectr must be equals to third argument');
end
N2=min(s);
if N2 ~= 1
error('first argument must be one-dimensional for spectr');
end
p=log(N)/log(2);
if abs(p-round(p))>eps
error('N must be pow of 2 for function spectr');
end
fq=fft(f);
q=0:N/2;
a(1)=fq(1)/N;
a(N/2+1)=fq(N/2+1)/N;
a(2:N/2)=2*real(fq(2:N/2))/N;
b(1)=0;
b(2:N/2)=-2*imag(fq(2:N/2))/N;
b(N/2+1)=0;
om=q/T;
