mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-13 09:07:27 -05:00
330 WIP - changing to 45 degree rotation before demodulation.
This commit is contained in:
@@ -20,11 +20,20 @@ import io.github.dsheirer.sample.complex.Complex;
|
||||
public class DQPSKSymbolPhaseErrorCalculator extends QPSKSymbolPhaseErrorCalculator
|
||||
{
|
||||
//Negative 45 degrees rotation to offset for differential additive 45 degrees of rotation
|
||||
public static final Complex DIFFERENTIAL_OFFSET = Complex.fromAngle(Math.PI / -4.0d);
|
||||
public static final Complex DIFFERENTIAL_OFFSET = Complex.fromAngle(Math.PI / 4.0d);
|
||||
|
||||
@Override
|
||||
public void adjust(Complex symbol)
|
||||
{
|
||||
symbol.multiply(DIFFERENTIAL_OFFSET);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getPhaseError(Complex symbol)
|
||||
{
|
||||
Complex copy = symbol.copy();
|
||||
|
||||
copy.multiply(DIFFERENTIAL_OFFSET);
|
||||
return super.getPhaseError(copy);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,33 +25,34 @@ public class InterpolatingSymbolBuffer
|
||||
|
||||
private float[] mDelayLineInphase;
|
||||
private float[] mDelayLineQuadrature;
|
||||
private float mMu; //Sample Counter
|
||||
private float mGainMu = 0.05f; //Sample Counter Gain
|
||||
private float mOmega;
|
||||
private float mGainOmega = 0.1f * mGainMu * mGainMu;
|
||||
private float mOmegaRel = 0.005f;
|
||||
private float mOmegaMid;
|
||||
private float mSamplingPoint; //Sample Counter
|
||||
private float mSampleCounterGain = 0.05f; //Sample Counter Gain
|
||||
private float mSamplesPerSymbol;
|
||||
private float mDetectedSamplesPerSymbol;
|
||||
private float mDetectedSamplesPerSymbolGain = 0.1f * mSampleCounterGain * mSampleCounterGain;
|
||||
private float mMaxDeviation = 0.005f;
|
||||
|
||||
private int mDelayLinePointer = 0;
|
||||
private float mSamplesPerSymbol;
|
||||
private int mTwiceSamplesPerSymbol;
|
||||
private RealInterpolator mInterpolator = new RealInterpolator(1.0f);
|
||||
private SymbolDecisionData2 mSymbolDecisionData2;
|
||||
|
||||
public InterpolatingSymbolBuffer(float samplesPerSymbol)
|
||||
{
|
||||
mSamplesPerSymbol = samplesPerSymbol;
|
||||
mMu = samplesPerSymbol;
|
||||
mSamplingPoint = samplesPerSymbol;
|
||||
mTwiceSamplesPerSymbol = (int)Math.floor(2.0 * samplesPerSymbol);
|
||||
mDelayLineInphase = new float[2 * mTwiceSamplesPerSymbol];
|
||||
mDelayLineQuadrature = new float[2 * mTwiceSamplesPerSymbol];
|
||||
mOmega = samplesPerSymbol;
|
||||
mOmegaMid = samplesPerSymbol;
|
||||
mDetectedSamplesPerSymbol = samplesPerSymbol;
|
||||
mSamplesPerSymbol = samplesPerSymbol;
|
||||
|
||||
mSymbolDecisionData2 = new SymbolDecisionData2((int)samplesPerSymbol);
|
||||
}
|
||||
|
||||
public void receive(Complex currentSample)
|
||||
{
|
||||
mMu--;
|
||||
mSymbolDecisionData2.receive(currentSample);
|
||||
mSamplingPoint--;
|
||||
|
||||
//Fill up the delay line to use with the interpolator
|
||||
mDelayLineInphase[mDelayLinePointer] = currentSample.inphase();
|
||||
@@ -62,6 +63,7 @@ public class InterpolatingSymbolBuffer
|
||||
//Increment pointer and keep pointer in bounds
|
||||
mDelayLinePointer++;
|
||||
mDelayLinePointer = mDelayLinePointer % mTwiceSamplesPerSymbol;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,7 +72,7 @@ public class InterpolatingSymbolBuffer
|
||||
*/
|
||||
public void increaseSampleCounter(float samplesToAdd)
|
||||
{
|
||||
mMu += samplesToAdd;
|
||||
mSamplingPoint += samplesToAdd;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,13 +83,13 @@ public class InterpolatingSymbolBuffer
|
||||
*/
|
||||
public void resetAndAdjust(float symbolTimingError)
|
||||
{
|
||||
//mOmega is samples per symbol and is constrained to floating between +/- .005 of the nominal samples per
|
||||
//mDetectedSamplesPerSymbol is samples per symbol and is constrained to floating between +/- .005 of the nominal samples per
|
||||
//symbol
|
||||
mOmega = mOmega + mGainOmega * -symbolTimingError;
|
||||
mOmega = mOmegaMid + clip(mOmega - mOmegaMid, mOmegaRel);
|
||||
mDetectedSamplesPerSymbol = mDetectedSamplesPerSymbol + mDetectedSamplesPerSymbolGain * symbolTimingError;
|
||||
mDetectedSamplesPerSymbol = mSamplesPerSymbol + clip(mDetectedSamplesPerSymbol - mSamplesPerSymbol, mMaxDeviation);
|
||||
|
||||
//Add another symbol's worth of samples to the counter and adjust timing based on gardner error
|
||||
increaseSampleCounter((mOmega + (mGainMu * -symbolTimingError)));
|
||||
increaseSampleCounter((mDetectedSamplesPerSymbol + (mSampleCounterGain * symbolTimingError)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -95,7 +97,7 @@ public class InterpolatingSymbolBuffer
|
||||
*/
|
||||
public boolean hasSymbol()
|
||||
{
|
||||
return mMu < 1.0f;
|
||||
return mSamplingPoint < 1.0f;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -105,7 +107,7 @@ public class InterpolatingSymbolBuffer
|
||||
public Complex getMiddleSample()
|
||||
{
|
||||
/* Calculate interpolated middle sample and current sample */
|
||||
mMiddleSample.setValues(getInphase(mMu), getQuadrature(mMu));
|
||||
mMiddleSample.setValues(getInphase(mSamplingPoint), getQuadrature(mSamplingPoint));
|
||||
|
||||
return mMiddleSample;
|
||||
}
|
||||
@@ -116,17 +118,18 @@ public class InterpolatingSymbolBuffer
|
||||
*/
|
||||
public Complex getCurrentSample()
|
||||
{
|
||||
float half_omega = mOmega / 2.0f;
|
||||
int half_sps = (int)Math.floor(half_omega);
|
||||
float half_mu = mMu + half_omega - half_sps;
|
||||
float halfDetectedSamplesPerSymbol = mDetectedSamplesPerSymbol / 2.0f;
|
||||
int halfSamplingPointOffset = (int)Math.floor(halfDetectedSamplesPerSymbol);
|
||||
float halfSamplingPoint = mSamplingPoint + halfDetectedSamplesPerSymbol - halfSamplingPointOffset;
|
||||
|
||||
if(half_mu > 1.0)
|
||||
if(halfSamplingPoint > 1.0)
|
||||
{
|
||||
half_mu -= 1.0;
|
||||
half_sps += 1;
|
||||
halfSamplingPoint -= 1.0;
|
||||
halfSamplingPointOffset += 1;
|
||||
}
|
||||
|
||||
mCurrentSample.setValues(getInphase(half_mu, half_sps), getQuadrature(half_mu, half_sps));
|
||||
mCurrentSample.setValues(getInphase(halfSamplingPointOffset, halfSamplingPoint),
|
||||
getQuadrature(halfSamplingPointOffset, halfSamplingPoint));
|
||||
|
||||
return mCurrentSample;
|
||||
}
|
||||
@@ -136,11 +139,10 @@ public class InterpolatingSymbolBuffer
|
||||
* be used to support an external eye-diagram chart.
|
||||
* @return symbol decision data.
|
||||
*/
|
||||
public SymbolDecisionData getSymbolDecisionData()
|
||||
public SymbolDecisionData2 getSymbolDecisionData()
|
||||
{
|
||||
//TODO: I think that delay line pointer needs to have +4 added to it since the filter is 8 taps long
|
||||
return new SymbolDecisionData(mDelayLineInphase, mDelayLineQuadrature,
|
||||
mSamplesPerSymbol, mDelayLinePointer, mMu);
|
||||
mSymbolDecisionData2.setSamplingPoint(mSamplingPoint);
|
||||
return mSymbolDecisionData2;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -155,12 +157,13 @@ public class InterpolatingSymbolBuffer
|
||||
|
||||
/**
|
||||
* Returns the interpolated inphase value for the specified offset
|
||||
* @param delayLineOffset offset into the inphase delay line buffer
|
||||
* @param interpolation into the buffer to calculate the interpolated sample
|
||||
* @return inphase value of the interpolated sample
|
||||
*/
|
||||
public float getInphase(float interpolation, int indexOffet)
|
||||
public float getInphase(int delayLineOffset, float interpolation)
|
||||
{
|
||||
return mInterpolator.filter(mDelayLineInphase, mDelayLinePointer + indexOffet, interpolation);
|
||||
return mInterpolator.filter(mDelayLineInphase, mDelayLinePointer + delayLineOffset, interpolation);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -175,12 +178,13 @@ public class InterpolatingSymbolBuffer
|
||||
|
||||
/**
|
||||
* Returns the interpolated quadrature value for the specified offset
|
||||
* @param delayLineOffset offset into the quadrature delay line buffer
|
||||
* @param interpolation into the buffer to calculate the interpolated sample
|
||||
* @return quadrature value of the interpolated sample
|
||||
*/
|
||||
public float getQuadrature(float interpolation, int indexOffset)
|
||||
public float getQuadrature(int delayLineOffset, float interpolation)
|
||||
{
|
||||
return mInterpolator.filter(mDelayLineQuadrature, mDelayLinePointer + indexOffset, interpolation);
|
||||
return mInterpolator.filter(mDelayLineQuadrature, mDelayLinePointer + delayLineOffset, interpolation);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -34,7 +34,7 @@ public class QPSKDemodulator implements ComplexSampleListener
|
||||
private Listener<Double> mPLLErrorListener;
|
||||
private Listener<Double> mPLLFrequencyListener;
|
||||
private Listener<Dibit> mDibitListener;
|
||||
private Listener<SymbolDecisionData> mSymbolDecisionDataListener;
|
||||
private Listener<SymbolDecisionData2> mSymbolDecisionDataListener;
|
||||
|
||||
private Complex mPreviousSample = new Complex(0, 0);
|
||||
private Complex mPreviousMiddleSample = new Complex(0, 0);
|
||||
@@ -47,6 +47,7 @@ public class QPSKDemodulator implements ComplexSampleListener
|
||||
private float mSymbolTimingError;
|
||||
private double mSampleRate;
|
||||
|
||||
|
||||
/**
|
||||
* Decoder for Quaternary Phase Shift Keying (QPSK) and Differential QPSK (DQPSK). This decoder uses both a
|
||||
* phase-locked loop and a gardner symbol timing error detector to automatically align to the incoming carrier
|
||||
@@ -129,6 +130,16 @@ public class QPSKDemodulator implements ComplexSampleListener
|
||||
mMiddleSymbol.normalize();
|
||||
mCurrentSymbol.normalize();
|
||||
|
||||
//Send to an external constellation symbol listener when registered
|
||||
if(mSymbolListener != null)
|
||||
{
|
||||
mSymbolListener.receive(mCurrentSymbol);
|
||||
}
|
||||
|
||||
//We rotate the symbol from star pattern to polar pattern to facilitate phase error calculation
|
||||
// mSymbolPhaseErrorCalculator.adjust(mCurrentSymbol);
|
||||
// mSymbolPhaseErrorCalculator.adjust(mMiddleSymbol);
|
||||
|
||||
//Symbol timing error calculations
|
||||
mSymbolTimingError = mGardnerDetector.getError(mPreviousSymbol, mMiddleSymbol, mCurrentSymbol);
|
||||
mInterpolatingSymbolBuffer.resetAndAdjust(mSymbolTimingError);
|
||||
@@ -138,20 +149,12 @@ public class QPSKDemodulator implements ComplexSampleListener
|
||||
mPreviousMiddleSample.setValues(mMiddleSample);
|
||||
mPreviousSymbol.setValues(mCurrentSymbol);
|
||||
|
||||
//Send to an external constellation symbol listener when registered
|
||||
if(mSymbolListener != null)
|
||||
{
|
||||
mSymbolListener.receive(mCurrentSymbol);
|
||||
}
|
||||
|
||||
//Adjust the current symbol as necessary (e.g. for differential encoding)
|
||||
mSymbolPhaseErrorCalculator.adjust(mCurrentSymbol);
|
||||
|
||||
//Calculate the phase error of the current symbol relative to the expected constellation and provide
|
||||
//feedback to the PLL
|
||||
mPhaseError = mSymbolPhaseErrorCalculator.getPhaseError(mCurrentSymbol);
|
||||
|
||||
mPhaseError = GardnerDetector.clip(mPhaseError, 0.2f);
|
||||
mPhaseError = GardnerDetector.clip(mPhaseError, 0.15f);
|
||||
mPLL.adjust(mPhaseError);
|
||||
|
||||
if(mPLLErrorListener != null)
|
||||
@@ -210,7 +213,7 @@ public class QPSKDemodulator implements ComplexSampleListener
|
||||
mPLLFrequencyListener = listener;
|
||||
}
|
||||
|
||||
public void setSymbolDecisionDataListener(Listener<SymbolDecisionData> listener)
|
||||
public void setSymbolDecisionDataListener(Listener<SymbolDecisionData2> listener)
|
||||
{
|
||||
mSymbolDecisionDataListener = listener;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
/*******************************************************************************
|
||||
* sdr-trunk
|
||||
* Copyright (C) 2014-2018 Dennis Sheirer
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
|
||||
* License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any
|
||||
* later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program.
|
||||
* If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
******************************************************************************/
|
||||
package io.github.dsheirer.dsp.psk;
|
||||
|
||||
import io.github.dsheirer.buffer.ComplexCircularBuffer;
|
||||
import io.github.dsheirer.sample.complex.Complex;
|
||||
|
||||
public class SymbolDecisionData2
|
||||
{
|
||||
private ComplexCircularBuffer mBuffer;
|
||||
private float mSamplingPoint;
|
||||
|
||||
public SymbolDecisionData2(int samplesPerSymbol)
|
||||
{
|
||||
mBuffer = new ComplexCircularBuffer(2 * samplesPerSymbol);
|
||||
}
|
||||
|
||||
public void receive(float inphase, float quadrature)
|
||||
{
|
||||
mBuffer.put(new Complex(inphase, quadrature));
|
||||
}
|
||||
|
||||
public void receive(Complex complex)
|
||||
{
|
||||
mBuffer.put(complex.copy());
|
||||
}
|
||||
|
||||
public void setSamplingPoint(float samplingPoint)
|
||||
{
|
||||
mSamplingPoint = samplingPoint;
|
||||
}
|
||||
|
||||
public float getSamplingPoint()
|
||||
{
|
||||
return mSamplingPoint;
|
||||
}
|
||||
|
||||
public Complex[] getDemodulated()
|
||||
{
|
||||
Complex[] samples = mBuffer.getAll();
|
||||
|
||||
int length = samples.length / 2;
|
||||
|
||||
Complex[] demodulated = new Complex[length];
|
||||
|
||||
for(int x = 0; x < samples.length / 2; x++)
|
||||
{
|
||||
Complex copy = samples[length + x].copy();
|
||||
copy.multiply(samples[x].conjugate());
|
||||
demodulated[x] = copy;
|
||||
}
|
||||
|
||||
return demodulated;
|
||||
}
|
||||
}
|
||||
@@ -192,7 +192,12 @@ public class CostasLoop implements IPhaseLockedLoop
|
||||
/* Limit frequency to +/- maximum loop frequency */
|
||||
limitFrequency();
|
||||
|
||||
mErrorBuffer.put(phaseError);
|
||||
// checkLoopBandwidth();
|
||||
}
|
||||
|
||||
private void checkLoopBandwidth()
|
||||
{
|
||||
mErrorBuffer.put(mLoopFrequency);
|
||||
|
||||
double standardDeviation = mErrorBuffer.standardDeviation();
|
||||
|
||||
|
||||
@@ -22,9 +22,9 @@ public enum Tracking
|
||||
// FINE(150.0, 0.0001, 0.001),
|
||||
// LOCKED(200.0, 0.0, 0.0001);
|
||||
SEARCHING(100.0, 0.4, Math.PI),
|
||||
COARSE(150.0, 0.2, 0.4),
|
||||
FINE(175.0, 0.1, 0.2),
|
||||
LOCKED(200.0, 0.0, 0.1);
|
||||
COARSE(200.0, 0.2, 0.4),
|
||||
FINE(400.0, 0.1, 0.2),
|
||||
LOCKED(600.0, 0.0, 0.1);
|
||||
|
||||
private double mLoopBandwidth;
|
||||
private double mThresholdMinimum;
|
||||
|
||||
Reference in New Issue
Block a user