1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-26 08:49:37 +00:00

Adds a negative operator.

This commit is contained in:
Thomas Harte 2018-11-26 22:34:04 -05:00
parent 5618288459
commit 61a63a673c
2 changed files with 18 additions and 0 deletions

View File

@ -114,6 +114,9 @@ FIRFilter::FIRFilter(std::size_t number_of_taps, float input_sample_rate, float
std::size_t Np = (number_of_taps - 1) / 2; std::size_t Np = (number_of_taps - 1) / 2;
float two_over_sample_rate = 2.0f / input_sample_rate; float two_over_sample_rate = 2.0f / input_sample_rate;
// Clamp the high cutoff frequency.
high_frequency = std::min(high_frequency, input_sample_rate * 0.5f);
std::vector<float> A(Np+1); std::vector<float> A(Np+1);
A[0] = 2.0f * (high_frequency - low_frequency) / input_sample_rate; A[0] = 2.0f * (high_frequency - low_frequency) / input_sample_rate;
for(unsigned int i = 1; i <= Np; ++i) { for(unsigned int i = 1; i <= Np; ++i) {
@ -146,6 +149,16 @@ FIRFilter FIRFilter::operator+(const FIRFilter &rhs) const {
return FIRFilter(sum); return FIRFilter(sum);
} }
FIRFilter FIRFilter::operator-() const {
std::vector<float> negative_coefficients;
for(const auto coefficient: get_coefficients()) {
negative_coefficients.push_back(1.0f - coefficient);
}
return FIRFilter(negative_coefficients);
}
FIRFilter FIRFilter::operator*(const FIRFilter &rhs) const { FIRFilter FIRFilter::operator*(const FIRFilter &rhs) const {
std::vector<float> coefficients = get_coefficients(); std::vector<float> coefficients = get_coefficients();
std::vector<float> rhs_coefficients = rhs.get_coefficients(); std::vector<float> rhs_coefficients = rhs.get_coefficients();

View File

@ -83,6 +83,11 @@ class FIRFilter {
*/ */
FIRFilter operator*(const FIRFilter &) const; FIRFilter operator*(const FIRFilter &) const;
/*!
@returns A filter that would have the opposite effect of this filter.
*/
FIRFilter operator-() const;
private: private:
std::vector<short> filter_coefficients_; std::vector<short> filter_coefficients_;