mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-15 12:51:49 -05:00
Tx ph.2: Interpolator polyphase filter: add possibility to specify the number of taps per phase
This commit is contained in:
parent
283742cada
commit
3173bc0b07
@ -3,7 +3,9 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include "dsp/interpolator.h"
|
#include "dsp/interpolator.h"
|
||||||
|
|
||||||
static std::vector<Real> createPolyphaseLowPass(
|
|
||||||
|
void Interpolator::createPolyphaseLowPass(
|
||||||
|
std::vector<Real>& taps,
|
||||||
int phaseSteps,
|
int phaseSteps,
|
||||||
double gain,
|
double gain,
|
||||||
double sampleRateHz,
|
double sampleRateHz,
|
||||||
@ -11,12 +13,26 @@ static std::vector<Real> createPolyphaseLowPass(
|
|||||||
double transitionWidthHz,
|
double transitionWidthHz,
|
||||||
double oobAttenuationdB)
|
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)
|
if((ntaps % 2) != 0)
|
||||||
ntaps++;
|
ntaps++;
|
||||||
ntaps *= phaseSteps;
|
ntaps *= phaseSteps;
|
||||||
|
|
||||||
std::vector<float> taps(ntaps);
|
taps.resize(ntaps);
|
||||||
std::vector<float> window(ntaps);
|
std::vector<float> window(ntaps);
|
||||||
|
|
||||||
for(int n = 0; n < ntaps; n++)
|
for(int n = 0; n < ntaps; n++)
|
||||||
@ -37,8 +53,6 @@ static std::vector<Real> createPolyphaseLowPass(
|
|||||||
|
|
||||||
for(int i = 0; i < ntaps; i++)
|
for(int i = 0; i < ntaps; i++)
|
||||||
taps[i] *= gain;
|
taps[i] *= gain;
|
||||||
|
|
||||||
return taps;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Interpolator::Interpolator() :
|
Interpolator::Interpolator() :
|
||||||
@ -52,17 +66,19 @@ Interpolator::~Interpolator()
|
|||||||
free();
|
free();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Interpolator::create(int phaseSteps, double sampleRate, double cutoff)
|
void Interpolator::create(int phaseSteps, double sampleRate, double cutoff, double nbTapsPerPhase)
|
||||||
{
|
{
|
||||||
free();
|
free();
|
||||||
|
|
||||||
std::vector<Real> taps = createPolyphaseLowPass(
|
std::vector<Real> taps;
|
||||||
|
|
||||||
|
createPolyphaseLowPass(
|
||||||
|
taps,
|
||||||
phaseSteps, // number of polyphases
|
phaseSteps, // number of polyphases
|
||||||
1.0, // gain
|
1.0, // gain
|
||||||
phaseSteps * sampleRate, // sampling frequency
|
phaseSteps * sampleRate, // sampling frequency
|
||||||
cutoff, // hz beginning of transition band
|
cutoff, // hz beginning of transition band
|
||||||
sampleRate / 5.0, // hz width of transition band
|
nbTapsPerPhase);
|
||||||
20.0); // out of band attenuation
|
|
||||||
|
|
||||||
// init state
|
// init state
|
||||||
m_ptr = 0;
|
m_ptr = 0;
|
||||||
|
@ -16,7 +16,7 @@ public:
|
|||||||
Interpolator();
|
Interpolator();
|
||||||
~Interpolator();
|
~Interpolator();
|
||||||
|
|
||||||
void create(int phaseSteps, double sampleRate, double cutoff);
|
void create(int phaseSteps, double sampleRate, double cutoff, double nbTapsPerPhase = 4.5);
|
||||||
void free();
|
void free();
|
||||||
|
|
||||||
// Original code allowed for upsampling, but was never used that way
|
// Original code allowed for upsampling, but was never used that way
|
||||||
@ -85,6 +85,23 @@ private:
|
|||||||
int m_phaseSteps;
|
int m_phaseSteps;
|
||||||
int m_nTaps;
|
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 createTaps(int nTaps, double sampleRate, double cutoff, std::vector<Real>* taps);
|
||||||
|
|
||||||
void advanceFilter(const Complex& next)
|
void advanceFilter(const Complex& next)
|
||||||
|
Loading…
Reference in New Issue
Block a user