Improve normalisation, so output doesn't exceed 1

This commit is contained in:
Jon Beniston 2023-09-04 09:32:39 +01:00
parent fdd73c9d99
commit a5214e3002
1 changed files with 30 additions and 10 deletions

View File

@ -89,18 +89,38 @@ public:
else else
{ {
// Calculate maximum output of filter, assuming upsampled bipolar input E.g. [1 0 0 -1 0 0..] // Calculate maximum output of filter, assuming upsampled bipolar input E.g. [1 0 0 -1 0 0..]
// This doesn't necessarily include the centre tap, so we try each offset // This doesn't necessarily include the centre tap, as ISI there should be zero,
double maxGain = 0.0; // it's often at the midpoint between two symbols. However, depending on beta,
for (i = 0; i < samplesPerSymbol; i++) // the input that produces the worst case can vary, so we currently try them all
double maxGain = 0;
for (int input = 0; input < (1 << symbolSpan); input++)
{ {
double g = 0.0; double maxV = 0;
for (j = 0; j < (int)m_taps.size() - 1; j += samplesPerSymbol) for(int i = 0; i < nTaps; i++) {
g += std::fabs(2.0 * m_taps[j]); m_samples[i] = 0;
if ((i & 1) == 0) }
g += std::fabs(m_taps[j]); for (int i = 0; i < symbolSpan; i++)
if (g > maxGain) {
maxGain = g; Type sym = (input >> i) & 1 ? 1 : -1;
for (int j = 0; j < samplesPerSymbol; j++)
{
Type out;
if (j == 1) {
out = filter(sym);
} else {
out = filter(0);
}
double outAbs = abs(out);
if (outAbs > maxV) {
maxV = outAbs;
}
}
}
if (maxV > maxGain) {
maxGain = maxV;
}
} }
// Scale up so maximum out is 1 // Scale up so maximum out is 1
for(i = 0; i < (int)m_taps.size(); i++) for(i = 0; i < (int)m_taps.size(); i++)
m_taps[i] /= maxGain; m_taps[i] /= maxGain;