SP2 = spec2f(F) returns a structure SP2 containing the 2D power
spectrum of the vector or scalar field(s) F. If F is an array of
fields, the average spectrum is returned.
SP2 = spec2f(F,'hann') applies a Hann (or Hanning) apodization window
to the fields along each direction in order to reduce aliasing. Note
that, in this case, energy is not conserved (the amount of energy
lost in the apodization is about 60%, but the exact value depends on
the details of the energy distribution).
The X and Y dimensions of the fields must be even. If one of the
dimension is odd, the last column/row is discarded.
spec2f(F,...,'disp') displays the 1D (azimuthally-averaged) power
spectrum - works only if F is defined on a square domain. If not, use
truncf (truncation) or zeropadf (zero padding) first.
Use the syntax SP2 = spec2f(F, ..., 'disp2d'), or spec2f(F, ...) without
output argument, to also display the 2D spectrum in the plane (kx,ky).
spec2f(F,...,'Property1','Property2',...) specifies the following
properties:
'circle ' also displays circles (to test the isotropy of 2D power spectra).
'contour' displays iso-contour of the spectrum
'contourf' displays filled iso-contours of spectrum
'linear' displays the spectrum in linear scale (log by default)
After the property 'contour' or 'contourf', it is possible to specify
the logarithmic step between each countour line. Default step is 1,
i.e. the contour lines are speced by a factor of 10.
spec2f(SP2) displays the spectrum, where SP has been previously computed
using SP2 = spec2f(...). If SP2 is a structure array, loops over all spectra
(press a key between each display).
For vector field(s), the structure SP contains:
kx,ky: wavenumbers along x and y
ex: 2D power spectrum of F_x
ey: 2D power spectrum of F_y
ez: 2D power spectrum of F_z (for 3-component fields only)
e: 2D power spectrum (sum of the p.s. of F_x, F_y, and F_z)
ep: 1D azimuthally averaged power spectrum
k: wavenumber
unitk: unit of wavenumber
unite: unit of power spectrum (energy density)
appod: Apodization window ('Hann' or 'None')
nfields: number of fields used in the computation
history: remind from which field specf has been called.
For scalar field(s), the structure SP contains:
kx,ky: wavenumbers along x and y
e: 2D power spectrum
k: wavenumber
ep: 1D azimuthally averaged power spectrum
unitk: unit of wavenumber
unite: unit of power spectrum (energy density)
appod, nfields, history: idem as for vector fields
The unit for the wavenumber is the inverse of the unit for the spatial
scale (e.g. in 1/mm). The length of the spectrum is half the length of
the field. Some properties:
sp2.k(1) is always 0 (zero mode = mean component of the field)
sp2.k(2) is the wavenumber increment, Delta k = 2*pi/L, where L is the
size of the field.
sp2.k(end) is pi/dx, where dx is the mesh size of the field.
The unit for the spectra is given by the unit of
the input field squared, times the unit of scale. For instance, for a
velocity field given in m/s with spatial scale in mm, the unit for the
spectra is (m^2/s^2)*mm, i.e. (m^3/s^2)/1000.
Example
v=loadvec('*');
sp2=spec2f(truncf(v),'hann');
spec2f(sp2,'disp2d');
Energy Conservation (Parseval theorem)
For a scalar field, energy conservation requires that
SUM(SP2.EX(:))*SP2.KX(2) = SUM(SP.EY(:))*SP.KY(2) = MEAN(F.W(:).^2)
and, if the field is square with equal scales along X and Y:
SUM(SP2.E(:))*SP.K(2) = MEAN(F.W(:).^2)
Relations between 1D and 2D spectra:
Two ways of computing the 1D spectrum along x of u_x:
v = loadvec('*');
u = vec2scal(v,'ux');
sp = specf(u); % 1D spectrum of u_x
sp2 = spec2f(u); % 2D spectrum of u_x
int_spx = sum(sp2.e,1); % sum of the 2D spec. along x
loglog(sp.k, sp.ex, 'ro', sp2.k, 2*int_spx(end/2+1:end), 'b');
See Also
specf, statf, vsf, ssf, truncf, zeropadf, corrf.
Published output in the Help browser
showdemo spec2f