-
Notifications
You must be signed in to change notification settings - Fork 31
/
fftaxis1D.m
56 lines (53 loc) · 1.69 KB
/
fftaxis1D.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
function [fax,selekt,lax]=fftaxis1D(sig,nfft,physl)
% [fax,selekt,lax]=fftaxis1D(sig,nfft,physl)
%
% Returns a vector of physical frequencies suitable to interpret the
% Fourier transform of a real or complex one-dimensional time-series.
% If the signal is real, the axis goes from 0 to <f_N, the Nyquist
% frequency, whereas if it is complex, it goes from 0 to <twice that (as
% an alternative to going from -f_N to f_N). The wavelengths go, not from
% the impractical infinity, but from the inverse of the Rayleigh
% frequency, i.e. the physical length of the signal, to <1/f_N.
%
% INPUT:
%
% sig A vector (time series) with signal values, real or complex
% nfft The number of frequencies requested
% physl The physical length scale of the entire signal, in UNIT
%
% OUTPUT:
%
% fax Physical frequency axis, in UNIT^{-1}
% selekt Index vector to pick out the non-redundant portions
% lax Physical wavelength axis, in UNIT
%
% EXAMPLE:
%
% Use without FFTSHIFT, as in:
%
% nfft=256; s=rand(nfft,1); [fax,selekt]=fftaxis1D(s,nfft,1);
% S=abs(fft(s-mean(s),nfft)).^2; plot(fax,log10(S(selekt)))
%
%% The "complete" axis is again, for a power-of-two signal
% [fax ; -flipud(fax(2:end-1))]
%
% The equivalence of FFTAXIS1D and KNUM2 is explicit:
% N=256;
% [fax,selekt]=fftaxis1D(rand(N,1),N,N-1);
% [K,kx]=knum2([2 N],[2 N]-1);
% fx=-fliplr(indeks(kx,selekt)/2/pi);
% difer(fx(:)-fax(:))
%
% SEE ALSO: KNUM2
%
% Last modified by fjsimons-at-alum.mit.edu, 03/19/2019
xsint=physl/(length(sig)-1);
if isreal(sig)
selekt = [1:floor(nfft/2)+1];
else
selekt = 1:nfft;
end
fax = (selekt - 1)'/xsint/nfft;
warning off MATLAB:divideByZero
lax=1./fax; lax(1)=physl;
warning on MATLAB:divideByZero