-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnorm_spec.asv
30 lines (24 loc) · 1.14 KB
/
norm_spec.asv
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
function [specNorm] = norm_spec(specSet,truncIDx)
% Normalizes spectra by subtracting the slope between specified truncation
% indices (truncIDx), setting max amplitude to 1 and min amplitude to 0.
% Inputs:
% specSet: An nxf matrix of detection spectra, where n is the number of
% spectra, and f is the number of frequencoes at which the spectra are
% evaluated.
% truncIdx: A 2 element vector containing the indices [low, high]between which to
% compute and subtract the spectral slope, and to truncate the spectra.
% Outputs:
% specNorm: An nxm matrix of detection spectra, where n is the number of
% spectra, and m is the number of frequencoes at which the spectra are
% evaluated between truncIdx(1) and truncIdx(2).
specSetTrunc = specSet(:, truncIDx(1):truncIDx(2));
alphaVec = specSetTrunc(:,end) - specSetTrunc(:,1);
slopeMat = zeros(size(specSetTrunc));
interpVal = size(specSetTrunc,2) - 1;
for it0 = 1:length(alphaVec)
slopeMat(it0,:) = 0:alphaVec(it0)/interpVal:alphaVec(it0);
end
specSlopeNorm = specSetTrunc - slopeMat;
specMean = nanmean(specSlopeNorm);
specNormMin = specMean - min(specMean);
specNorm = specNormMin./max(specNormMin);