/* Reflow Oven Controller * * Copyright (C) 2021 Mario Hüttel * * This file is part of the Reflow Oven Controller Project. * * The reflow oven controller is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * * The Reflow Oven Control Firmware is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with the reflow oven controller project. * If not, see . */ #include void fir_filter_init_null(struct fir_filter_fixed *filter) { uint32_t idx; if (!filter) return; filter->put_idx = 0U; for (idx = 0; idx < filter->tap_count; idx++) filter->data = 0; } int32_t fir_filter_process_sample(struct fir_filter_fixed *filter, int32_t sample) { uint32_t tap_idx; uint32_t coeff_idx; int32_t output = 0; if (!filter) return 0; /* Store the new data point */ filter->data[filter->put_idx] = sample; coeff_idx = filter->put_idx; /* Apply fir taps on data */ for (tap_idx = 0; tap_idx < filter->tap_count; tap_idx++) { output += filter->data[tap_idx] * filter->coefficients[coeff_idx]; if (coeff_idx) coeff_idx--; else coeff_idx = filter->tap_count-1; } filter->put_idx++; if (filter->put_idx >= filter->tap_count) filter->put_idx = 0; return output; }