fbgsense 0.1
Generic FBG spectrum analysis tool
spectrum.h
1/*
2 * This file is a part of the project "fbgsense", which is released under MIT license.
3 * Copyright (c) 2022 Daniel Múčka, Masaryk University, Faculty of Informatics
4 * See file LICENSE or visit https://opensource.org/licenses/MIT for full license details.
5 */
6
7#pragma once
8
9#include <numbers>
10#include <vector>
11#include <span>
12#include <array>
13#include <algorithm>
14
15#include <iostream>
16#include <sstream>
17#include <format>
18
19#include <fstream>
20#include <exception>
21
22#include "spectrum_types.h"
23#include "spectrum_state.h"
24#include "io/decimal_comma.h"
25#include "peak.h"
26#include "fitting.h"
27#include "linspace.h"
28#include "argmax.h"
29
30#include "filtering/filter.h"
31#include "filtering/filter_fft.h"
32#include "filtering/filter_savgol.h"
33
34#include "detection/detection_method.h"
35#include "detection/detection_method_localmax.h"
36
37#include "segmentation/segmentation_method.h"
38#include "segmentation/segmentation_method_localmin.h"
39#include "segmentation/segmentation_method_inflection.h"
40
41constexpr channel_t spectrum_max_channels = 16;
42
47{
48protected:
49 size_t m_samples{ 0 };
50 size_t m_storage{ 0 };
51
52 spectrum_unit_t* m_indices;
53 spectrum_unit_t* m_wavelengths;
54 spectrum_unit_t* m_intensities[spectrum_max_channels];
55
56 spectrum_unit_t* m_filtered_intensities[spectrum_max_channels];
57 std::span<complex_t> m_freq[spectrum_max_channels];
58 std::span<derivation_t> m_derivation[spectrum_max_channels];
59
60 minmax_t m_extremas[spectrum_max_channels];
61 std::vector<peak> m_peaks[spectrum_max_channels];
62
63 std::unique_ptr<fbgsense::filtering::filter> m_filter;
64 std::unique_ptr<fbgsense::detection::detection_method> m_detection_method;
65 std::unique_ptr<fbgsense::segmentation::segmentation_method> m_segmentation_method;
66public:
67 inline static constexpr size_t to_index(channel_t channel)
68 {
69 return channel - 1;
70 }
71
72 spectrum();
73 spectrum(size_t storage, size_t samples);
74 spectrum(size_t samples);
75 ~spectrum();
76
81 void set_filter(filter_type type);
82
87
92 void set_detection_method(detection_type type);
93
98
103 void set_segmentation_method(segment_type type);
104
109
113 spectrum_unit_t* get_wavelengths();
114
118 spectrum_unit_t* get_source_intensities(channel_t channel);
119
123 spectrum_unit_t* get_filtered_intensities(channel_t channel);
124
129
134
139
143 static channel_t get_channel_count();
144
149
153 bool is_noise(channel_t channel);
154
158 void recalculate(channel_t channel);
159
163 void filter(channel_t channel, std::initializer_list<parameter_t> params);
164
168 void detect(channel_t channel, std::initializer_list<parameter_t> params);
169
173 std::vector<region_t> segment(channel_t channel, std::initializer_list<parameter_t> params);
174
178 peak fit(channel_t channel, fit_settings_t fitSettings, region_t region);
179
184 bool perform(channel_t channel, std::initializer_list<parameter_t> filteringParams, std::initializer_list<parameter_t> detectionParams, std::initializer_list<parameter_t> segmentationParams, fit_settings_t fitSettings);
185
189 void perform(std::initializer_list<parameter_t> filteringParams, std::initializer_list<parameter_t> detectionParams, std::initializer_list<parameter_t> segmentationParams, fit_settings_t fitSettings);
190
194 void clean();
195
199 void print(std::ostream& s, std::string delimiter = "\t");
200
204 std::vector<peak> get_peaks();
205
209 std::vector<peak> get_peaks(channel_t channel);
210
214 spectrum_point_t get_spectrum_point(channel_t channel, size_t index);
215};
Data structure holding information about peak's properties.
Definition: peak.h:18
Provides support for custom computation implementations.
Definition: processor.h:17
Data structure providing access to the implemented method.
Definition: spectrum.h:47
spectrum_unit_t * get_wavelengths()
Get wavelength array. This array is shared across all intensities in the spectrum.
bool is_noise(channel_t channel)
Checks if the signal intensity is within reasonable range.
void set_detection_method(processor< fbgsense::detection::detection_method > &&type)
Set custom detection method processor.
void set_segmentation_method(segment_type type)
Set the method that will segment the spectrum into peak regions. The default method is segment_type::...
void set_detection_method(processor< fbgsense::segmentation::segmentation_method > &&type)
Set custom segmentation method processor.
void perform(std::initializer_list< parameter_t > filteringParams, std::initializer_list< parameter_t > detectionParams, std::initializer_list< parameter_t > segmentationParams, fit_settings_t fitSettings)
Perform every step of calculation for all channels.
peak fit(channel_t channel, fit_settings_t fitSettings, region_t region)
Fit a function on the specified dataset using least squares technique.
void clean()
Clear found peaks.
minmax_t get_wavelength_bounds()
Get lowest and highest wavelength value.
void recalculate(channel_t channel)
Find global extremas.
std::vector< region_t > segment(channel_t channel, std::initializer_list< parameter_t > params)
Find peak regions of interest (ROI).
std::vector< peak > get_peaks(channel_t channel)
Get peaks of specific channel.
void print(std::ostream &s, std::string delimiter="\t")
Print peaks to the specified stream.
void filter(channel_t channel, std::initializer_list< parameter_t > params)
Filtering process.
spectrum_unit_t * get_filtered_intensities(channel_t channel)
Get filtered intensities array for the specified channel.
size_t get_samples_count()
Get number of samples.
void set_filter(processor< fbgsense::filtering::filter > &&type)
Set custom filtering processor.
bool perform(channel_t channel, std::initializer_list< parameter_t > filteringParams, std::initializer_list< parameter_t > detectionParams, std::initializer_list< parameter_t > segmentationParams, fit_settings_t fitSettings)
Perform every step of calculation on the specific channel.
void detect(channel_t channel, std::initializer_list< parameter_t > params)
Peak detection process.
void set_filter(filter_type type)
Set the filter that will remove noise from the spectrum. The default is filter_type::FFT.
spectrum_unit_t * get_source_intensities(channel_t channel)
Get source intensities array for the specified channel.
void set_detection_method(detection_type type)
Set the detection method that will find potential peaks. The default method is detection_type::LOCAL_...
spectrum_point_t get_spectrum_point(channel_t channel, size_t index)
Get a single point from spectrum channel in form of a tuple.
spectrum_state get_spectrum_state(channel_t channel)
Get internal data structures for the given channel.
std::vector< peak > get_peaks()
Get flattened list of peaks.
size_t get_storage_size()
Get size of physical storage array.
static channel_t get_channel_count()
Get number of channels.
Definition: spectrum_types.h:67
Definition: spectrum_types.h:24
Definition: peak.h:44
Definition: spectrum_types.h:18
Data structure reflecting spectrum's current state. Used in processors.
Definition: spectrum_state.h:19