added an NCO

This commit is contained in:
Ahmet Inan 2019-02-04 12:29:40 +01:00
commit a3a2dbdc5f
2 changed files with 42 additions and 0 deletions

View file

@ -40,6 +40,10 @@ The following [infinite impulse response](https://en.wikipedia.org/wiki/Infinite
* [second-order Butterworth low pass filter](https://en.wikipedia.org/wiki/Butterworth_filter)
* [2n-order Butterworth cascade of second-order low pass filters](https://en.wikipedia.org/wiki/Butterworth_filter)
### [phasor.hh](phasor.hh)
[Numerically controlled oscillator](https://en.wikipedia.org/wiki/Numerically_controlled_oscillator) implemented using a [phasor](https://en.wikipedia.org/wiki/Phasor) and [complex multiplication](https://en.wikipedia.org/wiki/Complex_number#Multiplication) instead of a [lookup table](https://en.wikipedia.org/wiki/Lookup_table).
### [const.hh](const.hh)
Some constants we need

38
phasor.hh Normal file
View file

@ -0,0 +1,38 @@
/*
Numerically controlled oscillator
Copyright 2019 Ahmet Inan <inan@aicodix.de>
*/
#include "unit_circle.hh"
#pragma once
namespace DSP {
template <typename TYPE>
class Phasor
{
typedef TYPE complex_type;
typedef typename complex_type::value_type value_type;
complex_type prev, delta;
public:
constexpr Phasor() : prev(1, 0), delta(1, 0)
{
}
void omega(int n, int N)
{
delta = complex_type(
UnitCircle<value_type>::cos(n, N),
UnitCircle<value_type>::sin(n, N));
}
complex_type operator()()
{
complex_type tmp = prev;
prev *= delta;
prev /= abs(prev);
return tmp;
}
};
}