Skip to content

Commit

Permalink
Clear the 0 and half-frequency bins for the phase shift filter
Browse files Browse the repository at this point in the history
This doesn't change the filter response, but is more correct since a real
signal won't have an imaginary value on them (it can only have a magnitude with
a phase of 0 or pi).
  • Loading branch information
kcat committed Oct 4, 2023
1 parent 340a22b commit 23cc00e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions common/phase_shifter.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <array>
#include <stddef.h>
#include <type_traits>

#include "alcomplex.h"
#include "alspan.h"
Expand Down Expand Up @@ -54,13 +55,15 @@ struct PhaseShifterT {
fftBuffer[half_size] = 1.0;

forward_fft(al::span{fftBuffer.get(), fft_size});
for(size_t i{0};i < half_size+1;++i)
fftBuffer[0] *= std::numeric_limits<double>::epsilon();
for(size_t i{1};i < half_size;++i)
fftBuffer[i] = complex_d{-fftBuffer[i].imag(), fftBuffer[i].real()};
fftBuffer[half_size] *= std::numeric_limits<double>::epsilon();
for(size_t i{half_size+1};i < fft_size;++i)
fftBuffer[i] = std::conj(fftBuffer[fft_size - i]);
inverse_fft(al::span{fftBuffer.get(), fft_size});

auto fftiter = fftBuffer.get() + half_size + (FilterSize/2 - 1);
auto fftiter = fftBuffer.get() + fft_size - 1;
for(float &coeff : mCoeffs)
{
coeff = static_cast<float>(fftiter->real() / double{fft_size});
Expand Down

0 comments on commit 23cc00e

Please sign in to comment.