-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathturbint.m
55 lines (47 loc) · 1.51 KB
/
turbint.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
%% Calculates Energy in a given frame (e.g. krho=[2,50]) as an estimate of
%% turbulence intensity
%%
%%
%% Input:
%% x: vector or matrix (same size as PSD) with x values for PSD
%% PSD: power spectral density for variable x
%% snr: signal to noise ratio as matrix with same size as PSD
%% snrthres: threshold at which signal is believed to be swamped by noise
%%
%% date: 19.02.2014
function E=turbint(x,PSD,frame,snr,snrthres)
if nargin<5, snrthres=5; end
if nargin<4, snr=5*ones(size(PSD)); end
%% Check sizes of vectors, matrices
a=size(x);
b=size(PSD);
% for i=1:length(b)
% ja=find(a==b(i));
% end
% for i=1:length(a)
% jb=find(b==a(i));
% end
% if ja==1, x=x'; end
% if jb==1, PSD=PSD'; end
%% Calculate Turbulence Intensity
% If x is the same for all PSD it's easy
if min(a)==1
for i=1:b(1)
j=[find(x>min(frame),1,'first'):...
min([find(snr(i,:)<snrthres,1,'first') find(x>max(frame),1,'first')])-1];
E(i)=nanmean(PSD(i,j)./PSD(1,j));
end
% If not, we must first interpolate to common grid xi
else
xi=logspace(log10(min(frame)),log10(max(frame)),10);
for i=1:b(1)
j=[find(x(i,:)>min(frame),1,'first'):...
min([find(snr(i,:)<snrthres,1,'first') find(x(i,:)>max(frame),1,'first')])-1];
if length(x(i,j))<2
p(i,:)=NaN*ones(1,length(xi));
else
p(i,:)=interp1(x(i,j),PSD(i,j),xi);
end
E(i)=nanmean(p(i,:)./p(1,:));
end
end