24 #include "3rdparty/dspfilters/ChebyshevI.h" 25 #include "3rdparty/dspfilters/ChebyshevII.h" 26 #include "3rdparty/kissfft/kiss_fftr.h" 27 #include "3rdparty/chebyshev_polynomial.hpp" 28 #include "3rdparty/dtw.h" 30 #include <MCTypes.hpp> 50 if (container1.size() == 0 || container2.size() == 0)
53 MC::DoubleList Input1;
54 MC::DoubleList Input2;
55 dtw Dtw(container1.size(), 1);
57 for (
int i = 0; i < (int)container1.size(); ++i)
58 Input1.push_back(container1[i]);
59 for (
int i = 0; i < (int)container2.size(); ++i)
60 Input2.push_back(container2[i]);
62 return Dtw.fastdynamic(Input1, Input2);
79 double start_x,
double end_x)
81 if (container.size() == 0)
82 return MC::FloatList();
84 double* Coefficients =
nullptr;
85 int ContainerSize = container.size();
86 MC::FloatList Results;
88 double* Vector =
nullptr;
90 for (
int i = 0; i < (int)container.size(); ++i)
91 Input.push_back(container[i]);
92 Vector = r8vec_linspace_new(ContainerSize, start_x, end_x);
93 Coefficients = t_project_coefficients_data(start_x, end_x, ContainerSize, coefficients_count-1,
95 for (
int i = 0; i < coefficients_count; ++i)
97 Results.push_back((
float)Coefficients[i]);
99 delete[] Coefficients;
116 template <
typename U,
typename V>
118 double start_x,
double end_x)
120 MC::FloatTable NewTable;
122 for (
int i = 0; i < (int)table.size(); ++i)
124 NewTable.push_back(MAChebyshevPolyCoeffFromContainer<U>(table[i], coefficients_count, start_x, end_x));
139 template <
typename U>
142 if (container.size() == 0)
144 MC::FloatTable TempTable;
146 TempTable.push_back(MC::FloatList());
147 TempTable.push_back(MC::FloatList());
150 int ContainerSize = container.size();
151 MC::FloatTable Results;
152 MC::FloatList Amplitudes;
153 MC::FloatList Radians;
154 kiss_fft_scalar InputVector[ContainerSize];
155 kiss_fft_cpx OutputVector[ContainerSize / 2+1];
156 kiss_fftr_cfg Config;
159 for (
int i = 0; i < ContainerSize; i++)
160 InputVector[i] = (kiss_fft_scalar)container[i];
162 Config = kiss_fftr_alloc(ContainerSize, 0,
nullptr,
nullptr);
165 kiss_fftr(Config, InputVector, OutputVector);
168 for (
int i = 0; i < ContainerSize / 2+1; i++)
170 Amplitudes.push_back((
float)sqrt(OutputVector[i].r*OutputVector[i].r+OutputVector[i].i*OutputVector[i].i));
171 Radians.push_back((
float)atan2(OutputVector[i].i, OutputVector[i].r));
174 Results.push_back(Amplitudes);
175 Results.push_back(Radians);
189 template <
typename U,
typename V>
192 MC::FloatTable NewTable;
194 for (
int i = 0; i < (int)table.size(); ++i)
196 MC::FloatTable TempTable = MAFFTComponentsFromContainer<U>(table[i]);
198 NewTable.push_back(TempTable[0]);
199 NewTable.push_back(TempTable[1]);
217 template <
typename T,
typename U,
int order>
219 float ripple_db = 0.0873)
221 if (container.size() == 0)
224 Dsp::SimpleFilter<Dsp::ChebyshevI::HighPass<order>, 1> HighPassFilter;
226 const int BufferSize = 512;
227 float* ValueBuffer[1];
229 ValueBuffer[0] =
new float[BufferSize];
230 HighPassFilter.setup(order,
234 int DataSize = container.size();
235 int CurrentIndex = 0;
237 while (CurrentIndex <= DataSize-1)
239 int CurrentSliceSize = DataSize-CurrentIndex > BufferSize ? BufferSize : DataSize-CurrentIndex;
242 for (
int i = 0; i < CurrentSliceSize; ++i)
244 ValueBuffer[0][i] = (float)container[CurrentIndex+i];
246 HighPassFilter.process(BufferSize, ValueBuffer);
247 for (
int i = 0; i < CurrentSliceSize; ++i)
249 NewContainer.push_back((T)ValueBuffer[0][i]);
251 CurrentIndex += CurrentSliceSize;
269 template <
typename T,
typename U,
typename V,
int order>
271 float ripple_db = 0.0873)
275 for (
int i = 0; i < (int)table.size(); ++i)
277 NewTable.push_back(MAHighPassFilterToContainer<T, U, order>(table[i], sample_rate, cut_off_freq, ripple_db));
U MAHighPassFilterToContainer(const U &container, int sample_rate=125, float cut_off_freq=12.5, float ripple_db=0.0873)
Calculate a high pass filter over a container.
MC::FloatList MAChebyshevPolyCoeffFromContainer(const U &container, int coefficients_count, double start_x, double end_x)
Calculate Chebyshev polynomial coefficients over a container.
MC::FloatTable MAFFTComponentsFromContainer(const U &container)
Calculate FFT components over a container.
MC::FloatTable MAChebyshevPolyCoeffFromTable(const V &table, int coefficients_count, double start_x, double end_x)
Calculate Chebyshev polynomial coefficients over table rows.
MC::FloatTable MAFFTComponentsFromTable(const V &table)
Calculate FFT components over table rows.
float MADynamicTimeWarping(const U &container1, const U &container2)
Calculate dynamic time warping similarity between two containers.
V MAHighPassFilterToTable(const V &table, int sample_rate=125, float cut_off_freq=12.5, float ripple_db=0.0873)
Calculate a high pass filter over table rows.