Skip to content

Commit

Permalink
Merge pull request #10 from asceenl/master
Browse files Browse the repository at this point in the history
Added setCoeff method
  • Loading branch information
berndporr authored Mar 5, 2024
2 parents 9d9416a + 839a341 commit df5b112
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
11 changes: 10 additions & 1 deletion Fir1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ THE SOFTWARE.
#include <stdexcept>

// give the filter an array of doubles for the coefficients
Fir1::Fir1(double *_coefficients, unsigned number_of_taps) :
Fir1::Fir1(const double *_coefficients,const unsigned number_of_taps) :
coefficients(new double[number_of_taps]),
buffer(new double[number_of_taps]()),
taps(number_of_taps) {
Expand Down Expand Up @@ -107,4 +107,13 @@ void Fir1::getCoeff(double* coeff_data, unsigned number_of_taps) const {
if (number_of_taps > taps)
memset(&coeff_data[taps], 0, (number_of_taps - taps)*sizeof(double));
}
void Fir1::setCoeff(const double* coeff_data, const unsigned number_of_taps) {

if (number_of_taps != taps) {
throw std::runtime_error("Invalid number of taps in new coefficient array");
}
for (unsigned int i = 0; i < number_of_taps; i++) {
coefficients[i] = coeff_data[i];
}
}

14 changes: 13 additions & 1 deletion Fir1.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Fir1 {
* \param coefficients Coefficients as double array.
* \param number_of_taps Number of taps (needs to match the number of coefficients
**/
Fir1(double *coefficients, unsigned number_of_taps);
Fir1(const double *coefficients,const unsigned number_of_taps);

/** Coefficients as a text file (for example from Python)
* The number of taps is automatically detected
Expand Down Expand Up @@ -169,6 +169,18 @@ class Fir1 {
*/
void getCoeff(double* coeff_data, unsigned number_of_taps) const;

/**
* @brief Externally sets the coefficient array. This is useful when the
* actually running filter is at a different place as where the updating
* filter is employed.
*
* @param coeff_data New coefficients to set.
* @param number_of_taps Number of taps in the coefficient array. If this is
* not equal to the number of taps used in this filter, a runtime error is
* thrown.
*/
void setCoeff(const double *coeff_data, const unsigned number_of_taps);

/**
* Returns the coefficients as a vector
**/
Expand Down

0 comments on commit df5b112

Please sign in to comment.