(26-05-2022, 23:39)kaczakat napisał(a): Nawet gdybyś w przebłysku swojego geniuszu zamieścictutaj pliki biblioteki, której używasz, by ktoś mógł do niej zajrzeć, obraz przebiegu wejścia i wyjścia, ewentualny oczekiwany przebieg, to prędzej uzyskasz informacje tam skąd ją wziąłeś.Taki filtr, załącznik na samym dole
Inty są na pewno OK do zbierania danych przeliczanych we floatach? Sama biblioteka ma w sobie zmienne typu double, a tych nie ma dla Arduino z rodziny AVR - UNO/NANO/itd. Trzeba sięgnąć po uC ARM, ESP.
SampleFilter.cpp
Kod:
//SampleFilter.cpp
#include "SampleFilter.h"
static double filter_taps[SAMPLEFILTER_TAP_NUM] = {
0.001093482915112765,
0.0007173739480906833,
0.0009245034934017278,
0.0011468871783505015,
0.0013770955177285454,
0.001606379339851078,
0.0018227866655093294,
0.0020165226168445305,
0.0021705893045334407,
0.0022744427731499115,
0.0023125956249477647,
0.002270305635796323,
0.0021363872772250173,
0.001900023958439724,
0.0015528473390481572,
0.0010887462919628038,
0.0005075644316410254,
-0.00018731337549190747,
-0.0009883236254317807,
-0.0018821060852016733,
-0.002850433031890532,
-0.003869202547075428,
-0.004909465652618884,
-0.005937415094389048,
-0.006915789166175483,
-0.007804201101442141,
-0.008559301121934836,
-0.009137046220034431,
-0.0094936841603582,
-0.009587335521827549,
-0.009379122704225452,
-0.008834817073156639,
-0.007926234296599435,
-0.006632127405918286,
-0.004939825746127799,
-0.002845822099626519,
-0.000356636058600884,
0.002510639303824888,
0.005728226265430951,
0.009257979714101717,
0.013052150321083575,
0.01705380758165226,
0.02119809146010267,
0.02541361329857411,
0.029624102480451886,
0.03375034183429453,
0.0377121223078346,
0.04143038312560065,
0.04482920600127271,
0.0478380048961221,
0.05039337307949703,
0.05244070581946014,
0.05393578865223346,
0.05484610381777868,
0.05515177639176802,
0.05484610381777868,
0.05393578865223346,
0.05244070581946014,
0.05039337307949703,
0.0478380048961221,
0.04482920600127271,
0.04143038312560065,
0.0377121223078346,
0.03375034183429453,
0.029624102480451886,
0.02541361329857411,
0.02119809146010267,
0.01705380758165226,
0.013052150321083575,
0.009257979714101717,
0.005728226265430951,
0.002510639303824888,
-0.000356636058600884,
-0.002845822099626519,
-0.004939825746127799,
-0.006632127405918286,
-0.007926234296599435,
-0.008834817073156639,
-0.009379122704225452,
-0.009587335521827549,
-0.0094936841603582,
-0.009137046220034431,
-0.008559301121934836,
-0.007804201101442141,
-0.006915789166175483,
-0.005937415094389048,
-0.004909465652618884,
-0.003869202547075428,
-0.002850433031890532,
-0.0018821060852016733,
-0.0009883236254317807,
-0.00018731337549190747,
0.0005075644316410254,
0.0010887462919628038,
0.0015528473390481572,
0.001900023958439724,
0.0021363872772250173,
0.002270305635796323,
0.0023125956249477647,
0.0022744427731499115,
0.0021705893045334407,
0.0020165226168445305,
0.0018227866655093294,
0.001606379339851078,
0.0013770955177285454,
0.0011468871783505015,
0.0009245034934017278,
0.0007173739480906833,
0.001093482915112765
};
void SampleFilter_init(SampleFilter* f) {
int i;
for(i = 0; i < SAMPLEFILTER_TAP_NUM; ++i)
f->history[i] = 0;
f->last_index = 0;
}
void SampleFilter_put(SampleFilter* f, double input) {
f->history[f->last_index++] = input;
if(f->last_index == SAMPLEFILTER_TAP_NUM)
f->last_index = 0;
}
double SampleFilter_get(SampleFilter* f) {
double acc = 0;
int index = f->last_index, i;
for(i = 0; i < SAMPLEFILTER_TAP_NUM; ++i) {
index = index != 0 ? index-1 : SAMPLEFILTER_TAP_NUM-1;
acc += f->history[index] * filter_taps[i];
};
return acc;
}
SampleFilter.h
Kod:
#ifndef SAMPLEFILTER_H_
#define SAMPLEFILTER_H_
/*
FIR filter designed with
http://t-filter.appspot.com
sampling frequency: 1000 Hz
* 0 Hz - 20 Hz
gain = 1
desired ripple = 5 dB
actual ripple = 0.6420261787794526 dB
* 40 Hz - 500 Hz
gain = 0
desired attenuation = -40 dB
actual attenuation = -56.102931833558046 dB
*/
#define SAMPLEFILTER_TAP_NUM 109
typedef struct {
double history[SAMPLEFILTER_TAP_NUM];
unsigned int last_index;
} SampleFilter;
void SampleFilter_init(SampleFilter* f);
void SampleFilter_put(SampleFilter* f, double input);
double SampleFilter_get(SampleFilter* f);
#endif