mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-13 00:57:31 -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:
@@ -1,55 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* SDR Trunk
|
||||
* Copyright (C) 2014 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.filter;
|
||||
|
||||
import io.github.dsheirer.sample.Listener;
|
||||
import io.github.dsheirer.sample.complex.Complex;
|
||||
|
||||
@Deprecated
|
||||
public abstract class ComplexFilter implements Listener<Complex>
|
||||
{
|
||||
private Listener<Complex> mListener;
|
||||
|
||||
public void setListener( Listener<Complex> listener )
|
||||
{
|
||||
mListener = listener;
|
||||
}
|
||||
|
||||
public void dispose()
|
||||
{
|
||||
mListener = null;
|
||||
}
|
||||
|
||||
public Listener<Complex> getListener()
|
||||
{
|
||||
return mListener;
|
||||
}
|
||||
|
||||
public boolean hasListener()
|
||||
{
|
||||
return mListener != null;
|
||||
}
|
||||
|
||||
protected void send( Complex sample )
|
||||
{
|
||||
if( mListener != null )
|
||||
{
|
||||
mListener.receive( sample );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@ import io.github.dsheirer.dsp.filter.channelizer.output.TwoChannelOutputProcesso
|
||||
import io.github.dsheirer.dsp.filter.design.FilterDesignException;
|
||||
import io.github.dsheirer.sample.Broadcaster;
|
||||
import io.github.dsheirer.sample.Listener;
|
||||
import io.github.dsheirer.sample.buffer.IReusableBufferProvider;
|
||||
import io.github.dsheirer.sample.buffer.IReusableComplexBufferProvider;
|
||||
import io.github.dsheirer.sample.buffer.ReusableComplexBuffer;
|
||||
import io.github.dsheirer.source.ISourceEventProcessor;
|
||||
import io.github.dsheirer.source.Source;
|
||||
@@ -69,7 +69,7 @@ public class PolyphaseChannelManager implements ISourceEventProcessor
|
||||
private static final int POLYPHASE_SYNTHESIZER_TAPS_PER_CHANNEL = 9;
|
||||
|
||||
private Broadcaster<SourceEvent> mSourceEventBroadcaster = new Broadcaster<>();
|
||||
private IReusableBufferProvider<ReusableComplexBuffer> mReusableBufferProvider;
|
||||
private IReusableComplexBufferProvider mReusableBufferProvider;
|
||||
private List<PolyphaseChannelSource> mChannelSources = new CopyOnWriteArrayList<>();
|
||||
private ChannelCalculator mChannelCalculator;
|
||||
private ComplexPolyphaseChannelizerM2 mPolyphaseChannelizer;
|
||||
@@ -81,20 +81,20 @@ public class PolyphaseChannelManager implements ISourceEventProcessor
|
||||
/**
|
||||
* Creates a polyphase channel manager instance.
|
||||
*
|
||||
* @param reusableBufferProvider (ie tuner) that supports register/deregister for reusable baseband sample buffer
|
||||
* @param reusableComplexBufferProvider (ie tuner) that supports register/deregister for reusable baseband sample buffer
|
||||
* streams
|
||||
* @param frequency of the baseband complex buffer sample stream (ie center frequency)
|
||||
* @param sampleRate of the baseband complex buffer sample stream
|
||||
*/
|
||||
public PolyphaseChannelManager(IReusableBufferProvider<ReusableComplexBuffer> reusableBufferProvider,
|
||||
public PolyphaseChannelManager(IReusableComplexBufferProvider reusableComplexBufferProvider,
|
||||
long frequency, double sampleRate)
|
||||
{
|
||||
if(reusableBufferProvider == null)
|
||||
if(reusableComplexBufferProvider == null)
|
||||
{
|
||||
throw new IllegalArgumentException("Complex buffer provider argument cannot be null");
|
||||
}
|
||||
|
||||
mReusableBufferProvider = reusableBufferProvider;
|
||||
mReusableBufferProvider = reusableComplexBufferProvider;
|
||||
|
||||
int channelCount = (int)(sampleRate / MINIMUM_CHANNEL_BANDWIDTH);
|
||||
|
||||
|
||||
@@ -15,26 +15,23 @@
|
||||
******************************************************************************/
|
||||
package io.github.dsheirer.dsp.filter.dc;
|
||||
|
||||
import io.github.dsheirer.sample.buffer.ReusableBuffer;
|
||||
import io.github.dsheirer.sample.buffer.ReusableBufferQueue;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class BufferDCFilter
|
||||
{
|
||||
private final static Logger mLog = LoggerFactory.getLogger(BufferDCFilter.class);
|
||||
private ReusableBufferQueue mReusableBufferQueue = new ReusableBufferQueue("Buffer DC Filter");
|
||||
private double mAccumulator;
|
||||
|
||||
/**
|
||||
* Calculates the DC offset present in the samples and subtracts the offset from all samples.
|
||||
*/
|
||||
public static void filterReal(float[] samples)
|
||||
public void filterReal(float[] samples)
|
||||
{
|
||||
double accumulator = 0.0;
|
||||
|
||||
for(int x = 0; x < samples.length; x++)
|
||||
{
|
||||
accumulator += samples[x];
|
||||
}
|
||||
|
||||
float adjustment = (float)(accumulator / (double)samples.length);
|
||||
float adjustment = getOffset(samples);
|
||||
|
||||
for(int x = 0; x < samples.length; x++)
|
||||
{
|
||||
@@ -42,6 +39,18 @@ public class BufferDCFilter
|
||||
}
|
||||
}
|
||||
|
||||
private float getOffset(float[] samples)
|
||||
{
|
||||
mAccumulator = 0.0;
|
||||
|
||||
for(int x = 0; x < samples.length; x++)
|
||||
{
|
||||
mAccumulator += samples[x];
|
||||
}
|
||||
|
||||
return (float)(mAccumulator / (double)samples.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the DC offset present in the samples and subtracts the offset from all samples.
|
||||
*/
|
||||
@@ -67,4 +76,24 @@ public class BufferDCFilter
|
||||
samples[x + 1] = samples[x + 1] - qAdjustment;
|
||||
}
|
||||
}
|
||||
|
||||
public ReusableBuffer filter(ReusableBuffer unfilteredBuffer)
|
||||
{
|
||||
float[] unfilteredSamples = unfilteredBuffer.getSamples();
|
||||
|
||||
ReusableBuffer filteredBuffer = mReusableBufferQueue.getBuffer(unfilteredSamples.length);
|
||||
float[] filteredSamples = filteredBuffer.getSamples();
|
||||
|
||||
float offset = getOffset(unfilteredSamples);
|
||||
|
||||
for(int x = 0; x < unfilteredSamples.length; x++)
|
||||
{
|
||||
filteredSamples[x] = unfilteredSamples[x] - offset;
|
||||
}
|
||||
|
||||
unfilteredBuffer.decrementUserCount();
|
||||
filteredBuffer.incrementUserCount();
|
||||
|
||||
return filteredBuffer;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,41 +1,87 @@
|
||||
/*******************************************************************************
|
||||
* SDR Trunk
|
||||
* Copyright (C) 2014,2015 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/>
|
||||
* 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.filter.dc;
|
||||
|
||||
import io.github.dsheirer.sample.buffer.ReusableBuffer;
|
||||
import io.github.dsheirer.sample.buffer.ReusableBufferQueue;
|
||||
|
||||
/**
|
||||
* DC removal filter for removing any DC offset that may be present when a signal is not aligned within the
|
||||
* demodulated channel.
|
||||
*/
|
||||
public class DCRemovalFilter
|
||||
{
|
||||
protected float mAverage;
|
||||
protected float mRatio;
|
||||
private ReusableBufferQueue mReusableBufferQueue = new ReusableBufferQueue("DC Removal Filter");
|
||||
protected float mAverage;
|
||||
protected float mRatio;
|
||||
|
||||
public DCRemovalFilter( float ratio )
|
||||
{
|
||||
mRatio = ratio;
|
||||
}
|
||||
/**
|
||||
* Creates a DC removal filter.
|
||||
*
|
||||
* @param ratio
|
||||
*/
|
||||
public DCRemovalFilter(float ratio)
|
||||
{
|
||||
mRatio = ratio;
|
||||
}
|
||||
|
||||
public void reset()
|
||||
{
|
||||
mAverage = 0.0f;
|
||||
}
|
||||
/**
|
||||
* Resets the running average to zero.
|
||||
*/
|
||||
public void reset()
|
||||
{
|
||||
mAverage = 0.0f;
|
||||
}
|
||||
|
||||
public float filter( float sample )
|
||||
{
|
||||
float filtered = sample - mAverage;
|
||||
mAverage += mRatio * filtered;
|
||||
return filtered;
|
||||
}
|
||||
/**
|
||||
* Filters the sample and returns a filtered (ie DC-removed) sample.
|
||||
* @param sample to filter
|
||||
* @return filtered sample
|
||||
*/
|
||||
public float filter(float sample)
|
||||
{
|
||||
float filtered = sample - mAverage;
|
||||
mAverage += mRatio * filtered;
|
||||
return filtered;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the buffer samples and returns a new reusable buffer with the filtered samples.
|
||||
*
|
||||
* Note: this method automatically manages the user accounting between the buffer argument and the new returned
|
||||
* filtered sample buffer.
|
||||
*
|
||||
* @param unfilteredBuffer containing samples to filter
|
||||
* @return a new reusable buffer containing the filtered samples with the user count set to 1.
|
||||
*/
|
||||
public ReusableBuffer filter(ReusableBuffer unfilteredBuffer)
|
||||
{
|
||||
ReusableBuffer filteredBuffer = mReusableBufferQueue.getBuffer(unfilteredBuffer.getSampleCount());
|
||||
|
||||
float[] unfilteredSamples = unfilteredBuffer.getSamples();
|
||||
float[] filteredSamples = filteredBuffer.getSamples();
|
||||
|
||||
for(int x = 0; x < unfilteredSamples.length; x++)
|
||||
{
|
||||
filteredSamples[x] = filter(unfilteredSamples[x]);
|
||||
}
|
||||
|
||||
unfilteredBuffer.decrementUserCount();
|
||||
filteredBuffer.incrementUserCount();
|
||||
|
||||
return filteredBuffer;
|
||||
}
|
||||
}
|
||||
@@ -1,45 +1,106 @@
|
||||
/*******************************************************************************
|
||||
* 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.filter.dc;
|
||||
|
||||
import io.github.dsheirer.sample.buffer.ReusableBuffer;
|
||||
import io.github.dsheirer.sample.buffer.ReusableBufferQueue;
|
||||
import io.github.dsheirer.sample.real.RealSampleListener;
|
||||
|
||||
public class IIRSinglePoleDCRemovalFilter implements RealSampleListener
|
||||
{
|
||||
private float mAlpha;
|
||||
private float mPreviousInput = 0.0f;
|
||||
private float mPreviousOutput = 0.0f;
|
||||
private ReusableBufferQueue mReusableBufferQueue = new ReusableBufferQueue("IIR DC Filter");
|
||||
private float mAlpha;
|
||||
private float mPreviousInput = 0.0f;
|
||||
private float mPreviousOutput = 0.0f;
|
||||
private float mCurrentOutput = 0.0f;
|
||||
|
||||
private RealSampleListener mListener;
|
||||
|
||||
/**
|
||||
* IIR single-pole DC removal filter, as described by J M de Freitas in
|
||||
* 29Jan2007 paper at:
|
||||
*
|
||||
* http://www.mathworks.com/matlabcentral/fileexchange/downloads/72134/download
|
||||
*
|
||||
* @param alpha 0.0 - 1.0 float - the closer alpha is to unity, the closer
|
||||
* the cutoff frequency is to DC.
|
||||
*/
|
||||
public IIRSinglePoleDCRemovalFilter( float alpha )
|
||||
{
|
||||
mAlpha = alpha;
|
||||
}
|
||||
@Override
|
||||
public void receive( float currentInput )
|
||||
private RealSampleListener mListener;
|
||||
|
||||
/**
|
||||
* IIR single-pole DC removal filter, as described by J M de Freitas in
|
||||
* 29Jan2007 paper at:
|
||||
*
|
||||
* http://www.mathworks.com/matlabcentral/fileexchange/downloads/72134/download
|
||||
*
|
||||
* @param alpha 0.0 - 1.0 float - the closer alpha is to unity, the closer
|
||||
* the cutoff frequency is to DC.
|
||||
*/
|
||||
public IIRSinglePoleDCRemovalFilter(float alpha)
|
||||
{
|
||||
float currentOutput = ( currentInput - mPreviousInput ) +
|
||||
( mAlpha * mPreviousOutput );
|
||||
|
||||
if( mListener != null )
|
||||
{
|
||||
mListener.receive( currentOutput );
|
||||
}
|
||||
|
||||
mPreviousInput = currentInput;
|
||||
mPreviousOutput = currentOutput;
|
||||
mAlpha = alpha;
|
||||
}
|
||||
|
||||
public void setListener( RealSampleListener listener )
|
||||
{
|
||||
mListener = listener;
|
||||
}
|
||||
/**
|
||||
* Filters the sample
|
||||
* @param sample to filter
|
||||
* @return filtered output sample
|
||||
*/
|
||||
public float filter(float sample)
|
||||
{
|
||||
mCurrentOutput = (sample - mPreviousInput) + (mAlpha * mPreviousOutput);
|
||||
|
||||
mPreviousInput = sample;
|
||||
mPreviousOutput = mCurrentOutput;
|
||||
|
||||
return mCurrentOutput;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the input buffer and returns a new filtered output buffer.
|
||||
*
|
||||
* Buffer user accounting is handled by this method where the input buffer user count is decremented and the
|
||||
* returned output buffer has the user count incremented to one.
|
||||
*
|
||||
* @param inputBuffer to filter
|
||||
* @return filtered samples in a new (ie reused) output buffer
|
||||
*/
|
||||
public ReusableBuffer filter(ReusableBuffer inputBuffer)
|
||||
{
|
||||
ReusableBuffer outputBuffer = mReusableBufferQueue.getBuffer(inputBuffer.getSampleCount());
|
||||
float[] inputSamples = inputBuffer.getSamples();
|
||||
float[] outputSamples = outputBuffer.getSamples();
|
||||
|
||||
for(int x = 0; x < inputSamples.length; x++)
|
||||
{
|
||||
outputSamples[x] = filter(inputSamples[x]);
|
||||
}
|
||||
|
||||
inputBuffer.decrementUserCount();
|
||||
outputBuffer.incrementUserCount();
|
||||
|
||||
return outputBuffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the RealSampleListener interface for single sample streams.
|
||||
*/
|
||||
@Override
|
||||
public void receive(float sample)
|
||||
{
|
||||
if(mListener != null)
|
||||
{
|
||||
mListener.receive(filter(sample));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns the listener to receive filtered samples processed by the RealSampleListener interface
|
||||
*/
|
||||
public void setListener(RealSampleListener listener)
|
||||
{
|
||||
mListener = listener;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,69 +0,0 @@
|
||||
package io.github.dsheirer.dsp.filter.dc;
|
||||
|
||||
import io.github.dsheirer.sample.Listener;
|
||||
import io.github.dsheirer.sample.real.RealBuffer;
|
||||
|
||||
public class IIRSinglePoleDCRemovalFilter_RB implements Listener<RealBuffer>
|
||||
{
|
||||
private float mAlpha;
|
||||
private float mPreviousInput = 0.0f;
|
||||
private float mPreviousOutput = 0.0f;
|
||||
private Listener<RealBuffer> mListener;
|
||||
|
||||
/**
|
||||
* IIR single-pole DC removal filter, as described by J M de Freitas in
|
||||
* 29Jan2007 paper at:
|
||||
*
|
||||
* http://www.mathworks.com/matlabcentral/fileexchange/downloads/72134/download
|
||||
*
|
||||
* @param alpha 0.0 - 1.0 float - the closer alpha is to unity, the closer
|
||||
* the cutoff frequency is to DC.
|
||||
*/
|
||||
public IIRSinglePoleDCRemovalFilter_RB( float alpha )
|
||||
{
|
||||
mAlpha = alpha;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receive( RealBuffer buffer )
|
||||
{
|
||||
if( mListener != null )
|
||||
{
|
||||
mListener.receive( filter( buffer ) );
|
||||
}
|
||||
}
|
||||
|
||||
public RealBuffer filter( RealBuffer buffer )
|
||||
{
|
||||
float[] samples = buffer.getSamples();
|
||||
|
||||
for( int x = 0; x < samples.length; x++ )
|
||||
{
|
||||
samples[ x ] = filter( samples[ x ] );
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public float filter( float sample )
|
||||
{
|
||||
float currentOutput = ( sample - mPreviousInput ) +
|
||||
( mAlpha * mPreviousOutput );
|
||||
|
||||
mPreviousInput = sample;
|
||||
mPreviousOutput = currentOutput;
|
||||
|
||||
return currentOutput;
|
||||
}
|
||||
|
||||
public void reset()
|
||||
{
|
||||
mPreviousInput = 0.0f;
|
||||
mPreviousOutput = 0.0f;
|
||||
}
|
||||
|
||||
public void setListener( Listener<RealBuffer> listener )
|
||||
{
|
||||
mListener = listener;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package io.github.dsheirer.dsp.filter.design;
|
||||
|
||||
import io.github.dsheirer.dsp.filter.FilterFactory;
|
||||
import io.github.dsheirer.dsp.filter.fir.FIRFilterSpecification;
|
||||
import io.github.dsheirer.dsp.filter.fir.remez.RemezFIRFilterDesigner;
|
||||
import javafx.application.Application;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.stage.Stage;
|
||||
@@ -39,64 +39,68 @@ public class FilterViewer extends Application
|
||||
*/
|
||||
private float[] getFilter()
|
||||
{
|
||||
FIRFilterSpecification specification = FIRFilterSpecification.lowPassBuilder()
|
||||
.sampleRate(25000)
|
||||
.gridDensity(16)
|
||||
.oddLength(true)
|
||||
.passBandCutoff(6000)
|
||||
// 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();
|
||||
//
|
||||
FIRFilterSpecification specification = FIRFilterSpecification.highPassBuilder()
|
||||
.sampleRate(8000)
|
||||
.stopBandCutoff(200)
|
||||
.stopBandAmplitude(0.0)
|
||||
.stopBandRipple(0.025)
|
||||
.passBandStart(300)
|
||||
.passBandAmplitude(1.0)
|
||||
.passBandRipple(0.01)
|
||||
.stopBandStart(6500)
|
||||
.stopBandAmplitude(0.0)
|
||||
.stopBandRipple(0.005) //Approximately 94 dB attenuation
|
||||
.build();
|
||||
|
||||
// FIRFilterSpecification specification = FIRFilterSpecification.highPassBuilder()
|
||||
// .sampleRate(24000)
|
||||
// .stopBandCutoff(800)
|
||||
// .stopBandAmplitude(0.0)
|
||||
// .stopBandRipple(0.03)
|
||||
// .passBandStart(1000)
|
||||
// .passBandAmplitude(1.0)
|
||||
// .passBandRipple(0.08)
|
||||
// FIRFilterSpecification specification = FIRFilterSpecification.bandPassBuilder()
|
||||
// .sampleRate(8000)
|
||||
// .stopFrequency1(200)
|
||||
// .passFrequencyBegin(300)
|
||||
// .passFrequencyEnd(3800)
|
||||
// .stopFrequency2(3900)
|
||||
// .stopRipple(0.01)
|
||||
// .passRipple(0.01)
|
||||
// .build();
|
||||
|
||||
// FIRFilterSpecification specification = FIRFilterSpecification.bandPassBuilder()
|
||||
// .sampleRate( 48000 )
|
||||
// .stopFrequency1( 200 )
|
||||
// .passFrequencyBegin( 400 )
|
||||
// .passFrequencyEnd( 3200 )
|
||||
// .stopFrequency2( 3400 )
|
||||
// .stopRipple( 0.0003 )
|
||||
// .passRipple( 0.008)
|
||||
// .build();
|
||||
|
||||
float[] taps = null;
|
||||
|
||||
try
|
||||
{
|
||||
taps = FilterFactory.getSincM2Synthesizer(12500.0, 2, 19);
|
||||
// taps = FilterFactory.getSincFilter(25000.0, 12500.0, 2, 19, Window.WindowType.BLACKMAN_HARRIS_7, true);
|
||||
}
|
||||
catch(FilterDesignException fde)
|
||||
{
|
||||
mLog.error("Error");
|
||||
}
|
||||
|
||||
// try
|
||||
// {
|
||||
// RemezFIRFilterDesigner designer = new RemezFIRFilterDesigner(specification);
|
||||
//
|
||||
// if(designer.isValid())
|
||||
// {
|
||||
// taps = designer.getImpulseResponse();
|
||||
// }
|
||||
// taps = FilterFactory.getSincM2Synthesizer(12500.0, 2, 19);
|
||||
// taps = FilterFactory.getSincFilter(25000.0, 12500.0, 2, 19, Window.WindowType.BLACKMAN_HARRIS_7, true);
|
||||
// }
|
||||
// catch(FilterDesignException fde)
|
||||
// {
|
||||
// mLog.error("Filter design error", fde);
|
||||
// mLog.error("Error");
|
||||
// }
|
||||
|
||||
try
|
||||
{
|
||||
RemezFIRFilterDesigner designer = new RemezFIRFilterDesigner(specification);
|
||||
|
||||
if(designer.isValid())
|
||||
{
|
||||
taps = designer.getImpulseResponse();
|
||||
}
|
||||
}
|
||||
catch(FilterDesignException fde)
|
||||
{
|
||||
mLog.error("Filter design error", fde);
|
||||
}
|
||||
|
||||
if(taps == null)
|
||||
{
|
||||
throw new IllegalStateException("Couldn't design filter");
|
||||
}
|
||||
|
||||
|
||||
return taps;
|
||||
|
||||
@@ -27,7 +27,7 @@ import io.github.dsheirer.sample.buffer.ReusableBufferQueue;
|
||||
*/
|
||||
public class RealFIRFilter2 extends FIRFilter
|
||||
{
|
||||
private ReusableBufferQueue mReusableBufferQueue = new ReusableBufferQueue();
|
||||
private ReusableBufferQueue mReusableBufferQueue = new ReusableBufferQueue("RealFIRFilter2");
|
||||
|
||||
private float[] mData;
|
||||
private float[] mCoefficients;
|
||||
|
||||
@@ -20,21 +20,20 @@ import com.laszlosystems.libresample4j.SampleBuffers;
|
||||
import io.github.dsheirer.sample.Listener;
|
||||
import io.github.dsheirer.sample.buffer.ReusableBuffer;
|
||||
import io.github.dsheirer.sample.buffer.ReusableBufferQueue;
|
||||
import io.github.dsheirer.sample.real.RealBuffer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
public class RealResampler implements Listener<RealBuffer>
|
||||
public class RealResampler
|
||||
{
|
||||
protected static final Logger mLog = LoggerFactory.getLogger(RealResampler.class);
|
||||
|
||||
private ReusableBufferQueue mReusableBufferQueue = new ReusableBufferQueue("RealResampler");
|
||||
private Resampler mResampler;
|
||||
private Listener<ReusableBuffer> mResampledListener;
|
||||
private BufferManager mBufferManager = new BufferManager();
|
||||
private ReusableBufferQueue mReusableBufferQueue = new ReusableBufferQueue("RealResampler");
|
||||
private double mResampleFactor;
|
||||
|
||||
/**
|
||||
@@ -50,12 +49,11 @@ public class RealResampler implements Listener<RealBuffer>
|
||||
|
||||
/**
|
||||
* Primary input method to the resampler
|
||||
* @param realBuffer to resample
|
||||
* @param reusableBuffer to resample
|
||||
*/
|
||||
@Override
|
||||
public void receive(RealBuffer realBuffer)
|
||||
public void resample(ReusableBuffer reusableBuffer)
|
||||
{
|
||||
mBufferManager.load(realBuffer);
|
||||
mBufferManager.load(reusableBuffer);
|
||||
mResampler.process(mResampleFactor, mBufferManager, false);
|
||||
}
|
||||
|
||||
@@ -74,25 +72,10 @@ public class RealResampler implements Listener<RealBuffer>
|
||||
*/
|
||||
public class BufferManager implements SampleBuffers
|
||||
{
|
||||
private int mBufferLength = 1000;
|
||||
private int mBufferLength = 8000;
|
||||
private FloatBuffer mInputBuffer = ByteBuffer.allocate(mBufferLength).asFloatBuffer();
|
||||
private FloatBuffer mOutputBuffer = ByteBuffer.allocate(mBufferLength).asFloatBuffer();
|
||||
|
||||
public void resize(int bufferLength)
|
||||
{
|
||||
int floatBufferLength = bufferLength * 4;
|
||||
|
||||
FloatBuffer inputBuffer = ByteBuffer.allocate(floatBufferLength).asFloatBuffer();
|
||||
inputBuffer.put(mInputBuffer);
|
||||
mInputBuffer = inputBuffer;
|
||||
|
||||
FloatBuffer outputBuffer = ByteBuffer.allocate(floatBufferLength).asFloatBuffer();
|
||||
outputBuffer.put(mOutputBuffer);
|
||||
mOutputBuffer = outputBuffer;
|
||||
|
||||
mBufferLength = bufferLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* Current length of the input and output buffers
|
||||
*/
|
||||
@@ -104,16 +87,10 @@ public class RealResampler implements Listener<RealBuffer>
|
||||
/**
|
||||
* Queues the buffer sample for resampling
|
||||
*/
|
||||
public void load(RealBuffer realBuffer)
|
||||
public void load(ReusableBuffer reusableBuffer)
|
||||
{
|
||||
int remaining = mInputBuffer.remaining();
|
||||
|
||||
if(mInputBuffer.remaining() < realBuffer.getSamples().length)
|
||||
{
|
||||
resize(mInputBuffer.capacity() + (realBuffer.getSamples().length - mInputBuffer.remaining()));
|
||||
}
|
||||
|
||||
mInputBuffer.put(realBuffer.getSamples());
|
||||
mInputBuffer.put(reusableBuffer.getSamples());
|
||||
reusableBuffer.decrementUserCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -147,9 +124,10 @@ public class RealResampler implements Listener<RealBuffer>
|
||||
{
|
||||
mOutputBuffer.put(samples, offset, length);
|
||||
|
||||
while(mOutputBuffer.position() > 200)
|
||||
while(mOutputBuffer.position() > 1000)
|
||||
{
|
||||
ReusableBuffer outputBuffer = mReusableBufferQueue.getBuffer(200);
|
||||
ReusableBuffer outputBuffer = mReusableBufferQueue.getBuffer(1000);
|
||||
outputBuffer.incrementUserCount();
|
||||
|
||||
mOutputBuffer.flip();
|
||||
mOutputBuffer.get(outputBuffer.getSamples());
|
||||
@@ -157,9 +135,12 @@ public class RealResampler implements Listener<RealBuffer>
|
||||
|
||||
if(mResampledListener != null)
|
||||
{
|
||||
outputBuffer.incrementUserCount();
|
||||
mResampledListener.receive(outputBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
outputBuffer.decrementUserCount();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,19 +17,47 @@
|
||||
******************************************************************************/
|
||||
package io.github.dsheirer.dsp.fm;
|
||||
|
||||
import io.github.dsheirer.sample.buffer.ReusableBuffer;
|
||||
import io.github.dsheirer.sample.buffer.ReusableBufferQueue;
|
||||
import io.github.dsheirer.sample.buffer.ReusableComplexBuffer;
|
||||
import io.github.dsheirer.sample.complex.Complex;
|
||||
|
||||
public abstract class FMDemodulator
|
||||
/**
|
||||
* FM Demodulator for demodulating complex samples and producing demodulated floating point samples.
|
||||
*/
|
||||
public class FMDemodulator
|
||||
{
|
||||
private ReusableBufferQueue mReusableBufferQueue = new ReusableBufferQueue("FMDemodulator");
|
||||
private float mPreviousI = 0.0f;
|
||||
private float mPreviousQ = 0.0f;
|
||||
protected float mGain;
|
||||
|
||||
/**
|
||||
* Creates an FM demodulator instance with a default gain of 1.0.
|
||||
*/
|
||||
public FMDemodulator()
|
||||
{
|
||||
this(1.0f);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an FM demodulator instance and applies the gain value to each demodulated output sample.
|
||||
* @param gain to apply to demodulated samples.
|
||||
*/
|
||||
public FMDemodulator(float gain)
|
||||
{
|
||||
mGain = gain;
|
||||
}
|
||||
|
||||
/**
|
||||
* Demodulates the I/Q sample via complex sample multiplication by the complex conjugates of the most recently
|
||||
* demodulated complex sample (ie previous sample). Each new sample overwrites the previously stored sample to
|
||||
* allow future invocations of the method to simply use a new sample value.
|
||||
*
|
||||
* @param currentI of the sample
|
||||
* @param currentQ of the sample
|
||||
* @return demodulated sample
|
||||
*/
|
||||
public float demodulate(float currentI, float currentQ)
|
||||
{
|
||||
/**
|
||||
@@ -65,6 +93,12 @@ public abstract class FMDemodulator
|
||||
return (float)(angle * mGain);
|
||||
}
|
||||
|
||||
/**
|
||||
* Demodulates the complex samples and returns the demodulated value.
|
||||
* @param previous
|
||||
* @param current
|
||||
* @return
|
||||
*/
|
||||
public static double demodulate(Complex previous, Complex current)
|
||||
{
|
||||
double inphase = (current.inphase() * previous.inphase()) - (current.quadrature() * -previous.quadrature());
|
||||
@@ -88,14 +122,48 @@ public abstract class FMDemodulator
|
||||
return angle;
|
||||
}
|
||||
|
||||
public abstract void dispose();
|
||||
/**
|
||||
* Demodulates the complex baseband sample buffer and returns a demodulated reusable buffer with the user count
|
||||
* set to 1. The complex baseband buffer's user count is decremented after demodulation.
|
||||
*
|
||||
* @param basebandSampleBuffer containing samples to demodulate
|
||||
* @return demodulated sample buffer.
|
||||
*/
|
||||
public ReusableBuffer demodulate(ReusableComplexBuffer basebandSampleBuffer)
|
||||
{
|
||||
ReusableBuffer demodulatedBuffer = mReusableBufferQueue.getBuffer(basebandSampleBuffer.getSampleCount());
|
||||
|
||||
float[] basebandSamples = basebandSampleBuffer.getSamples();
|
||||
float[] demodulatedSamples = demodulatedBuffer.getSamples();
|
||||
|
||||
for(int x = 0; x < basebandSamples.length; x += 2)
|
||||
{
|
||||
demodulatedSamples[x / 2] = demodulate(basebandSamples[x], basebandSamples[x + 1]);
|
||||
}
|
||||
|
||||
basebandSampleBuffer.decrementUserCount();
|
||||
demodulatedBuffer.incrementUserCount();
|
||||
|
||||
return demodulatedBuffer;
|
||||
}
|
||||
|
||||
public void dispose()
|
||||
{
|
||||
//no-op
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets this demodulator by zeroing the stored previous sample.
|
||||
*/
|
||||
public void reset()
|
||||
{
|
||||
mPreviousI = 0.0f;
|
||||
mPreviousQ = 0.0f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the gain to the specified level.
|
||||
*/
|
||||
public void setGain(float gain)
|
||||
{
|
||||
mGain = gain;
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* SDR Trunk
|
||||
* Copyright (C) 2014,2015 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.fm;
|
||||
|
||||
import io.github.dsheirer.sample.Listener;
|
||||
import io.github.dsheirer.sample.complex.ComplexBuffer;
|
||||
import io.github.dsheirer.sample.real.RateCounter_RB;
|
||||
import io.github.dsheirer.sample.real.RealBuffer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class FMDemodulator_CB extends FMDemodulator implements Listener<ComplexBuffer>
|
||||
{
|
||||
private final static Logger mLog = LoggerFactory.getLogger( FMDemodulator_CB.class );
|
||||
|
||||
private Listener<RealBuffer> mListener;
|
||||
|
||||
private RateCounter_RB mRateCounter = new RateCounter_RB( "FM DEMOD OUTPUT" );
|
||||
|
||||
public FMDemodulator_CB( float gain )
|
||||
{
|
||||
super( gain );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receive( ComplexBuffer buffer )
|
||||
{
|
||||
if( mListener != null )
|
||||
{
|
||||
float[] samples = buffer.getSamples();
|
||||
|
||||
int half = samples.length / 2;
|
||||
|
||||
float[] demodulated = new float[ half ];
|
||||
|
||||
for( int x = 0; x < half; x++ )
|
||||
{
|
||||
int index = x * 2;
|
||||
|
||||
demodulated[ x ] = demodulate( samples[ index ],
|
||||
samples[ index + 1 ] );
|
||||
}
|
||||
|
||||
mListener.receive( new RealBuffer( demodulated ) );
|
||||
}
|
||||
}
|
||||
|
||||
public void setListener( Listener<RealBuffer> listener )
|
||||
{
|
||||
mListener = listener;
|
||||
}
|
||||
|
||||
public void removeListener()
|
||||
{
|
||||
mListener = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose()
|
||||
{
|
||||
mListener = null;
|
||||
}
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* SDR Trunk
|
||||
* Copyright (C) 2014,2015 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.fm;
|
||||
|
||||
import io.github.dsheirer.sample.Listener;
|
||||
import io.github.dsheirer.sample.complex.Complex;
|
||||
import io.github.dsheirer.sample.real.RealSampleListener;
|
||||
|
||||
@Deprecated
|
||||
public class FMDiscriminator implements Listener<Complex>
|
||||
{
|
||||
private RealSampleListener mListener;
|
||||
private Complex mPreviousSample = new Complex( 0.0f, 0.0f );
|
||||
private double mGain;
|
||||
|
||||
/**
|
||||
* Implements a polar discriminator with ArcTangent angle estimator to
|
||||
* demodulate complex sampled frequency modulated signals.
|
||||
*
|
||||
* @param gain - gain to be applied to the demodulated output - can be
|
||||
* dynamically applied to continuously adjust audio output
|
||||
*/
|
||||
public FMDiscriminator( double gain )
|
||||
{
|
||||
mGain = gain;
|
||||
}
|
||||
|
||||
public void dispose()
|
||||
{
|
||||
mListener = null;
|
||||
mPreviousSample = null;
|
||||
}
|
||||
|
||||
public synchronized void setGain( double gain )
|
||||
{
|
||||
mGain = gain;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receive( Complex currentSample )
|
||||
{
|
||||
/**
|
||||
* Multiply the current sample against the complex conjugate of the
|
||||
* previous sample to derive the phase delta between the two samples
|
||||
*
|
||||
* Negating the previous sample quadrature produces the conjugate
|
||||
*/
|
||||
double i = ( currentSample.inphase() * mPreviousSample.inphase() ) -
|
||||
( currentSample.quadrature() * -mPreviousSample.quadrature() );
|
||||
double q = ( currentSample.quadrature() * mPreviousSample.inphase() ) +
|
||||
( currentSample.inphase() * -mPreviousSample.quadrature() );
|
||||
|
||||
double angle;
|
||||
|
||||
//Check for divide by zero
|
||||
if( i == 0 )
|
||||
{
|
||||
angle = 0.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
/**
|
||||
* Use the arc-tangent of imaginary (q) divided by real (i) to
|
||||
* get the phase angle (+/-) which was directly manipulated by the
|
||||
* original message waveform during the modulation. This value now
|
||||
* serves as the instantaneous amplitude of the demodulated signal
|
||||
*/
|
||||
double denominator = 1.0d / i;
|
||||
angle = Math.atan( (double)q * denominator );
|
||||
}
|
||||
|
||||
if( mListener != null )
|
||||
{
|
||||
mListener.receive( (float)( angle * mGain ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the current sample to use during the next iteration
|
||||
*/
|
||||
mPreviousSample = currentSample;
|
||||
}
|
||||
|
||||
public void setListener( RealSampleListener listener )
|
||||
{
|
||||
mListener = listener;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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.symbol;
|
||||
|
||||
public interface ISyncDetectListener
|
||||
{
|
||||
void syncDetected();
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* SDR Trunk
|
||||
* Copyright (C) 2014 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.symbol;
|
||||
|
||||
/**
|
||||
* Interface to allow an external process indicate that it has detected a
|
||||
* sync pattern in the bit stream
|
||||
*/
|
||||
public interface SyncDetectListener
|
||||
{
|
||||
public void syncDetected();
|
||||
}
|
||||
@@ -20,5 +20,5 @@ package io.github.dsheirer.dsp.symbol;
|
||||
|
||||
public interface SyncDetectProvider
|
||||
{
|
||||
public void setSyncDetectListener( SyncDetectListener listener );
|
||||
public void setSyncDetectListener( ISyncDetectListener listener );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user