-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcorrectRaman.m
More file actions
57 lines (40 loc) · 1.57 KB
/
correctRaman.m
File metadata and controls
57 lines (40 loc) · 1.57 KB
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
56
57
function [outputObject] = correctRaman( x, y, pMax)
includeFolders = genpath('include');
addpath( includeFolders );
x = x(:);
y = y(:);
% Precomputed wavelet filters
prefilters = load('./include/wavelets/prefilters.mat');
waveletStruct = prefilters.waveletStruct;
wnames = fieldnames( waveletStruct );
nWavelets = length( wnames );
optimalP = zeros( nWavelets, 1);
costFunValues = Inf( nWavelets, 1);
nMax = 20;
pInit = pMax - 2;
for ii = 1:nWavelets
wname_ii = wnames{ii};
filters_ii = waveletStruct.( wname_ii );
bgMatrix_ii = computeBackgroundMatrix( y, filters_ii, nMax);
optFun_ii = @(p) spectrumNorm( y, p, bgMatrix_ii, pMax);
[ optP_ii, val_ii] = fminsearch( optFun_ii, pInit);
optimalP(ii) = optP_ii;
costFunValues(ii) = val_ii;
end
[ ~, ind] = min( costFunValues );
optimizedP = optimalP(ind);
optimizedWavelet = wnames{ind};
filters = waveletStruct.( optimizedWavelet );
bgMatrix = computeBackgroundMatrix( y, filters, nMax);
background = returnBackground( 0, optimizedP, bgMatrix);
correctedSpectrum = y - background;
minOptS = min( correctedSpectrum );
correctedSpectrum = correctedSpectrum - minOptS;
outputObject = {};
outputObject.x = x;
outputObject.y = y;
outputObject.background = background + minOptS;
outputObject.correctedSpectrum = correctedSpectrum;
outputObject.optimizedP = optimizedP;
outputObject.optimizedWavelet = optimizedWavelet;
end