/* Copyright 2016 Benjamin Vedder benjamin@vedder.se This file is part of the VESC firmware. The VESC firmware is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. The VESC 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 this program. If not, see . */ #include "digital_filter.h" #include #include // Found at http://paulbourke.net/miscellaneous//dft/ void filter_fft(int dir, int m, float *real, float *imag) { long n,i,i1,j,k,i2,l,l1,l2; float c1,c2,tx,ty,t1,t2,u1,u2,z; // Calculate the number of points n = 1 << m; // Do the bit reversal i2 = n >> 1; j = 0; for (i=0;i>= 1; } j += k; } // Compute the FFT c1 = -1.0; c2 = 0.0; l2 = 1; for (l=0;l> (32 - bits); for (int i = 0;i < size;i++) { result += filter[i] * vector[offset]; offset++; offset &= cnt_mask; } return result; } /** * Add sample to buffer * @param buffer * The buffer to add the sample to * @param sample * The sample to add * @param bits * The length of the buffer in bits * @param offset * Pointer to the current offset in the buffer. Will be updated in this call * and wrapped at the length of this buffer. */ void filter_add_sample(float *buffer, float sample, int bits, uint32_t *offset) { uint32_t cnt_mask = 0xFFFFFFFF >> (32 - bits); buffer[*offset] = sample; *offset += 1; *offset &= cnt_mask; }