mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-14 01:27:34 -05:00
[WIP] Creates a new AFSK-1200 correlation decoder and updates the
Fleetsync II decoder to use it. Adds instrumented version of the decoder and a new Fleetsync2 FX pane to the DemodulatorViewerFX tool. Note: the remaining AFSK-1200 based decoders will all be ported to use this new AFSK1200 decoder (MDC1200, Tait1200, LowJack1200).
This commit is contained in:
290
src/main/java/io/github/dsheirer/dsp/afsk/AFSK1200Decoder.java
Normal file
290
src/main/java/io/github/dsheirer/dsp/afsk/AFSK1200Decoder.java
Normal file
@@ -0,0 +1,290 @@
|
||||
/*******************************************************************************
|
||||
* 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.afsk;
|
||||
|
||||
import io.github.dsheirer.bits.MessageFramer;
|
||||
import io.github.dsheirer.buffer.FloatAveragingBuffer;
|
||||
import io.github.dsheirer.dsp.filter.design.FilterDesignException;
|
||||
import io.github.dsheirer.dsp.filter.fir.FIRFilterSpecification;
|
||||
import io.github.dsheirer.dsp.filter.fir.real.RealFIRFilter2;
|
||||
import io.github.dsheirer.dsp.filter.fir.remez.RemezFIRFilterDesigner;
|
||||
import io.github.dsheirer.dsp.filter.resample.RealResampler;
|
||||
import io.github.dsheirer.dsp.mixer.IOscillator;
|
||||
import io.github.dsheirer.dsp.mixer.Oscillator;
|
||||
import io.github.dsheirer.sample.Listener;
|
||||
import io.github.dsheirer.sample.buffer.ReusableBuffer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Audio Frequency Shift Keying (AFSK) 1200-baud correlation decoder for decoding 8 kHz FM-demodulated audio samples.
|
||||
*
|
||||
* Note: internally the incoming 8 kHz sample rate is resampled to 7200 Hz to be an integral of the 1200 Hz baud rate
|
||||
* which equates to six samples per symbol. Each symbol is correlated over an eight sample period with correlation
|
||||
* values averaged over a seven correlation value period.
|
||||
*
|
||||
* Provides normal or inverted decoded output.
|
||||
*/
|
||||
public class AFSK1200Decoder implements Listener<ReusableBuffer>
|
||||
{
|
||||
private final static Logger mLog = LoggerFactory.getLogger(AFSK1200Decoder.class);
|
||||
|
||||
public enum Output
|
||||
{
|
||||
NORMAL, INVERTED
|
||||
}
|
||||
|
||||
public static final double SAMPLE_RATE = 7200.0d;
|
||||
public static final int SAMPLES_PER_SYMBOL = 6; //SAMPLE_RATE / 1200 baud;
|
||||
|
||||
//Correlation period of 8 samples works well and should align nicely with SIMD intrinsic vector sizes
|
||||
public static final int CORRELATION_PERIOD = SAMPLES_PER_SYMBOL + 2;
|
||||
public static final int AVERAGING_PERIOD = SAMPLES_PER_SYMBOL + 1;
|
||||
public static final double MARK = 1200.0;
|
||||
public static final double SPACE = 1800.0;
|
||||
public static final float TIMING_ERROR_GAIN = 1.0f / 3.0f; //Timing error adjustments over 3 symbol periods
|
||||
|
||||
private static float[] sBandPassFilterCoefficients;
|
||||
|
||||
static
|
||||
{
|
||||
FIRFilterSpecification specification = FIRFilterSpecification.bandPassBuilder()
|
||||
.sampleRate(8000)
|
||||
.stopFrequency1(1000)
|
||||
.passFrequencyBegin(1100)
|
||||
.passFrequencyEnd(1900)
|
||||
.stopFrequency2(2000)
|
||||
.stopRipple(0.000001)
|
||||
.passRipple(0.00001)
|
||||
.build();
|
||||
|
||||
try
|
||||
{
|
||||
RemezFIRFilterDesigner designer = new RemezFIRFilterDesigner(specification);
|
||||
|
||||
if(designer.isValid())
|
||||
{
|
||||
sBandPassFilterCoefficients = designer.getImpulseResponse();
|
||||
}
|
||||
}
|
||||
catch(FilterDesignException fde)
|
||||
{
|
||||
mLog.error("Filter design error", fde);
|
||||
}
|
||||
}
|
||||
|
||||
private Correlator mCorrelator1200 = new Correlator(SAMPLE_RATE, MARK, AVERAGING_PERIOD, CORRELATION_PERIOD);
|
||||
private Correlator mCorrelator1800 = new Correlator(SAMPLE_RATE, SPACE, AVERAGING_PERIOD, CORRELATION_PERIOD);
|
||||
private float[] mCorrelationValues1200;
|
||||
private float[] mCorrelationValues1800;
|
||||
|
||||
protected boolean mNormalOutput;
|
||||
protected float mSymbolTimingGain = TIMING_ERROR_GAIN;
|
||||
protected AFSKSampleBuffer mSampleBuffer;
|
||||
protected AFSKTimingErrorDetector mTimingErrorDetector = new AFSKTimingErrorDetector(SAMPLES_PER_SYMBOL);
|
||||
private RealFIRFilter2 mBandPassFilter = new RealFIRFilter2(sBandPassFilterCoefficients);
|
||||
protected MessageFramer mMessageFramer;
|
||||
private boolean mSampleDecision;
|
||||
|
||||
//Resample to an integral of the baud rate 1200 baud * 6 samples per symbol = 7200.0 Hertz
|
||||
private RealResampler mResampler = new RealResampler(8000.0, SAMPLE_RATE, 2000, 1);
|
||||
|
||||
/**
|
||||
* Constructs a decoder using the provided arguments.
|
||||
*
|
||||
* @param sampleBuffer for storing incoming samples and calculating symbols
|
||||
* @param detector for timing error alignment
|
||||
* @param output NORMAL: 1200Hz = Mark(1) and 1800Hz = Space(0), or INVERTED (vice-versa)
|
||||
*/
|
||||
public AFSK1200Decoder(AFSKSampleBuffer sampleBuffer, AFSKTimingErrorDetector detector, Output output)
|
||||
{
|
||||
mTimingErrorDetector = detector;
|
||||
mSampleBuffer = sampleBuffer;
|
||||
mSampleBuffer.setTimingGain(mSymbolTimingGain);
|
||||
mResampler.setListener(new Decoder());
|
||||
mNormalOutput = (output == Output.NORMAL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a decoder using the provided arguments.
|
||||
*
|
||||
* @param output NORMAL: 1200Hz = Mark(1) and 1800Hz = Space(0), or INVERTED (vice-versa)
|
||||
*/
|
||||
public AFSK1200Decoder(Output output)
|
||||
{
|
||||
this(new AFSKSampleBuffer(SAMPLES_PER_SYMBOL, TIMING_ERROR_GAIN),
|
||||
new AFSKTimingErrorDetector(SAMPLES_PER_SYMBOL), output);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disposes of all references to prepare for garbage collection
|
||||
*/
|
||||
public void dispose()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the buffer samples by converting all samples to boolean values reflecting if the sample value is
|
||||
* greater than zero (or not). Average symbol timing offset is calculated for the full buffer and the offset is
|
||||
* adjusted and then each of the symbols are decoded using a simple majority decision.
|
||||
*
|
||||
* @param buffer containing 8.0 kHz unfiltered FM demodulated audio samples with sub-audible LTR signalling.
|
||||
*/
|
||||
@Override
|
||||
public void receive(ReusableBuffer buffer)
|
||||
{
|
||||
//TODO: remove the passband filter ... the correlators should be able to deal with the noise and the filters may be
|
||||
//TODO: introducing noise anyway
|
||||
// ReusableBuffer bandPassFiltered = mBandPassFilter.filter(buffer);
|
||||
// mResampler.resample(bandPassFiltered);
|
||||
mResampler.resample(buffer);
|
||||
}
|
||||
|
||||
protected void dispatch(boolean symbol)
|
||||
{
|
||||
if(mMessageFramer != null)
|
||||
{
|
||||
mMessageFramer.receive(mNormalOutput ? symbol : !symbol);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a listener to receive decoded LTR symbols.
|
||||
*
|
||||
* @param messageFramer to receive symbols.
|
||||
*/
|
||||
public void setMessageFramer(MessageFramer messageFramer)
|
||||
{
|
||||
mMessageFramer = messageFramer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the symbol listener from receiving decoded LTR symbols.
|
||||
*/
|
||||
public void removeListener()
|
||||
{
|
||||
mMessageFramer = null;
|
||||
}
|
||||
|
||||
|
||||
public class Decoder implements Listener<ReusableBuffer>
|
||||
{
|
||||
@Override
|
||||
public void receive(ReusableBuffer buffer)
|
||||
{
|
||||
//Calculate correlation values against each 1200/1800 reference signal
|
||||
mCorrelationValues1200 = mCorrelator1200.process(buffer);
|
||||
mCorrelationValues1800 = mCorrelator1800.process(buffer);
|
||||
|
||||
buffer.decrementUserCount();
|
||||
|
||||
for(int x = 0; x < mCorrelationValues1200.length; x++)
|
||||
{
|
||||
//1200 = Mark (1) and 1800 = Space (0)
|
||||
mSampleDecision = mCorrelationValues1200[x] > mCorrelationValues1800[x];
|
||||
mSampleBuffer.receive(mSampleDecision);
|
||||
mTimingErrorDetector.receive(mSampleDecision);
|
||||
|
||||
if(mSampleBuffer.hasSymbol())
|
||||
{
|
||||
dispatch(mSampleBuffer.getSymbol());
|
||||
mSampleBuffer.resetAndAdjust(mTimingErrorDetector.getError());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a correlation value for each FM demodulated sample against samples generated for an established
|
||||
* reference frequency, correlated and averaged over separate periods relative to the samples per symbol period.
|
||||
*
|
||||
* The sample rate of the correlator should be an integral value of the target frequency for optimal performance,
|
||||
* This correlator only works across integral sample periods and does not provide intra-sample interpolation.
|
||||
*
|
||||
* Correlation period (ie number of samples) should be relative to the samples per symbol. You may have to
|
||||
* experiment with various values of (samplesPerSymbol +/- 1, 2 or 3) to obtain the optimal decoder performance.
|
||||
*
|
||||
* Averaging period defines the number of correlation values to average before producing the final correlation
|
||||
* value for each sample.
|
||||
*/
|
||||
public class Correlator
|
||||
{
|
||||
private FloatAveragingBuffer mAveragingBuffer;
|
||||
private float[] mReferenceSamples;
|
||||
private float[] mDemodulatedSamples;
|
||||
private float[] mCorrelationValues;
|
||||
private float mCorrelationAccumulator;
|
||||
|
||||
/**
|
||||
* Constructs a correlator instance,
|
||||
*
|
||||
* @param sampleRate of the incoming sample stream. Note: this should be an integral of the symbol rate.
|
||||
* @param frequency of the mark or space symbol to test for correlation
|
||||
* @param averagingPeriod is the number of correlation values to average each period
|
||||
* @param correlationPeriod is the number of samples to correlate each period
|
||||
*/
|
||||
public Correlator(double sampleRate, double frequency, int averagingPeriod, int correlationPeriod)
|
||||
{
|
||||
mAveragingBuffer = new FloatAveragingBuffer(averagingPeriod);
|
||||
|
||||
IOscillator referenceSignalGenerator = new Oscillator(frequency, sampleRate);
|
||||
mReferenceSamples = referenceSignalGenerator.generateReal(correlationPeriod);
|
||||
|
||||
mDemodulatedSamples = new float[correlationPeriod];
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes each sample in the incoming sample buffer against a generated reference sample set for one symbol
|
||||
* period to derive a correlation value that is in-turn averaged over one symbol period.
|
||||
*
|
||||
* @param reusableBuffer containing FM demodulated samples
|
||||
* @return a reusable array of correlation values for each sample
|
||||
*/
|
||||
public float[] process(ReusableBuffer reusableBuffer)
|
||||
{
|
||||
if(mCorrelationValues == null || mCorrelationValues.length != reusableBuffer.getSampleCount())
|
||||
{
|
||||
mCorrelationValues = new float[reusableBuffer.getSampleCount()];
|
||||
}
|
||||
|
||||
float[] samples = reusableBuffer.getSamples();
|
||||
|
||||
int y;
|
||||
|
||||
for(int x = 0; x < samples.length; x++)
|
||||
{
|
||||
//Note: we're using array copy and dot product structures that the JRE can promote to SIMD intrinsics
|
||||
//when the host processor supports SIMD instructions
|
||||
System.arraycopy(mDemodulatedSamples, 1, mDemodulatedSamples, 0, mDemodulatedSamples.length - 1);
|
||||
mDemodulatedSamples[mDemodulatedSamples.length - 1] = samples[x];
|
||||
|
||||
mCorrelationAccumulator = 0.0f;
|
||||
|
||||
for(y = 0; y < mDemodulatedSamples.length; y++)
|
||||
{
|
||||
mCorrelationAccumulator += mDemodulatedSamples[y] * mReferenceSamples[y];
|
||||
}
|
||||
|
||||
//Add the absolute value of correlation accumulator value to the averaging buffer and store the current
|
||||
//average as the correlation value for this sample. We use absolute value because we don't care if the
|
||||
//signal is out of phase with the reference samples
|
||||
mCorrelationValues[x] = mAveragingBuffer.get(Math.abs(mCorrelationAccumulator));
|
||||
}
|
||||
|
||||
return mCorrelationValues;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*******************************************************************************
|
||||
* 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.afsk;
|
||||
|
||||
import io.github.dsheirer.sample.Broadcaster;
|
||||
import io.github.dsheirer.sample.Listener;
|
||||
|
||||
public class AFSK1200DecoderInstrumented extends AFSK1200Decoder
|
||||
{
|
||||
private Broadcaster<Boolean> mSymbolBroadcaster = new Broadcaster<>();
|
||||
|
||||
public AFSK1200DecoderInstrumented(boolean invertOutput)
|
||||
{
|
||||
super(new AFSKSampleBufferInstrumented(SAMPLES_PER_SYMBOL, TIMING_ERROR_GAIN),
|
||||
new AFSKTimingErrorDetectorInstrumented(SAMPLES_PER_SYMBOL), Output.NORMAL);
|
||||
}
|
||||
|
||||
public AFSKSampleBufferInstrumented getSampleBuffer()
|
||||
{
|
||||
return (AFSKSampleBufferInstrumented)mSampleBuffer;
|
||||
}
|
||||
|
||||
public AFSKTimingErrorDetectorInstrumented getErrorDetector()
|
||||
{
|
||||
return (AFSKTimingErrorDetectorInstrumented)mTimingErrorDetector;
|
||||
}
|
||||
|
||||
protected void dispatch(boolean symbol)
|
||||
{
|
||||
if(mMessageFramer != null)
|
||||
{
|
||||
mMessageFramer.receive(mNormalOutput ? symbol : !symbol);
|
||||
}
|
||||
|
||||
mSymbolBroadcaster.broadcast(symbol);
|
||||
}
|
||||
|
||||
public void addListener(Listener<Boolean> listener)
|
||||
{
|
||||
mSymbolBroadcaster.addListener(listener);
|
||||
}
|
||||
}
|
||||
121
src/main/java/io/github/dsheirer/dsp/afsk/AFSKSampleBuffer.java
Normal file
121
src/main/java/io/github/dsheirer/dsp/afsk/AFSKSampleBuffer.java
Normal file
@@ -0,0 +1,121 @@
|
||||
/*******************************************************************************
|
||||
* 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.afsk;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class AFSKSampleBuffer
|
||||
{
|
||||
private final static Logger mLog = LoggerFactory.getLogger(AFSKSampleBuffer.class);
|
||||
|
||||
private final static float SYMBOL_SAMPLE_THRESHOLD = 1.0f;
|
||||
protected boolean[] mDelayLine;
|
||||
protected int mDelayLinePointer = 0;
|
||||
|
||||
private int mHalfIntegerSamplesPerSymbol;
|
||||
private int mPositiveSampleDecisionCount;
|
||||
protected int mTwiceSamplesPerSymbol;
|
||||
protected int mSymbolStart;
|
||||
protected int mSymbolEnd;
|
||||
protected int mSamplesPerSymbol;
|
||||
protected float mSymbolSamplingPoint;
|
||||
protected float mSymbolTimingGain;
|
||||
|
||||
/**
|
||||
* Buffer to store complex sample data and produce interpolated samples.
|
||||
* @param samplesPerSymbol
|
||||
*/
|
||||
public AFSKSampleBuffer(int samplesPerSymbol, float symbolTimingGain)
|
||||
{
|
||||
mSamplesPerSymbol = samplesPerSymbol;
|
||||
mSymbolTimingGain = symbolTimingGain;
|
||||
|
||||
mHalfIntegerSamplesPerSymbol = samplesPerSymbol / 2;
|
||||
mSymbolSamplingPoint = samplesPerSymbol;
|
||||
mTwiceSamplesPerSymbol = 2 * samplesPerSymbol;
|
||||
mDelayLine = new boolean[2 * mTwiceSamplesPerSymbol];
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores the sample in the sample buffer to support making symbol decisions.
|
||||
*
|
||||
* Note: use the hasSymbol() method to determine if sufficient samples have been collected to make a symbol
|
||||
* determination.
|
||||
*
|
||||
* @param sample to store in the sample buffer
|
||||
*/
|
||||
public void receive(boolean sample)
|
||||
{
|
||||
mSymbolSamplingPoint--;
|
||||
|
||||
mDelayLine[mDelayLinePointer] = sample;
|
||||
mDelayLine[mDelayLinePointer + mTwiceSamplesPerSymbol] = sample;
|
||||
|
||||
//Increment pointer and keep pointer in bounds
|
||||
mDelayLinePointer++;
|
||||
mDelayLinePointer = mDelayLinePointer % mTwiceSamplesPerSymbol;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjusts samples per symbol and symbol timing counters and increments the sample counter to collect another
|
||||
* symbol.
|
||||
*
|
||||
* @param symbolTimingError from a symbol timing error detector
|
||||
*/
|
||||
public void resetAndAdjust(float symbolTimingError)
|
||||
{
|
||||
mSymbolSamplingPoint += (mSamplesPerSymbol + (symbolTimingError * mSymbolTimingGain));
|
||||
}
|
||||
|
||||
public void setTimingGain(float gain)
|
||||
{
|
||||
mSymbolTimingGain = gain;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if this buffer has accumulated enough samples to represent a full symbol
|
||||
*/
|
||||
public boolean hasSymbol()
|
||||
{
|
||||
return mSymbolSamplingPoint < SYMBOL_SAMPLE_THRESHOLD;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the symbol as a majority decision where the number of positive/true samples are greater than half
|
||||
* of the samples per symbol. Symbol decision is based on the samples collected over the preceeding 1.0 to 2.0
|
||||
* symbol periods.
|
||||
*
|
||||
* @return a true symbol if the majority of the samples were true or positive, otherwise a false symbol.
|
||||
*/
|
||||
public boolean getSymbol()
|
||||
{
|
||||
mPositiveSampleDecisionCount = 0;
|
||||
|
||||
mSymbolStart = mDelayLinePointer;
|
||||
mSymbolEnd = mDelayLinePointer + mSamplesPerSymbol - 1;
|
||||
|
||||
for(int x = mSymbolStart; x <= mSymbolEnd; x++)
|
||||
{
|
||||
if(mDelayLine[x])
|
||||
{
|
||||
mPositiveSampleDecisionCount++;
|
||||
}
|
||||
}
|
||||
|
||||
return mPositiveSampleDecisionCount > mHalfIntegerSamplesPerSymbol;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*******************************************************************************
|
||||
* 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.afsk;
|
||||
|
||||
public class AFSKSampleBufferInstrumented extends AFSKSampleBuffer
|
||||
{
|
||||
public boolean mLastSymbol;
|
||||
|
||||
/**
|
||||
* Buffer to store complex sample data and produce interpolated samples.
|
||||
*
|
||||
* @param samplesPerSymbol
|
||||
* @param symbolTimingGain
|
||||
*/
|
||||
public AFSKSampleBufferInstrumented(int samplesPerSymbol, float symbolTimingGain)
|
||||
{
|
||||
super(samplesPerSymbol, symbolTimingGain);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sample delay buffer containing boolean (ie positive or negative) samples.
|
||||
*/
|
||||
public boolean[] getDelayLine()
|
||||
{
|
||||
return mDelayLine;
|
||||
}
|
||||
|
||||
/**
|
||||
* Current delay buffer pointer which points to where the next sample will be stored and/or the oldest sample in
|
||||
* the buffer.
|
||||
*/
|
||||
public int getDelayLinePointer()
|
||||
{
|
||||
return mDelayLinePointer;
|
||||
}
|
||||
|
||||
public int getDelayLineSecondPointer()
|
||||
{
|
||||
return mDelayLinePointer + mTwiceSamplesPerSymbol;
|
||||
}
|
||||
|
||||
/**
|
||||
* Current symbol timing gain value
|
||||
* @return
|
||||
*/
|
||||
public float getSymbolTimingGain()
|
||||
{
|
||||
return mSymbolTimingGain;
|
||||
}
|
||||
|
||||
public float getSamplesPerSymbol()
|
||||
{
|
||||
return mSamplesPerSymbol;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getSymbol()
|
||||
{
|
||||
mLastSymbol = super.getSymbol();
|
||||
return mLastSymbol;
|
||||
}
|
||||
|
||||
public boolean getLastSymbol()
|
||||
{
|
||||
return mLastSymbol;
|
||||
}
|
||||
|
||||
public int getSymbolStart()
|
||||
{
|
||||
return mSymbolStart;
|
||||
}
|
||||
|
||||
public int getSymbolEnd()
|
||||
{
|
||||
return mSymbolEnd;
|
||||
}
|
||||
}
|
||||
122
src/main/java/io/github/dsheirer/dsp/afsk/AFSKTest.java
Normal file
122
src/main/java/io/github/dsheirer/dsp/afsk/AFSKTest.java
Normal file
@@ -0,0 +1,122 @@
|
||||
/*******************************************************************************
|
||||
* 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.afsk;
|
||||
|
||||
import io.github.dsheirer.buffer.FloatAveragingBuffer;
|
||||
import io.github.dsheirer.dsp.mixer.IOscillator;
|
||||
import io.github.dsheirer.dsp.mixer.Oscillator;
|
||||
import io.github.dsheirer.sample.complex.Complex;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
public class AFSKTest
|
||||
{
|
||||
private final static Logger mLog = LoggerFactory.getLogger(AFSK1200Decoder.class);
|
||||
|
||||
private static final DecimalFormat df = new DecimalFormat("00.000");
|
||||
|
||||
public static String format(double value)
|
||||
{
|
||||
if(value > 0)
|
||||
{
|
||||
return " " + df.format(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
return df.format(value);
|
||||
}
|
||||
}
|
||||
|
||||
public static float[] generateAFSK1200(boolean[] symbols, int samplesPerSymbol, float gain)
|
||||
{
|
||||
float[] samples = new float[symbols.length * samplesPerSymbol];
|
||||
|
||||
Oscillator oscillator = new Oscillator(1200.0, (double)samplesPerSymbol * 1200);
|
||||
|
||||
for(int x = 0; x < symbols.length; x++)
|
||||
{
|
||||
oscillator.setFrequency(symbols[x] ? 1200.0 : 1800.0);
|
||||
|
||||
for(int y = 0; y < samplesPerSymbol; y++)
|
||||
{
|
||||
Complex sample = new Complex(oscillator.inphase(), oscillator.quadrature());
|
||||
sample.multiply(gain);
|
||||
samples[x * samplesPerSymbol + y] = sample.inphase();
|
||||
oscillator.rotate();
|
||||
}
|
||||
}
|
||||
|
||||
return samples;
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
int sampleSize = 6;
|
||||
|
||||
FloatAveragingBuffer avg1200 = new FloatAveragingBuffer(sampleSize);
|
||||
FloatAveragingBuffer avg1800 = new FloatAveragingBuffer(sampleSize);
|
||||
|
||||
IOscillator oscillator1200 = new Oscillator(1200.0, 7200.0);
|
||||
IOscillator oscillator1800 = new Oscillator(1800.0, 7200.0);
|
||||
oscillator1200.generateReal(1);
|
||||
oscillator1800.generateReal(1);
|
||||
|
||||
float[] reference1200 = oscillator1200.generateReal(sampleSize);
|
||||
float[] reference1800 = oscillator1800.generateReal(sampleSize);
|
||||
|
||||
boolean[] symbols = new boolean[]{true,false,true,false,true,false,true,false,true,true,true,false,true,false,
|
||||
false,false,true,false,false,false,false,true,false,true,true,true,true,false,true,true,false,true,false,
|
||||
true,false,true,false,true,false,true,false,true,false,true,false,true,false,true,false,true,false,true,
|
||||
false,true,false,true,false,true,false,true,false,true,false,true,false,true,false,true,false,true,false,
|
||||
true,false,true,false,true,false,true,false,true,false,true,false,true,false,true,false,true,false,true,
|
||||
false,true,false,true,false,true,false,true,false,true,false,true,false,true,false,true,false,true,false,
|
||||
true,false,true,false,true,false,true,false,true,false,true,false,true,false,true,false,true,false,true,
|
||||
false,true,false,true,false,true,false,true,false,true,false,true,false,true,false,true,false,true,false,
|
||||
true,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,
|
||||
false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false};
|
||||
|
||||
float[] samples = generateAFSK1200(symbols, 6, 0.5f);
|
||||
|
||||
mLog.debug("Length:" + samples.length);
|
||||
|
||||
int offset = 0;
|
||||
|
||||
float correlation1200 = 0.0f;
|
||||
float correlation1800 = 0.0f;
|
||||
|
||||
while(offset + sampleSize < samples.length)
|
||||
{
|
||||
correlation1200 = 0.0f;
|
||||
correlation1800 = 0.0f;
|
||||
|
||||
for(int x = 0; x < sampleSize; x++)
|
||||
{
|
||||
correlation1200 += reference1200[x] * samples[x + offset];
|
||||
correlation1800 += reference1800[x] * samples[x + offset];
|
||||
}
|
||||
|
||||
correlation1200 = avg1200.get(Math.abs(correlation1200));
|
||||
correlation1800 = avg1800.get(Math.abs(correlation1800));
|
||||
|
||||
mLog.debug(offset + " 1200:" + format(correlation1200) + " 1800:" + format(correlation1800) +
|
||||
" Decision: " + (correlation1200 > correlation1800 ? "0" : "1"));
|
||||
|
||||
offset++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
/*******************************************************************************
|
||||
* 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.afsk;
|
||||
|
||||
/**
|
||||
* Zero crossing error detector. Provides symbol timing error correction values by detecting zero-crossings within
|
||||
* each symbol period. Ideally there should be only 0 or 1 zero crossings within each symbol period. However, when
|
||||
* there is a slight DC offset in the demodulated samples, there can be up to 2 zero crossings within a symbol
|
||||
* period.
|
||||
*
|
||||
* This detector will only provide error corrections when there are 1 or 2 zero crossings detected. If the number
|
||||
* of zero crossings is greater than 2, then it is assumed that there is no signal present and the returned timing
|
||||
* error value is zero. This detector provides an error correction value relative to (approximately) the middle of
|
||||
* a symbol period and therefore continuously attempts to align zero crossings to the middle of the period.
|
||||
*
|
||||
* Since this detector does NOT use interpolation, the error signal will contain minor levels of symbol timing
|
||||
* jitter. Error signal values are reported as integrals of the sampling period.
|
||||
*/
|
||||
public class AFSKTimingErrorDetector
|
||||
{
|
||||
protected boolean[] mBuffer;
|
||||
protected int mDetectedZeroCrossing;
|
||||
protected float mSymbolMiddle;
|
||||
private int mZeroCrossingCount;
|
||||
|
||||
/**
|
||||
* Constructs the detector for the specified samples per symbol.
|
||||
*
|
||||
* @param samplesPerSymbol
|
||||
*/
|
||||
public AFSKTimingErrorDetector(int samplesPerSymbol)
|
||||
{
|
||||
mBuffer = new boolean[samplesPerSymbol];
|
||||
mSymbolMiddle = (float)(samplesPerSymbol - 1) / 2.0f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores the sample in the buffer. Use the getError() method once enough samples have been processed to determine
|
||||
* the error for a symbol period.
|
||||
*
|
||||
* @param sample
|
||||
*/
|
||||
public void receive(boolean sample)
|
||||
{
|
||||
//Shift all samples left and store new sample at the end
|
||||
System.arraycopy(mBuffer, 1, mBuffer, 0, mBuffer.length - 1);
|
||||
mBuffer[mBuffer.length - 1] = sample;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the symbol timing error for the samples processed thus far. This method should be invoked once per
|
||||
* symbol period, triggered via an external samples per symbol tracking process.
|
||||
*
|
||||
* @return symbol timing error calculated as the distance between the approximate symbol center and the next closest
|
||||
* zero crossing index. An error value of zero is returned if the number of zero crossings is less than one or
|
||||
* greater than two.
|
||||
*/
|
||||
public int getError()
|
||||
{
|
||||
mZeroCrossingCount = 0;
|
||||
|
||||
for(int x = 0; x < mBuffer.length - 1; x++)
|
||||
{
|
||||
if(mBuffer[x] ^ mBuffer[x + 1])
|
||||
{
|
||||
mDetectedZeroCrossing = x + 1;
|
||||
mZeroCrossingCount++;
|
||||
|
||||
if(mZeroCrossingCount > 1)
|
||||
{
|
||||
return 0; //Too many crossings
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(mZeroCrossingCount == 1)
|
||||
{
|
||||
if(mDetectedZeroCrossing > mSymbolMiddle)
|
||||
{
|
||||
return -(mBuffer.length - mDetectedZeroCrossing);
|
||||
}
|
||||
else
|
||||
{
|
||||
return mDetectedZeroCrossing + 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*******************************************************************************
|
||||
* 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.afsk;
|
||||
|
||||
import javafx.beans.property.SimpleIntegerProperty;
|
||||
|
||||
public class AFSKTimingErrorDetectorInstrumented extends AFSKTimingErrorDetector
|
||||
{
|
||||
public SimpleIntegerProperty timingError = new SimpleIntegerProperty();
|
||||
|
||||
/**
|
||||
* Constructs the detector for the specified samples per symbol.
|
||||
*
|
||||
* @param samplesPerSymbol
|
||||
*/
|
||||
public AFSKTimingErrorDetectorInstrumented(int samplesPerSymbol)
|
||||
{
|
||||
super(samplesPerSymbol);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getError()
|
||||
{
|
||||
int error = super.getError();
|
||||
|
||||
timingError.setValue(error);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
public int getDetectedZeroCrossing()
|
||||
{
|
||||
return mDetectedZeroCrossing;
|
||||
}
|
||||
|
||||
public boolean[] getBuffer()
|
||||
{
|
||||
return mBuffer;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user