Remove distinction between Coeff and Sample types; they are always the same floating point type.
This commit is contained in:
parent
70ba5520ca
commit
c3778fb920
20
Filter.cc
20
Filter.cc
|
@ -208,23 +208,23 @@ void DownsampleFilter::process(const SampleVector& samples_in,
|
||||||
// the FIR coefficient table. This is a bitch.
|
// the FIR coefficient table. This is a bitch.
|
||||||
|
|
||||||
// Estimate number of output samples we can produce in this run.
|
// Estimate number of output samples we can produce in this run.
|
||||||
Coeff p = m_pos_frac;
|
Sample p = m_pos_frac;
|
||||||
Coeff pstep = m_downsample;
|
Sample pstep = m_downsample;
|
||||||
unsigned int n_out = int(2 + n / pstep);
|
unsigned int n_out = int(2 + n / pstep);
|
||||||
|
|
||||||
samples_out.resize(n_out);
|
samples_out.resize(n_out);
|
||||||
|
|
||||||
// Produce output samples.
|
// Produce output samples.
|
||||||
unsigned int i = 0;
|
unsigned int i = 0;
|
||||||
Coeff pf = p;
|
Sample pf = p;
|
||||||
unsigned int pi = int(pf);
|
unsigned int pi = int(pf);
|
||||||
while (pi < n) {
|
while (pi < n) {
|
||||||
Coeff k1 = pf - pi;
|
Sample k1 = pf - pi;
|
||||||
Coeff k0 = 1 - k1;
|
Sample k0 = 1 - k1;
|
||||||
|
|
||||||
Sample y = 0;
|
Sample y = 0;
|
||||||
for (unsigned int j = 0; j <= order; j++) {
|
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];
|
Sample s = (j <= pi) ? samples_in[pi-j] : m_state[order+pi-j];
|
||||||
y += k * s;
|
y += k * s;
|
||||||
}
|
}
|
||||||
|
@ -278,8 +278,8 @@ void LowPassFilterRC::process(const SampleVector& samples_in,
|
||||||
* Discrete domain:
|
* Discrete domain:
|
||||||
* H(z) = (1 - exp(-1/timeconst)) / (1 - exp(-1/timeconst) / z)a
|
* H(z) = (1 - exp(-1/timeconst)) / (1 - exp(-1/timeconst) / z)a
|
||||||
*/
|
*/
|
||||||
Coeff a1 = - exp(-1/m_timeconst);;
|
Sample a1 = - exp(-1/m_timeconst);;
|
||||||
Coeff b0 = 1 + a1;
|
Sample b0 = 1 + a1;
|
||||||
|
|
||||||
unsigned int n = samples_in.size();
|
unsigned int n = samples_in.size();
|
||||||
samples_out.resize(n);
|
samples_out.resize(n);
|
||||||
|
@ -298,8 +298,8 @@ void LowPassFilterRC::process(const SampleVector& samples_in,
|
||||||
// Process samples in-place.
|
// Process samples in-place.
|
||||||
void LowPassFilterRC::processInPlace(SampleVector& samples)
|
void LowPassFilterRC::processInPlace(SampleVector& samples)
|
||||||
{
|
{
|
||||||
Coeff a1 = - exp(-1/m_timeconst);;
|
Sample a1 = - exp(-1/m_timeconst);;
|
||||||
Coeff b0 = 1 + a1;
|
Sample b0 = 1 + a1;
|
||||||
|
|
||||||
unsigned int n = samples.size();
|
unsigned int n = samples.size();
|
||||||
|
|
||||||
|
|
8
Filter.h
8
Filter.h
|
@ -85,8 +85,8 @@ private:
|
||||||
double m_downsample;
|
double m_downsample;
|
||||||
unsigned int m_downsample_int;
|
unsigned int m_downsample_int;
|
||||||
unsigned int m_pos_int;
|
unsigned int m_pos_int;
|
||||||
Coeff m_pos_frac;
|
Sample m_pos_frac;
|
||||||
CoeffVector m_coeff;
|
SampleVector m_coeff;
|
||||||
SampleVector m_state;
|
SampleVector m_state;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -132,7 +132,7 @@ public:
|
||||||
void process(const SampleVector& samples_in, SampleVector& samples_out);
|
void process(const SampleVector& samples_in, SampleVector& samples_out);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Coeff b0, a1, a2, a3, a4;
|
Sample b0, a1, a2, a3, a4;
|
||||||
Sample y1, y2, y3, y4;
|
Sample y1, y2, y3, y4;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -157,7 +157,7 @@ public:
|
||||||
void processInPlace(SampleVector& samples);
|
void processInPlace(SampleVector& samples);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Coeff b0, b1, b2, a1, a2;
|
Sample b0, b1, b2, a1, a2;
|
||||||
Sample x1, x2, y1, y2;
|
Sample x1, x2, y1, y2;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
38
FmDecode.cc
38
FmDecode.cc
|
@ -96,12 +96,12 @@ PilotPhaseLock::PilotPhaseLock(double freq, double bandwidth, double minsignal)
|
||||||
m_lock_delay = int(10.0 / bandwidth);
|
m_lock_delay = int(10.0 / bandwidth);
|
||||||
m_lock_cnt = 0;
|
m_lock_cnt = 0;
|
||||||
|
|
||||||
// Create 2nd order filter for IQ representation of phase error
|
// Create 2nd order filter for I/Q representation of phase error.
|
||||||
// with both poles at z = exp(-2.5 * bandwidth * 2*PI).
|
// Filter has both poles at z = exp(-2.5 * bandwidth * 2*PI).
|
||||||
double t = exp(-2.5 * bandwidth * 2.0 * M_PI);
|
double t = exp(-2.5 * bandwidth * 2.0 * M_PI);
|
||||||
m_iqfilter_a1 = -2.0 * t;
|
m_phasor_a1 = -2.0 * t;
|
||||||
m_iqfilter_a2 = t * t;
|
m_phasor_a2 = t * t;
|
||||||
m_iqfilter_b0 = m_iqfilter_a1 + m_iqfilter_a2;
|
m_phasor_b0 = m_phasor_a1 + m_phasor_a2;
|
||||||
|
|
||||||
// Create loop filter to stabilize the loop.
|
// Create loop filter to stabilize the loop.
|
||||||
// Zero at z = exp(-0.2 * bandwidth * 2*PI),
|
// 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_freq = freq * 2.0 * M_PI;
|
||||||
m_phase = 0;
|
m_phase = 0;
|
||||||
|
|
||||||
m_iqfilter_i1 = 0;
|
m_phasor_i1 = 0;
|
||||||
m_iqfilter_i2 = 0;
|
m_phasor_i2 = 0;
|
||||||
m_iqfilter_q1 = 0;
|
m_phasor_q1 = 0;
|
||||||
m_iqfilter_q2 = 0;
|
m_phasor_q2 = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -141,16 +141,16 @@ void PilotPhaseLock::process(const SampleVector& samples_in,
|
||||||
Sample phasor_q = psin * x;
|
Sample phasor_q = psin * x;
|
||||||
|
|
||||||
// Run IQ phase error through low-pass filter.
|
// Run IQ phase error through low-pass filter.
|
||||||
phasor_i = m_iqfilter_b0 * phasor_i
|
phasor_i = m_phasor_b0 * phasor_i
|
||||||
- m_iqfilter_a1 * m_iqfilter_i1
|
- m_phasor_a1 * m_phasor_i1
|
||||||
- m_iqfilter_a2 * m_iqfilter_i2;
|
- m_phasor_a2 * m_phasor_i2;
|
||||||
phasor_q = m_iqfilter_b0 * phasor_q
|
phasor_q = m_phasor_b0 * phasor_q
|
||||||
- m_iqfilter_a1 * m_iqfilter_q1
|
- m_phasor_a1 * m_phasor_q1
|
||||||
- m_iqfilter_a2 * m_iqfilter_q2;
|
- m_phasor_a2 * m_phasor_q2;
|
||||||
m_iqfilter_i2 = m_iqfilter_i1;
|
m_phasor_i2 = m_phasor_i1;
|
||||||
m_iqfilter_i1 = phasor_i;
|
m_phasor_i1 = phasor_i;
|
||||||
m_iqfilter_q2 = m_iqfilter_q1;
|
m_phasor_q2 = m_phasor_q1;
|
||||||
m_iqfilter_q1 = phasor_q;
|
m_phasor_q1 = phasor_q;
|
||||||
|
|
||||||
// Convert I/Q ratio to estimate of phase error.
|
// Convert I/Q ratio to estimate of phase error.
|
||||||
Sample phase_err;
|
Sample phase_err;
|
||||||
|
|
10
FmDecode.h
10
FmDecode.h
|
@ -26,7 +26,7 @@ public:
|
||||||
void process(const IQSampleVector& samples_in, SampleVector& samples_out);
|
void process(const IQSampleVector& samples_in, SampleVector& samples_out);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const Coeff m_freq_scale_factor;
|
const Sample m_freq_scale_factor;
|
||||||
IQSample m_last_sample;
|
IQSample m_last_sample;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -56,10 +56,10 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Coeff m_minfreq, m_maxfreq;
|
Sample m_minfreq, m_maxfreq;
|
||||||
Coeff m_iqfilter_b0, m_iqfilter_a1, m_iqfilter_a2;
|
Sample m_phasor_b0, m_phasor_a1, m_phasor_a2;
|
||||||
Coeff m_loopfilter_b0, m_loopfilter_b1;
|
Sample m_phasor_i1, m_phasor_i2, m_phasor_q1, m_phasor_q2;
|
||||||
Sample m_iqfilter_i1, m_iqfilter_i2, m_iqfilter_q1, m_iqfilter_q2;
|
Sample m_loopfilter_b0, m_loopfilter_b1;
|
||||||
Sample m_loopfilter_x1;
|
Sample m_loopfilter_x1;
|
||||||
Sample m_freq, m_phase;
|
Sample m_freq, m_phase;
|
||||||
Sample m_minsignal;
|
Sample m_minsignal;
|
||||||
|
|
6
SoftFM.h
6
SoftFM.h
|
@ -10,12 +10,10 @@ typedef std::vector<IQSample> IQSampleVector;
|
||||||
typedef double Sample;
|
typedef double Sample;
|
||||||
typedef std::vector<Sample> SampleVector;
|
typedef std::vector<Sample> SampleVector;
|
||||||
|
|
||||||
typedef double Coeff;
|
|
||||||
typedef std::vector<Coeff> CoeffVector;
|
|
||||||
|
|
||||||
|
|
||||||
/** Compute mean and RMS over a sample vector. */
|
/** 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 vsum = 0;
|
||||||
Sample vsumsq = 0;
|
Sample vsumsq = 0;
|
||||||
|
|
Loading…
Reference in New Issue