mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-13 17:17:29 -05:00
[WIP] Updates the LTR-Standard and LTR-Net decoders to use a new LTR
decoder with a zero-crossing symbol timing error detector. The new decoder is optimized for 8 kHz FM demodulated audio produced by the AudioModule.
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
/*******************************************************************************
|
||||
* 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.fsk;
|
||||
|
||||
/**
|
||||
* Interface to receive sync state change events.
|
||||
*/
|
||||
public interface ISyncStateListener
|
||||
{
|
||||
void setSyncState(SyncState syncState);
|
||||
}
|
||||
221
src/main/java/io/github/dsheirer/dsp/fsk/LTRDecoder.java
Normal file
221
src/main/java/io/github/dsheirer/dsp/fsk/LTRDecoder.java
Normal file
@@ -0,0 +1,221 @@
|
||||
/*******************************************************************************
|
||||
* 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.fsk;
|
||||
|
||||
import io.github.dsheirer.dsp.filter.dc.IIRSinglePoleDCRemovalFilter;
|
||||
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.symbol.ISyncDetectListener;
|
||||
import io.github.dsheirer.sample.Listener;
|
||||
import io.github.dsheirer.sample.buffer.ReusableBuffer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Logic Trunked Radio (LTR) 300-baud FSK decoder is designed to operate against an 8 kHz FM demodulated audio stream.
|
||||
*
|
||||
* This decoder employs a zero-crossing timing error detector with adjustable symbol timing error gain. This decoder
|
||||
* also employs a synchronization monitor that automatically adjusts symbol timing error gain according to the quantity
|
||||
* of successful message sync pattern detections. This is optimized for LTR signals that periodically transmit idle
|
||||
* bursts and transmit continuous message streams during voice transmissions. The synchronization monitor adjusts to an
|
||||
* aggressive gain value when sync is lost and automatically reduces timing error gain as successive sync pattern
|
||||
* detections occur.
|
||||
*
|
||||
* FM demodulated sample buffers should not be filtered prior to this decoder. An internal DC-removal filter coupled
|
||||
* with a low-pass filter removes any tuning offset and/or audio components above 300 Hertz. The DC removal filter is
|
||||
* adjusted for a slower offset removal in order to prevent overly distorting the FSK signalling component. This mild
|
||||
* adjustment may not fully compensate for mis-tuned signals and may result in missed decodes of idle bursts. However,
|
||||
* the DC filter will track a mis-tuned signal to baseband quickly upon a continuous transmission.
|
||||
*/
|
||||
public class LTRDecoder implements Listener<ReusableBuffer>, ISyncDetectListener, ISyncStateListener
|
||||
{
|
||||
private final static Logger mLog = LoggerFactory.getLogger(LTRDecoder.class);
|
||||
|
||||
public static final float SAMPLES_PER_SYMBOL = 8000.0f / 300.0f;
|
||||
|
||||
protected static final float COARSE_TIMING_GAIN = 1.0f / 3.0f;
|
||||
protected static final float MEDIUM_TIMING_GAIN = 1.0f / 4.0f;
|
||||
protected static final float FINE_TIMING_GAIN = 1.0f / 5.0f;
|
||||
|
||||
private static float[] sLowPassFilterCoefficients;
|
||||
|
||||
static
|
||||
{
|
||||
FIRFilterSpecification specification = FIRFilterSpecification.lowPassBuilder()
|
||||
.sampleRate(8000)
|
||||
.gridDensity(16)
|
||||
.oddLength(true)
|
||||
.passBandCutoff(300)
|
||||
.passBandAmplitude(1.0)
|
||||
.passBandRipple(0.01)
|
||||
.stopBandStart(500)
|
||||
.stopBandAmplitude(0.0)
|
||||
.stopBandRipple(0.03) //Approximately 60 dB attenuation
|
||||
.build();
|
||||
|
||||
try
|
||||
{
|
||||
RemezFIRFilterDesigner designer = new RemezFIRFilterDesigner(specification);
|
||||
|
||||
if(designer.isValid())
|
||||
{
|
||||
sLowPassFilterCoefficients = designer.getImpulseResponse();
|
||||
}
|
||||
}
|
||||
catch(FilterDesignException fde)
|
||||
{
|
||||
mLog.error("Filter design error", fde);
|
||||
}
|
||||
}
|
||||
|
||||
protected float mSymbolTimingGain = COARSE_TIMING_GAIN;
|
||||
protected SampleBuffer mSampleBuffer;
|
||||
protected ZeroCrossingErrorDetector mTimingErrorDetector = new ZeroCrossingErrorDetector(SAMPLES_PER_SYMBOL);
|
||||
protected SynchronizationMonitor mSynchronizationMonitor;
|
||||
private IIRSinglePoleDCRemovalFilter mDCFilter = new IIRSinglePoleDCRemovalFilter(0.99999f);
|
||||
private RealFIRFilter2 mLowPassFilter = new RealFIRFilter2(sLowPassFilterCoefficients);
|
||||
private Listener<Boolean> mSymbolDecisionListener;
|
||||
|
||||
private boolean mSampleDecision;
|
||||
|
||||
/**
|
||||
* Implements a Logic Trunked Radio sub-audible 300 baud FSK signaling decoder
|
||||
*
|
||||
* @param messageLength in symbols
|
||||
*/
|
||||
public LTRDecoder(int messageLength)
|
||||
{
|
||||
this(messageLength, new SampleBuffer(SAMPLES_PER_SYMBOL, COARSE_TIMING_GAIN),
|
||||
new ZeroCrossingErrorDetector(SAMPLES_PER_SYMBOL));
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements a Logic Trunked Radio sub-audible 300 baud FSK signaling decoder.
|
||||
*
|
||||
* @param messageLength in symbols
|
||||
* @param sampleBuffer to use for storing sample decisions
|
||||
* @param detector for symbol timing errors
|
||||
*/
|
||||
public LTRDecoder(int messageLength, SampleBuffer sampleBuffer, ZeroCrossingErrorDetector detector)
|
||||
{
|
||||
mSynchronizationMonitor = new SynchronizationMonitor(messageLength);
|
||||
mSynchronizationMonitor.setListener(this);
|
||||
mTimingErrorDetector = detector;
|
||||
mSampleBuffer = sampleBuffer;
|
||||
mSampleBuffer.setTimingGain(mSymbolTimingGain);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the ISyncDetectedListener interface to be notified of message sync detection events.
|
||||
*
|
||||
* This allows the internal timing error detector to adjust symbol timing error gain levels according to the
|
||||
* message synchronization state to quickly adjust to initial signal streams or to reduce gain levels once
|
||||
* synchronization has been achieved.
|
||||
*/
|
||||
@Override
|
||||
public void syncDetected()
|
||||
{
|
||||
mSynchronizationMonitor.syncDetected();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
ReusableBuffer dcFiltered = mDCFilter.filter(buffer);
|
||||
ReusableBuffer lowPassFiltered = mLowPassFilter.filter(dcFiltered);
|
||||
|
||||
for(float sample : lowPassFiltered.getSamples())
|
||||
{
|
||||
mSampleDecision = sample > 0.0;
|
||||
|
||||
mSampleBuffer.receive(mSampleDecision);
|
||||
mTimingErrorDetector.receive(mSampleDecision);
|
||||
|
||||
if(mSampleBuffer.hasSymbol())
|
||||
{
|
||||
if(mSymbolDecisionListener != null)
|
||||
{
|
||||
mSymbolDecisionListener.receive(mSampleBuffer.getSymbol());
|
||||
}
|
||||
|
||||
mSampleBuffer.resetAndAdjust(-mTimingErrorDetector.getError());
|
||||
|
||||
mSynchronizationMonitor.increment();
|
||||
}
|
||||
}
|
||||
|
||||
lowPassFiltered.decrementUserCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a listener to receive decoded LTR symbols.
|
||||
*
|
||||
* @param listener to receive symbols.
|
||||
*/
|
||||
public void setListener(Listener<Boolean> listener)
|
||||
{
|
||||
mSymbolDecisionListener = listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the symbol listener from receiving decoded LTR symbols.
|
||||
*/
|
||||
public void removeListener()
|
||||
{
|
||||
mSymbolDecisionListener = null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implements the ISyncStateListener interface to receive synchronization state events and adjust the symbol timing
|
||||
* error gain levels on the internal timing error detector.
|
||||
*
|
||||
* Gain levels are defined relative to a unit gain of 1.0 over a number of symbol periods. LTR uses an initial
|
||||
* ramp-up symbol reversal pattern of 0101 which provides three zero crossing detection opportunities for the timing
|
||||
* error detector, therefore we react to a COARSE gain state to average timing error over 3 symbols.
|
||||
*
|
||||
* @param syncState from an external synchronization state monitor
|
||||
*/
|
||||
@Override
|
||||
public void setSyncState(SyncState syncState)
|
||||
{
|
||||
switch(syncState)
|
||||
{
|
||||
case FINE:
|
||||
mSymbolTimingGain = FINE_TIMING_GAIN;
|
||||
break;
|
||||
case MEDIUM:
|
||||
mSymbolTimingGain = MEDIUM_TIMING_GAIN;
|
||||
break;
|
||||
case COARSE:
|
||||
mSymbolTimingGain = COARSE_TIMING_GAIN;
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Unrecognized sync state level: " + syncState.name());
|
||||
}
|
||||
|
||||
mSampleBuffer.setTimingGain(mSymbolTimingGain);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*******************************************************************************
|
||||
* 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.fsk;
|
||||
|
||||
public class LTRDecoderInstrumented extends LTRDecoder
|
||||
{
|
||||
/**
|
||||
* Instrumented extension to LTRDecoder
|
||||
*
|
||||
* @param messageLength in symbols
|
||||
*/
|
||||
public LTRDecoderInstrumented(int messageLength)
|
||||
{
|
||||
super(messageLength, new SampleBufferInstrumented(SAMPLES_PER_SYMBOL, COARSE_TIMING_GAIN),
|
||||
new ZeroCrossingErrorDetectorInstrumented(SAMPLES_PER_SYMBOL));
|
||||
}
|
||||
|
||||
public SampleBufferInstrumented getSampleBuffer()
|
||||
{
|
||||
return (SampleBufferInstrumented)mSampleBuffer;
|
||||
}
|
||||
|
||||
public ZeroCrossingErrorDetectorInstrumented getErrorDetector()
|
||||
{
|
||||
return (ZeroCrossingErrorDetectorInstrumented)mTimingErrorDetector;
|
||||
}
|
||||
}
|
||||
@@ -40,7 +40,7 @@ import io.github.dsheirer.sample.real.RealBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class LTRFSKDecoder implements Listener<RealBuffer>, Instrumentable
|
||||
public class LTRFSKDecoderLegacy implements Listener<RealBuffer>, Instrumentable
|
||||
{
|
||||
private RealPrimeCICDecimate mCICDecimator;
|
||||
|
||||
@@ -72,7 +72,7 @@ public class LTRFSKDecoder implements Listener<RealBuffer>, Instrumentable
|
||||
* Implements a Logic Trunked Radio sub-audible 300 baud FSK signaling
|
||||
* decoder. Expects a 48000 sample rate input.
|
||||
*/
|
||||
public LTRFSKDecoder()
|
||||
public LTRFSKDecoderLegacy()
|
||||
{
|
||||
mCICDecimator = new RealPrimeCICDecimate( 32, 1, 375, 60, WindowType.HAMMING, 2 );
|
||||
|
||||
124
src/main/java/io/github/dsheirer/dsp/fsk/SampleBuffer.java
Normal file
124
src/main/java/io/github/dsheirer/dsp/fsk/SampleBuffer.java
Normal file
@@ -0,0 +1,124 @@
|
||||
/*******************************************************************************
|
||||
* 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.fsk;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class SampleBuffer
|
||||
{
|
||||
private final static Logger mLog = LoggerFactory.getLogger(SampleBuffer.class);
|
||||
|
||||
protected boolean[] mDelayLine;
|
||||
protected int mDelayLinePointer = 0;
|
||||
|
||||
protected int mTwiceSamplesPerSymbol;
|
||||
private int mIntegerSamplesPerSymbol;
|
||||
private int mHalfIntegerSamplesPerSymbol;
|
||||
private int mPositiveSampleDecisionCount;
|
||||
protected int mSymbolStart;
|
||||
protected int mSymbolEnd;
|
||||
protected float mSamplesPerSymbol;
|
||||
protected float mMidSymbolSamplingPoint;
|
||||
protected float mSymbolTimingGain;
|
||||
|
||||
/**
|
||||
* Buffer to store complex sample data and produce interpolated samples.
|
||||
* @param samplesPerSymbol
|
||||
*/
|
||||
public SampleBuffer(float samplesPerSymbol, float symbolTimingGain)
|
||||
{
|
||||
mSamplesPerSymbol = samplesPerSymbol;
|
||||
mSymbolTimingGain = symbolTimingGain;
|
||||
|
||||
mIntegerSamplesPerSymbol = (int)(samplesPerSymbol + 0.5f);
|
||||
mHalfIntegerSamplesPerSymbol = (int)(samplesPerSymbol / 2.0f + 0.5f);
|
||||
mMidSymbolSamplingPoint = samplesPerSymbol + mHalfIntegerSamplesPerSymbol;
|
||||
mTwiceSamplesPerSymbol = (int)Math.floor(2.0 * 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)
|
||||
{
|
||||
mMidSymbolSamplingPoint--;
|
||||
|
||||
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)
|
||||
{
|
||||
mMidSymbolSamplingPoint += (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 mMidSymbolSamplingPoint < 1.0f;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 0.5 to 1.5
|
||||
* 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;
|
||||
|
||||
//Symbol samples are 0.5 and 1.5 symbols ahead of the current buffer pointer, but 0.5 to 1.5 symbol period
|
||||
//before the most recently stored sample decision.
|
||||
mSymbolStart = mDelayLinePointer + mHalfIntegerSamplesPerSymbol;
|
||||
mSymbolEnd = mSymbolStart + mIntegerSamplesPerSymbol;
|
||||
|
||||
for(int x = mSymbolStart; x < mSymbolEnd; x++)
|
||||
{
|
||||
if(mDelayLine[x])
|
||||
{
|
||||
mPositiveSampleDecisionCount++;
|
||||
}
|
||||
}
|
||||
|
||||
return mPositiveSampleDecisionCount > mHalfIntegerSamplesPerSymbol;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
/*******************************************************************************
|
||||
* 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.fsk;
|
||||
|
||||
public class SampleBufferInstrumented extends SampleBuffer
|
||||
{
|
||||
public boolean mLastSymbol;
|
||||
|
||||
/**
|
||||
* Buffer to store complex sample data and produce interpolated samples.
|
||||
*
|
||||
* @param samplesPerSymbol
|
||||
* @param symbolTimingGain
|
||||
*/
|
||||
public SampleBufferInstrumented(float 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Current mid-symbol sampling point
|
||||
*/
|
||||
public float getMidSymbolSamplingPoint()
|
||||
{
|
||||
return mMidSymbolSamplingPoint;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
21
src/main/java/io/github/dsheirer/dsp/fsk/SyncState.java
Normal file
21
src/main/java/io/github/dsheirer/dsp/fsk/SyncState.java
Normal file
@@ -0,0 +1,21 @@
|
||||
/*******************************************************************************
|
||||
* 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.fsk;
|
||||
|
||||
public enum SyncState
|
||||
{
|
||||
COARSE, MEDIUM, FINE;
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
/*******************************************************************************
|
||||
* 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.fsk;
|
||||
|
||||
import io.github.dsheirer.dsp.symbol.ISyncDetectListener;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Monitors a symbol stream and externally provided sync detection events to track the sync state as the number of
|
||||
* message synchronization events relative the count of symbols that have been decoded to provide synchronization state
|
||||
* events to a registered listener.
|
||||
*
|
||||
* This might be used to provide a control signal to a symbol timing error detector to adjust timing error gain levels.
|
||||
*
|
||||
* This class only works with messages of uniform symbol length.
|
||||
*
|
||||
* Synchronization States:
|
||||
*
|
||||
* -COARSE - default state. demoted from MEDIUM after one message period with no sync detection.
|
||||
*
|
||||
* -MEDIUM - promoted from COARSE when one sync detection occurs after two message periods, or demoted from FINE
|
||||
* after two message periods with no sync detections.
|
||||
*
|
||||
* -FINE - promoted from MEDIUM after two or more consecutive sync detections within the preceding two or more
|
||||
* message periods.
|
||||
*/
|
||||
public class SynchronizationMonitor implements ISyncDetectListener
|
||||
{
|
||||
private final static Logger mLog = LoggerFactory.getLogger(SynchronizationMonitor.class);
|
||||
|
||||
private ISyncStateListener mSyncStateListener;
|
||||
private SyncState mSyncState = SyncState.COARSE;
|
||||
private int mSyncCount;
|
||||
private int mSymbolCount = 0;
|
||||
private int mMessageLength;
|
||||
|
||||
/**
|
||||
* Constructs the synchronization monitor for the specified message symbol length.
|
||||
* @param messageLength in symbols.
|
||||
*/
|
||||
public SynchronizationMonitor(int messageLength)
|
||||
{
|
||||
mMessageLength = messageLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets to the default state of COARSE
|
||||
*/
|
||||
public void reset()
|
||||
{
|
||||
setSyncState(SyncState.COARSE);
|
||||
mSymbolCount = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the sync state and broadcasts any state changes to the registered sync state listener.
|
||||
*/
|
||||
private void setSyncState(SyncState syncState)
|
||||
{
|
||||
if(mSyncState != syncState)
|
||||
{
|
||||
mSyncState = syncState;
|
||||
|
||||
if(mSyncStateListener != null)
|
||||
{
|
||||
mSyncStateListener.setSyncState(mSyncState);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the message synchronization state based on the current number of sync detections.
|
||||
*/
|
||||
private void updateSyncState()
|
||||
{
|
||||
if(mSyncCount < 0)
|
||||
{
|
||||
mSyncCount = 0;
|
||||
|
||||
//The previous state was also zero, so there are no changes
|
||||
return;
|
||||
}
|
||||
|
||||
switch(mSyncCount)
|
||||
{
|
||||
case 0:
|
||||
setSyncState(SyncState.COARSE);
|
||||
break;
|
||||
case 1:
|
||||
setSyncState(SyncState.MEDIUM);
|
||||
break;
|
||||
default:
|
||||
setSyncState(SyncState.FINE);
|
||||
}
|
||||
|
||||
//Max is 3 which means state will drop to MEDIUM after 2 elapsed message periods and COARSE after 3 elapsed
|
||||
// message periods with no sync detection.
|
||||
if(mSyncCount > 3)
|
||||
{
|
||||
mSyncCount = 3;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the ISyncDetectionListener interface to be notified when an external entity detects a message
|
||||
* sync word in the symbol stream.
|
||||
*/
|
||||
@Override
|
||||
public void syncDetected()
|
||||
{
|
||||
mSymbolCount = 0;
|
||||
mSyncCount++;
|
||||
updateSyncState();
|
||||
}
|
||||
|
||||
/**
|
||||
* Increments the symbol count for each decoded symbol.
|
||||
*/
|
||||
public void increment()
|
||||
{
|
||||
mSymbolCount++;
|
||||
|
||||
if(mSymbolCount > mMessageLength)
|
||||
{
|
||||
mSymbolCount = 0;
|
||||
mSyncCount--;
|
||||
updateSyncState();
|
||||
}
|
||||
}
|
||||
|
||||
public void setListener(ISyncStateListener listener)
|
||||
{
|
||||
mSyncStateListener = listener;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
/*******************************************************************************
|
||||
* 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.fsk;
|
||||
|
||||
/**
|
||||
* 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 ZeroCrossingErrorDetector
|
||||
{
|
||||
protected boolean[] mBuffer;
|
||||
protected float mZeroCrossingIdeal;
|
||||
protected float mZeroCrossingOne;
|
||||
protected float mZeroCrossingTwo;
|
||||
protected float mDetectedZeroCrossing;
|
||||
private int mZeroCrossingCount;
|
||||
|
||||
/**
|
||||
* Constructs the detector for the specified samples per symbol.
|
||||
*
|
||||
* @param samplesPerSymbol
|
||||
*/
|
||||
public ZeroCrossingErrorDetector(float samplesPerSymbol)
|
||||
{
|
||||
mBuffer = new boolean[(int)Math.ceil(samplesPerSymbol)];
|
||||
mZeroCrossingIdeal = mBuffer.length - 1.5f - (samplesPerSymbol / 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 float getError()
|
||||
{
|
||||
mZeroCrossingCount = 0;
|
||||
|
||||
for(int x = 0; x < mBuffer.length - 1; x++)
|
||||
{
|
||||
if(mBuffer[x] ^ mBuffer[x + 1])
|
||||
{
|
||||
if(mZeroCrossingCount == 0)
|
||||
{
|
||||
mZeroCrossingCount++;
|
||||
mZeroCrossingOne = x + 0.5f;
|
||||
}
|
||||
else if(mZeroCrossingCount == 1)
|
||||
{
|
||||
mZeroCrossingCount++;
|
||||
mZeroCrossingTwo = x + 0.5f;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Max zero crossings exceeded - no error can be calculated - abort early
|
||||
return 0.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(mZeroCrossingCount == 1)
|
||||
{
|
||||
mDetectedZeroCrossing = mZeroCrossingOne;
|
||||
|
||||
return mZeroCrossingIdeal - mZeroCrossingOne;
|
||||
}
|
||||
else if(mZeroCrossingCount == 2)
|
||||
{
|
||||
float errorDistanceOne = mZeroCrossingIdeal - mZeroCrossingOne;
|
||||
float errorDistanceTwo = mZeroCrossingCount - mZeroCrossingTwo;
|
||||
|
||||
if(Math.abs(errorDistanceOne) < Math.abs(errorDistanceTwo))
|
||||
{
|
||||
mDetectedZeroCrossing = mZeroCrossingOne;
|
||||
}
|
||||
else
|
||||
{
|
||||
mDetectedZeroCrossing = mZeroCrossingTwo;
|
||||
}
|
||||
|
||||
return mZeroCrossingIdeal - mDetectedZeroCrossing;
|
||||
}
|
||||
|
||||
return 0.0f;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*******************************************************************************
|
||||
* 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.fsk;
|
||||
|
||||
import javafx.beans.property.SimpleFloatProperty;
|
||||
|
||||
public class ZeroCrossingErrorDetectorInstrumented extends ZeroCrossingErrorDetector
|
||||
{
|
||||
public SimpleFloatProperty timingError = new SimpleFloatProperty();
|
||||
|
||||
/**
|
||||
* Constructs the detector for the specified samples per symbol.
|
||||
*
|
||||
* @param samplesPerSymbol
|
||||
*/
|
||||
public ZeroCrossingErrorDetectorInstrumented(float samplesPerSymbol)
|
||||
{
|
||||
super(samplesPerSymbol);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getError()
|
||||
{
|
||||
float error = super.getError();
|
||||
|
||||
timingError.setValue(error);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
public float getZeroCrossingIdeal()
|
||||
{
|
||||
return mZeroCrossingIdeal;
|
||||
}
|
||||
|
||||
public float getDetectedZeroCrossing()
|
||||
{
|
||||
return mDetectedZeroCrossing;
|
||||
}
|
||||
|
||||
public boolean[] getBuffer()
|
||||
{
|
||||
return mBuffer;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user