worked on fir/iir filters

This commit is contained in:
2018-08-06 18:33:17 +02:00
parent 327b580b69
commit d6ac8a72ca
5 changed files with 216 additions and 442 deletions

View File

@@ -181,8 +181,16 @@ private:
}
// https://dsp.stackexchange.com/questions/4693/fir-filter-gain
static void normalizeAC(std::vector<std::complex<float>>& kernel, const float freq) {
throw std::runtime_error("TODO");
static void normalizeAC(std::vector<std::complex<float>>& kernel, const float freq, const float sRate) {
// std::complex<float> sum;
// for (size_t i = 0; i < kernel.size(); ++i) {
// const float t = (float) i / sRate;
// const float v = std::sin(t*freq);
// }
// for (auto f : kernel) {sum += f * sin;}
// for (auto& f : kernel) {f /= sum;}
throw std::runtime_error("todo");
}
/** build a lowpass filter kernel */

View File

@@ -35,6 +35,16 @@ namespace FIR {
this->kernel = kernel;
}
const Kernel& getKernel() const {
return this->kernel;
}
void prefill(float val) {
for (size_t i = 0; i < (kernel.size()-1)/2; ++i) {
append(val);
}
}
/** filter the given incoming real data */
DataVec append(const DataVec& newData) {
// append to local buffer (as we need some history)
@@ -56,10 +66,11 @@ namespace FIR {
DataVec processLocalBuffer() {
// sanity check
Assert::isNot0(kernel.size(), "FIRComplex:: kernel not yet configured!");
Assert::isNot0(kernel.size(), "FIR::Real::Filter kernel not yet configured!");
// number of processable elements (due to filter size)
const int processable = data.size() - kernel.size() + 1 - kernel.size()/2;
//const int processable = data.size() - kernel.size() + 1 - kernel.size()/2;
const int processable = data.size() - kernel.size();
// nothing to-do?
if (processable <= 0) {return DataVec();}