mirror of
https://github.com/aicodix/dsp.git
synced 2026-04-27 14:30:36 +00:00
make it work for negative n too
This commit is contained in:
parent
692bfa4d31
commit
cf54a8e431
2 changed files with 9 additions and 1 deletions
|
|
@ -15,7 +15,7 @@ template <typename TYPE, typename PRECISE>
|
|||
void test(int MAX)
|
||||
{
|
||||
for (int N = 1; N <= MAX; ++N) {
|
||||
for (int n = 0; n < N; ++n) {
|
||||
for (int n = -N; n <= N; ++n) {
|
||||
PRECISE x = DSP::Const<PRECISE>::TwoPi() * PRECISE(n) / PRECISE(N);
|
||||
PRECISE cos_err = std::abs(DSP::UnitCircle<TYPE>::cos(n, N) - std::cos(x));
|
||||
assert(cos_err < std::numeric_limits<TYPE>::epsilon());
|
||||
|
|
|
|||
|
|
@ -56,6 +56,10 @@ public:
|
|||
static constexpr TYPE cos(int n, int N)
|
||||
{
|
||||
return
|
||||
8*n <-7*N ? cosine_approx(rad(n+N, N)) :
|
||||
8*n <-5*N ? -sine_approx(rad(4*n+3*N, 4*N)) :
|
||||
8*n <-3*N ? -cosine_approx(rad(2*n+N, 2*N)) :
|
||||
8*n <-1*N ? sine_approx(rad(4*n+N, 4*N)) :
|
||||
8*n < 1*N ? cosine_approx(rad(n, N)) :
|
||||
8*n < 3*N ? -sine_approx(rad(4*n-N, 4*N)) :
|
||||
8*n < 5*N ? -cosine_approx(rad(2*n-N, 2*N)) :
|
||||
|
|
@ -65,6 +69,10 @@ public:
|
|||
static constexpr TYPE sin(int n, int N)
|
||||
{
|
||||
return
|
||||
8*n <-7*N ? sine_approx(rad(n+N, N)) :
|
||||
8*n <-5*N ? cosine_approx(rad(4*n+3*N, 4*N)) :
|
||||
8*n <-3*N ? -sine_approx(rad(2*n+N, 2*N)) :
|
||||
8*n <-1*N ? -cosine_approx(rad(4*n+N, 4*N)) :
|
||||
8*n < 1*N ? sine_approx(rad(n, N)) :
|
||||
8*n < 3*N ? cosine_approx(rad(4*n-N, 4*N)) :
|
||||
8*n < 5*N ? -sine_approx(rad(2*n-N, 2*N)) :
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue