pt1 bug gefixed und alternative farbschemas eingestellt

This commit is contained in:
Alexander Alber 2022-06-26 23:06:21 +02:00
parent 46dcbd5e1e
commit bdab2c30fe
4 changed files with 27 additions and 36 deletions

View File

@ -9,7 +9,7 @@ struct Pt1
/* PT1: y = y_(n-1) + (Ku - y_(n-1)) * dt/T1 */ /* PT1: y = y_(n-1) + (Ku - y_(n-1)) * dt/T1 */
Pt1(T K, T T1) : T1(T1), K(K){}; Pt1(T K, T T1) : T1(T1), K(K){};
Pt1() = default;
T update(T u, T dt) T update(T u, T dt)
{ {
T y = this->y_n1 + (this->K * u - this->y_n1) * dt / this->T1; T y = this->y_n1 + (this->K * u - this->y_n1) * dt / this->T1;

View File

@ -12,9 +12,9 @@
#define SAMPLING_FREQUENCY_CONTROL \ #define SAMPLING_FREQUENCY_CONTROL \
1 // check number of times per second if the current band pass is the best 1 // check number of times per second if the current band pass is the best
// one // one
#define Q 20. // quality factor of band pass filters #define Q 30. // quality factor of band pass filters
#define PI 3.1415926535897932384626433832795 #define PI 3.1415926535897932384626433832795
#define n_BP 30 // number of band pass filters #define n_BP 40 // number of band pass filters
static const unsigned long sampling_period_bp = 1000000L / SAMPLING_FREQUENCY_BP; static const unsigned long sampling_period_bp = 1000000L / SAMPLING_FREQUENCY_BP;
static const unsigned long sampling_period_control = 1000000L / SAMPLING_FREQUENCY_CONTROL; static const unsigned long sampling_period_control = 1000000L / SAMPLING_FREQUENCY_CONTROL;
@ -23,7 +23,7 @@ static unsigned long last_us_bp = 0L;
static unsigned long last_us_control = 0L; static unsigned long last_us_control = 0L;
static Biquad<float> bp_filters[n_BP]; static Biquad<float> bp_filters[n_BP];
static Pt1<float> y_filter{1.f, 1.f}; static Pt1<float> y_filter[n_BP];
static Pt1<float> pos_filter{1.f, 1.f}; static Pt1<float> pos_filter{1.f, 1.f};
static float yy1[n_BP]; static float yy1[n_BP];
@ -78,6 +78,7 @@ set_filter()
a1 = -2.f * cos(w0); a1 = -2.f * cos(w0);
a2 = 1.f - a; a2 = 1.f - a;
bp_filters[i] = Biquad<float>{a0, a1, a2, b0, b1, b2}; bp_filters[i] = Biquad<float>{a0, a1, a2, b0, b1, b2};
y_filter[i] = Pt1<float>{1.f, 1.f};
} }
} }
@ -128,10 +129,13 @@ void BeatDetectApp::loop()
yy3[i] = yy2[i]; yy3[i] = yy2[i];
yy2[i] = yy1[i]; yy2[i] = yy1[i];
yy1[i] = y[i]; yy1[i] = y[i];
y_fil[i] = y_filter.update(std::abs(y[i]), y_fil[i] = y_filter[i].update(std::abs(y[i]),
0.005f); // linie der scheitelpunkte 0.005f); // linie der scheitelpunkte
// y_fil[i] += (abs(y[i]) - y_fil[i]) * 0.005; //linie der // y_fil[i] += (abs(y[i]) - y_fil[i]) * 0.005; //linie der
// scheitelpunkte // scheitelpunkte
} }
@ -181,12 +185,14 @@ void BeatDetectApp::loop()
for (int i = 0; i < NUM_LEDS; i++) for (int i = 0; i < NUM_LEDS; i++)
{ {
leds[i].g = get_value(i, pos_target_filtered); //leds[i].g = get_value(i, pos_target_filtered);
leds[i].r = get_value(i, pos_target_filtered + 2); //leds[i].r = get_value(i, pos_target_filtered + 2);
//leds[i].b = get_value(i, pos_target_filtered - 2);
leds[i].g = get_value(i, pos_target_filtered + 2);
leds[i].r = 0;//get_value(i, pos_target_filtered + 2);
leds[i].b = get_value(i, pos_target_filtered - 2); leds[i].b = get_value(i, pos_target_filtered - 2);
// leds[i].setRGB(brightness_red, brightness_green, brightness_blue);
// leds[i].setHSV(160, (rounds == 6) ? 0xFF : 0, brightness);
} }
FastLED.show(); FastLED.show();
} }
@ -205,22 +211,16 @@ void BeatDetectApp::loop()
} }
} }
if (argmax > -1) if (argmax != active)
{
if (argmax == candidate)
{ {
rounds ++; rounds ++;
} }
else
if (rounds > 5)
{ {
active = argmax;
rounds = 0; rounds = 0;
candidate = argmax;
}
if (rounds > 3)
{
rounds = 0;
active = candidate;
}
} }
} }
} }

View File

@ -95,7 +95,8 @@ void FackelApp::init()
for (int i = 0; i < 128; i++) for (int i = 0; i < 128; i++)
{ {
uint8_t r, g, b; uint8_t r, g, b;
hsl_to_rgb(i / 5, 255, i * 2 > 128 ? 128 : i * 2, &r, &g, &b); //hsl_to_rgb(i / 5, 255, i * 2 > 128 ? 128 : i * 2, &r, &g, &b);
hsl_to_rgb(i / 5 + 180, 255, i * 2 > 128 ? 128 : i * 2, &r, &g, &b);
g = g == 1 ? 0 : g; g = g == 1 ? 0 : g;
b = b == 1 ? 0 : b; b = b == 1 ? 0 : b;
palette[i].r = r; palette[i].r = r;

View File

@ -22,10 +22,6 @@ std::vector<std::reference_wrapper<App>> apps = {
std::ref<App>(fackel_app) std::ref<App>(fackel_app)
}; };
<<<<<<< HEAD
unsigned int current_app = 1;
unsigned int next_app;
=======
static unsigned int current_app = 0; static unsigned int current_app = 0;
static unsigned int next_app; static unsigned int next_app;
static bool init_successfull = false; static bool init_successfull = false;
@ -55,20 +51,14 @@ void switch_app() {
next_app = next_app % apps.size(); next_app = next_app % apps.size();
} }
>>>>>>> update main app handling to include an off state
void setup() void setup()
{ {
next_app = current_app; next_app = current_app;
<<<<<<< HEAD
zauberstab_init();
//Serial.begin(115200);
=======
if (zauberstab_init() != 0) { if (zauberstab_init() != 0) {
return; return;
} }
Serial.begin(115200); Serial.begin(115200);
>>>>>>> update main app handling to include an off state
init_successfull = true; init_successfull = true;
apps[current_app].get().init(); apps[current_app].get().init();