[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:
Denny
2018-06-02 08:47:48 -04:00
parent c13315f731
commit a898be265f
64 changed files with 2660 additions and 1285 deletions

View File

@@ -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;

View File

@@ -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;
}
}

View File

@@ -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;
}
}