Skip to content

Instantly share code, notes, and snippets.

@jniemann66
Created July 26, 2020 10:51
Show Gist options
  • Save jniemann66/3da9547de0d6dcd6b3ff59e7bd67db6a to your computer and use it in GitHub Desktop.
Save jniemann66/3da9547de0d6dcd6b3ff59e7bd67db6a to your computer and use it in GitHub Desktop.
freq doubler - multiples +45 deg with -45 deg phase shift
class FrequencyDoubler
{
public:
FrequencyDoubler() {
coeffs = ReSampler::makeHilbert(1001);
length = coeffs.size();
history.resize(length);
centerTap = length / 2;
currentIndex = length - 1;
}
template<typename FloatType>
double filter(FloatType input)
{
history[currentIndex] = input; // place input into history
int d = currentIndex + centerTap;
FloatType s0 = history[d >= length ? d - length : d]; // delay only
FloatType s1 = 0.0;
int p = currentIndex;
for(int j = 0 ; j < length; j++) {
FloatType v = history.at(p++);
if(p == length) {
p = 0;
}
s1 += coeffs.at(j) * v;
}
if(currentIndex == 0) {
currentIndex = length - 1;
} else {
currentIndex--;
}
// multiply +45deg signal with -45deg
return (s0 + s1) * (s0 - s1);
}
private:
std::vector<double> coeffs;
std::vector<double> history;
int length;
int centerTap;
int currentIndex;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment