Tx ph.2: Interpolator polyphase filter: add possibility to specify the number of taps per phase

pull/27/head
f4exb 2016-10-31 23:40:46 +01:00
rodzic 283742cada
commit 3173bc0b07
2 zmienionych plików z 49 dodań i 16 usunięć

Wyświetl plik

@ -3,20 +3,36 @@
#include <vector>
#include "dsp/interpolator.h"
static std::vector<Real> createPolyphaseLowPass(
int phaseSteps,
double gain,
double sampleRateHz,
double cutoffFreqHz,
double transitionWidthHz,
double oobAttenuationdB)
void Interpolator::createPolyphaseLowPass(
std::vector<Real>& taps,
int phaseSteps,
double gain,
double sampleRateHz,
double cutoffFreqHz,
double transitionWidthHz,
double oobAttenuationdB)
{
int ntaps = (int)(oobAttenuationdB * sampleRateHz / (22.0 * transitionWidthHz));
double nbTapsPerPhase = (oobAttenuationdB * sampleRateHz) / (22.0 * transitionWidthHz * phaseSteps);
return createPolyphaseLowPass(taps, phaseSteps, gain, sampleRateHz, cutoffFreqHz, nbTapsPerPhase);
}
void Interpolator::createPolyphaseLowPass(
std::vector<Real>& taps,
int phaseSteps,
double gain,
double sampleRateHz,
double cutoffFreqHz,
double nbTapsPerPhase)
{
int ntaps = (int)(nbTapsPerPhase * phaseSteps);
qDebug("Interpolator::createPolyphaseLowPass: ntaps: %d", ntaps);
if((ntaps % 2) != 0)
ntaps++;
ntaps *= phaseSteps;
std::vector<float> taps(ntaps);
taps.resize(ntaps);
std::vector<float> window(ntaps);
for(int n = 0; n < ntaps; n++)
@ -37,8 +53,6 @@ static std::vector<Real> createPolyphaseLowPass(
for(int i = 0; i < ntaps; i++)
taps[i] *= gain;
return taps;
}
Interpolator::Interpolator() :
@ -52,17 +66,19 @@ Interpolator::~Interpolator()
free();
}
void Interpolator::create(int phaseSteps, double sampleRate, double cutoff)
void Interpolator::create(int phaseSteps, double sampleRate, double cutoff, double nbTapsPerPhase)
{
free();
std::vector<Real> taps = createPolyphaseLowPass(
std::vector<Real> taps;
createPolyphaseLowPass(
taps,
phaseSteps, // number of polyphases
1.0, // gain
phaseSteps * sampleRate, // sampling frequency
cutoff, // hz beginning of transition band
sampleRate / 5.0, // hz width of transition band
20.0); // out of band attenuation
nbTapsPerPhase);
// init state
m_ptr = 0;

Wyświetl plik

@ -16,7 +16,7 @@ public:
Interpolator();
~Interpolator();
void create(int phaseSteps, double sampleRate, double cutoff);
void create(int phaseSteps, double sampleRate, double cutoff, double nbTapsPerPhase = 4.5);
void free();
// Original code allowed for upsampling, but was never used that way
@ -85,6 +85,23 @@ private:
int m_phaseSteps;
int m_nTaps;
static void createPolyphaseLowPass(
std::vector<Real>& taps,
int phaseSteps,
double gain,
double sampleRateHz,
double cutoffFreqHz,
double transitionWidthHz,
double oobAttenuationdB);
static void createPolyphaseLowPass(
std::vector<Real>& taps,
int phaseSteps,
double gain,
double sampleRateHz,
double cutoffFreqHz,
double nbTapsPerPhase);
void createTaps(int nTaps, double sampleRate, double cutoff, std::vector<Real>* taps);
void advanceFilter(const Complex& next)