-
Notifications
You must be signed in to change notification settings - Fork 3
/
blurcheck.m
53 lines (50 loc) · 1.7 KB
/
blurcheck.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
function blurcheck(Sbar,params)
% BLURCHECK(Sbar,params)
%
% Performs a check on the blurring of a spectral matrix. Checks Hermiticity
% in the univariate case, when Sbar is a column of length prod(params.NyNx),
% and the eigenvalues of Sbar for being real and positive in the bivariate
% case, in which case Sbar has dimensions prod(params.NyNx)-by-3.
%
% INPUT:
%
% Sbar The unwrapped blurred spectral matrix being checked
% For univariate spectra, it's a column vector.
% For bivariate spectra, it's [S_XX(k(:)) SXY(k(:)) SYY(k(:))]
% params Parameters of this experiment, the ones that are needed are:
% NyNx number of samples in the y and x directions
%
% Last modified by fjsimons-at-alum.mit.edu, 06/20/2018
% Target dimensions, the original ones
NyNx=params.NyNx;
% Uni-variate case
if size(Sbar,2)==1
% Check Hermiticity
hermcheck(reshape(Sbar,NyNx));
end
% Bi-variate case
if size(Sbar,2)==3
% Number of random tries
ntry=10;
for kindex=1:ntry
% Some random wavenumber entry
kk=max(round(rand*prod(NyNx)),1);
% Check the eigenvalues of the little matrix at that wavenumber
egos=eig([Sbar(kk,1) Sbar(kk,2) ; Sbar(kk,2) Sbar(kk,3)]);
if ~all(egos>0)
disp(sprintf('%s: some NEGATIVE eigenvalues',upper(mfilename)))
end
if ~isreal(egos)
disp(sprintf('%s: some IMAGINARY eigenvalues',upper(mfilename)))
cpxity(kindex)=100*mean(abs(imag(egos(:))))./mean(abs(real(egos(:))));
end
end
% Attempt a brief report
try
disp(sprintf(...
'%s: maximum IM/RE percentage out of %i tried is %5.0e%s',...
upper(mfilename),ntry,max(cpxity),'%'))
catch
%disp(sprintf('%s: no problems found',upper(mfilename)))
end
end