mirror of
https://github.com/radio95-rnt/fm95.git
synced 2026-02-27 03:23:54 +01:00
man github.dev is better than that, but tilt doesn't work
This commit is contained in:
22
filter/iir.c
22
filter/iir.c
@@ -15,22 +15,22 @@ inline float apply_preemphasis(ResistorCapacitor *filter, float sample) {
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tilt_init(TiltCorrectionFilter* filter, float alpha) {
|
void tilt_init(TiltCorrectionFilter* filter, float correction_strength) {
|
||||||
// Allow correction_strength > 1.0 for aggressive correction
|
filter->alpha = 0.9999f;
|
||||||
filter->alpha = 0.9999f; // Fixed time constant for DC tracking
|
filter->gain = correction_strength; // Can be > 1.0
|
||||||
filter->gain = alpha; // Separate gain parameter
|
filter->x_prev = 0.0f;
|
||||||
filter->dc_estimate = 0.0f;
|
filter->y_prev = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
float tilt(TiltCorrectionFilter* filter, float input) {
|
float tilt(TiltCorrectionFilter* filter, float input) {
|
||||||
// Track the baseline/DC level
|
// High-pass filter
|
||||||
filter->dc_estimate = filter->alpha * filter->dc_estimate + (1.0f - filter->alpha) * input;
|
float hp_out = filter->alpha * (filter->y_prev + input - filter->x_prev);
|
||||||
|
|
||||||
// Calculate the deviation from baseline
|
// Apply gain and add back to original
|
||||||
float deviation = input - filter->dc_estimate;
|
float output = input + filter->gain * hp_out;
|
||||||
|
|
||||||
// Apply correction gain and add back to baseline
|
filter->x_prev = input;
|
||||||
float output = filter->dc_estimate + deviation * filter->gain;
|
filter->y_prev = hp_out;
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
@@ -15,7 +15,8 @@ float apply_preemphasis(ResistorCapacitor *filter, float sample);
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
float alpha;
|
float alpha;
|
||||||
float dc_estimate;
|
float x_prev;
|
||||||
|
float y_prev;
|
||||||
float gain;
|
float gain;
|
||||||
} TiltCorrectionFilter;
|
} TiltCorrectionFilter;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user