-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEMSC_test.m
More file actions
52 lines (43 loc) · 1.68 KB
/
Copy pathEMSC_test.m
File metadata and controls
52 lines (43 loc) · 1.68 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
%% EMSC_test - Generate synthetic scatter-affected spectra for EMSC.
% Creates spectra with multiplicative scatter, polynomial baseline effects,
% and measurement noise around a known reference spectrum.
% Use as demo data for the EMSC GUI.
%
% Output variables:
% spectra - 30x600 matrix (samples x wavelengths)
% wavelength - 1x600 vector (nm)
% reference - 1x600 known reference spectrum for custom-reference mode
%
% Author: Lovelace's Square
% Date Created: 2026-07-20
% License: MIT
% Reviewed by Lovelace's Square: Yes
% Version: v 1.0
rng(42);
nSamples = 30;
nChannels = 600;
wavelength = linspace(1000, 2400, nChannels);
x = linspace(-1, 1, nChannels);
gauss = @(center, height, width) height .* ...
exp(-0.5 .* ((wavelength - center) ./ width).^2);
% Known spectrum used to create and validate the synthetic samples.
reference = 0.35 + ...
gauss(1120, 0.65, 45) + ...
gauss(1380, 0.95, 65) + ...
gauss(1700, 0.75, 50) + ...
gauss(1980, 1.10, 70) + ...
gauss(2220, 0.80, 55);
spectra = zeros(nSamples, nChannels);
for s = 1:nSamples
multiplier = 0.70 + 0.60 * rand();
baseline = (0.04 * randn()) + ...
(0.10 * randn()) .* x + ...
(0.06 * randn()) .* x.^2;
noise = 0.018 * randn(1, nChannels);
spectra(s, :) = multiplier .* reference + baseline + noise;
end
clearvars -except spectra wavelength reference
fprintf('Created: spectra (%dx%d), wavelength (1x%d), reference (1x%d)\n', ...
size(spectra, 1), size(spectra, 2), length(wavelength), length(reference));
fprintf('Contains multiplicative scatter, polynomial baseline effects, and noise.\n');
fprintf('Run EMSC(spectra) and select reference as a custom reference if needed.\n');