1
0
Fork 0

Remove distinction between Coeff and Sample types; they are always the same floating point type.

This commit is contained in:
Joris van Rantwijk 2013-12-29 00:44:10 +01:00
parent 70ba5520ca
commit c3778fb920
5 changed files with 41 additions and 43 deletions

View File

@ -208,23 +208,23 @@ void DownsampleFilter::process(const SampleVector& samples_in,
// the FIR coefficient table. This is a bitch.
// Estimate number of output samples we can produce in this run.
Coeff p = m_pos_frac;
Coeff pstep = m_downsample;
Sample p = m_pos_frac;
Sample pstep = m_downsample;
unsigned int n_out = int(2 + n / pstep);
samples_out.resize(n_out);
// Produce output samples.
unsigned int i = 0;
Coeff pf = p;
Sample pf = p;
unsigned int pi = int(pf);
while (pi < n) {
Coeff k1 = pf - pi;
Coeff k0 = 1 - k1;
Sample k1 = pf - pi;
Sample k0 = 1 - k1;
Sample y = 0;
for (unsigned int j = 0; j <= order; j++) {
Coeff k = m_coeff[j] * k0 + m_coeff[j+1] * k1;
Sample k = m_coeff[j] * k0 + m_coeff[j+1] * k1;
Sample s = (j <= pi) ? samples_in[pi-j] : m_state[order+pi-j];
y += k * s;
}
@ -278,8 +278,8 @@ void LowPassFilterRC::process(const SampleVector& samples_in,
* Discrete domain:
* H(z) = (1 - exp(-1/timeconst)) / (1 - exp(-1/timeconst) / z)a
*/
Coeff a1 = - exp(-1/m_timeconst);;
Coeff b0 = 1 + a1;
Sample a1 = - exp(-1/m_timeconst);;
Sample b0 = 1 + a1;
unsigned int n = samples_in.size();
samples_out.resize(n);
@ -298,8 +298,8 @@ void LowPassFilterRC::process(const SampleVector& samples_in,
// Process samples in-place.
void LowPassFilterRC::processInPlace(SampleVector& samples)
{
Coeff a1 = - exp(-1/m_timeconst);;
Coeff b0 = 1 + a1;
Sample a1 = - exp(-1/m_timeconst);;
Sample b0 = 1 + a1;
unsigned int n = samples.size();

View File

@ -85,8 +85,8 @@ private:
double m_downsample;
unsigned int m_downsample_int;
unsigned int m_pos_int;
Coeff m_pos_frac;
CoeffVector m_coeff;
Sample m_pos_frac;
SampleVector m_coeff;
SampleVector m_state;
};
@ -132,7 +132,7 @@ public:
void process(const SampleVector& samples_in, SampleVector& samples_out);
private:
Coeff b0, a1, a2, a3, a4;
Sample b0, a1, a2, a3, a4;
Sample y1, y2, y3, y4;
};
@ -157,7 +157,7 @@ public:
void processInPlace(SampleVector& samples);
private:
Coeff b0, b1, b2, a1, a2;
Sample b0, b1, b2, a1, a2;
Sample x1, x2, y1, y2;
};

View File

@ -96,12 +96,12 @@ PilotPhaseLock::PilotPhaseLock(double freq, double bandwidth, double minsignal)
m_lock_delay = int(10.0 / bandwidth);
m_lock_cnt = 0;
// Create 2nd order filter for IQ representation of phase error
// with both poles at z = exp(-2.5 * bandwidth * 2*PI).
// Create 2nd order filter for I/Q representation of phase error.
// Filter has both poles at z = exp(-2.5 * bandwidth * 2*PI).
double t = exp(-2.5 * bandwidth * 2.0 * M_PI);
m_iqfilter_a1 = -2.0 * t;
m_iqfilter_a2 = t * t;
m_iqfilter_b0 = m_iqfilter_a1 + m_iqfilter_a2;
m_phasor_a1 = -2.0 * t;
m_phasor_a2 = t * t;
m_phasor_b0 = m_phasor_a1 + m_phasor_a2;
// Create loop filter to stabilize the loop.
// Zero at z = exp(-0.2 * bandwidth * 2*PI),
@ -113,10 +113,10 @@ PilotPhaseLock::PilotPhaseLock(double freq, double bandwidth, double minsignal)
m_freq = freq * 2.0 * M_PI;
m_phase = 0;
m_iqfilter_i1 = 0;
m_iqfilter_i2 = 0;
m_iqfilter_q1 = 0;
m_iqfilter_q2 = 0;
m_phasor_i1 = 0;
m_phasor_i2 = 0;
m_phasor_q1 = 0;
m_phasor_q2 = 0;
}
@ -141,16 +141,16 @@ void PilotPhaseLock::process(const SampleVector& samples_in,
Sample phasor_q = psin * x;
// Run IQ phase error through low-pass filter.
phasor_i = m_iqfilter_b0 * phasor_i
- m_iqfilter_a1 * m_iqfilter_i1
- m_iqfilter_a2 * m_iqfilter_i2;
phasor_q = m_iqfilter_b0 * phasor_q
- m_iqfilter_a1 * m_iqfilter_q1
- m_iqfilter_a2 * m_iqfilter_q2;
m_iqfilter_i2 = m_iqfilter_i1;
m_iqfilter_i1 = phasor_i;
m_iqfilter_q2 = m_iqfilter_q1;
m_iqfilter_q1 = phasor_q;
phasor_i = m_phasor_b0 * phasor_i
- m_phasor_a1 * m_phasor_i1
- m_phasor_a2 * m_phasor_i2;
phasor_q = m_phasor_b0 * phasor_q
- m_phasor_a1 * m_phasor_q1
- m_phasor_a2 * m_phasor_q2;
m_phasor_i2 = m_phasor_i1;
m_phasor_i1 = phasor_i;
m_phasor_q2 = m_phasor_q1;
m_phasor_q1 = phasor_q;
// Convert I/Q ratio to estimate of phase error.
Sample phase_err;

View File

@ -26,7 +26,7 @@ public:
void process(const IQSampleVector& samples_in, SampleVector& samples_out);
private:
const Coeff m_freq_scale_factor;
const Sample m_freq_scale_factor;
IQSample m_last_sample;
};
@ -56,10 +56,10 @@ public:
}
private:
Coeff m_minfreq, m_maxfreq;
Coeff m_iqfilter_b0, m_iqfilter_a1, m_iqfilter_a2;
Coeff m_loopfilter_b0, m_loopfilter_b1;
Sample m_iqfilter_i1, m_iqfilter_i2, m_iqfilter_q1, m_iqfilter_q2;
Sample m_minfreq, m_maxfreq;
Sample m_phasor_b0, m_phasor_a1, m_phasor_a2;
Sample m_phasor_i1, m_phasor_i2, m_phasor_q1, m_phasor_q2;
Sample m_loopfilter_b0, m_loopfilter_b1;
Sample m_loopfilter_x1;
Sample m_freq, m_phase;
Sample m_minsignal;

View File

@ -10,12 +10,10 @@ typedef std::vector<IQSample> IQSampleVector;
typedef double Sample;
typedef std::vector<Sample> SampleVector;
typedef double Coeff;
typedef std::vector<Coeff> CoeffVector;
/** Compute mean and RMS over a sample vector. */
inline void samples_mean_rms(const SampleVector& samples, double& mean, double& rms)
inline void samples_mean_rms(const SampleVector& samples,
double& mean, double& rms)
{
Sample vsum = 0;
Sample vsumsq = 0;