powerSpectralDensity.m 2.07 KB
Newer Older
1
2
function psdVals = powerSpectralDensity(array, betaWindow)
% POWERSPECTRALDENSITY computes the power-spectral-density (PSD) of a given array.
Leon Merten Lohse's avatar
Leon Merten Lohse committed
3
%
4
%    ``psdVals = powerSpectralDensity(array, beta_window)``
Leon Merten Lohse's avatar
Leon Merten Lohse committed
5
%
mtoeppe's avatar
mtoeppe committed
6
% Note that prior to the Fourier transform, the array is weighted with a Kaiser-Bessel window
mtoeppe's avatar
mtoeppe committed
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
% in order to avoid truncation errors.
%
% Parameters
% ----------
% array : numerical array
%     array of which the PSD is computed
% betaWindow : number, optional
%     non-negative number that determines the shape of the Kaiser-Bessel-window;
%     values <= 0 omit the windowing-operation; default = 8
%
% Returns
% -------
% psdVals : numerical array
%     array containing the computed PSD
% 
mtoeppe's avatar
mtoeppe committed
22
23
% Example
% -------
mtoeppe's avatar
mtoeppe committed
24
25
26
27
28
29
30
31
32
%
% .. code-block:: matlab
%
%     % PSD of a disk (should yield an Airy-disk)
%     N = [128,128];
%     r_disk = 10;
%     im = fspecial('disk', r_disk);
%     im = padarray(padarray(im, ceil((N-size(im))/2), 0, 'pre'), floor((N-size(im))/2), 0, 'post');
%     figure('name', 'image'); showImage(im)
33
%     figure('name', 'Log(PSD(image))'); showImage(log(powerSpectralDensity(im)))
Leon Merten Lohse's avatar
Leon Merten Lohse committed
34

mtoeppe's avatar
mtoeppe committed
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
% HoloTomoToolbox
% Copyright (C) 2019  Institut fuer Roentgenphysik, Universitaet Goettingen
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program.  If not, see <http://www.gnu.org/licenses/>.
Leon Merten Lohse's avatar
Leon Merten Lohse committed
50

mtoeppe's avatar
mtoeppe committed
51
52
53
if (nargin < 2)
    betaWindow = 8;
end
Leon Merten Lohse's avatar
Leon Merten Lohse committed
54

mtoeppe's avatar
mtoeppe committed
55
56
57
58
% Optionally weight array with Kaiser-Bessel-window to avoid truncation errors
if betaWindow > 0
    array = array .* kaiserBesselWindow(size(array), betaWindow);
end
Leon Merten Lohse's avatar
Leon Merten Lohse committed
59

mtoeppe's avatar
mtoeppe committed
60
61
% Compute power spectral density
psdVals = fftshift(abs(fftn(array)).^2);
Leon Merten Lohse's avatar
Leon Merten Lohse committed
62
63

end