330 WIP on redesigning the P25 C4FM decoder. Creates a new decoder

based on the P25 LSM decoder using a costas loop and a gardner detector.
Updates the Demodulator Viewer FX application to add in a symbol chart
and a phase error chart.  The decoder won't lock on yet ... still a wip.
This commit is contained in:
Denny
2018-02-17 13:41:36 -05:00
parent 80c5ad1bc8
commit eaf7c7d11e
47 changed files with 3926 additions and 2093 deletions

View File

@@ -1,80 +1,168 @@
/*******************************************************************************
* 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.buffer;
import org.apache.commons.math3.stat.descriptive.moment.Mean;
import org.apache.commons.math3.stat.descriptive.moment.Variance;
import org.apache.commons.math3.stat.descriptive.rank.Max;
import org.apache.commons.math3.stat.descriptive.rank.Min;
import java.util.Arrays;
/**
* Circular sample buffer - allocates a buffer and stores samples in a circular
* fashion, overwriting older samples with newly arrived samples. Initially
* fills buffer with 0-valued samples
*
* Can be used as a delay-type buffer, to delay samples by the 'size' amount
* Circular sample buffer - allocates a buffer and stores samples in a circular fashion, overwriting older samples with
* newly arrived samples. Initially fills buffer with 0-valued (default) samples or with a specified value.
*/
public class DoubleCircularBuffer
{
double[] mBuffer;
int mBufferPointer = 0;
public DoubleCircularBuffer( int size )
{
mBuffer = new double[ size ];
Arrays.fill( mBuffer, 0.0 );
}
private Variance mVariance;
private Max mMax;
private Mean mMean;
private Min mMin;
private double[] mBuffer;
private int mBufferPointer = 0;
/**
* Puts the new value into the buffer and returns the oldest buffer value
* that it replaced
* @param newValue
* @return
*/
public double get( double newValue )
{
double oldestSample = mBuffer[ mBufferPointer ];
/**
* Creates a circular double buffer of the specified size and all entries filled with the specified initial value.
* @param size of the buffer
* @param initialFillValue to fill the buffer entries
*/
public DoubleCircularBuffer(int size, double initialFillValue)
{
mBuffer = new double[size];
Arrays.fill(mBuffer, initialFillValue);
}
mBuffer[ mBufferPointer ] = newValue;
mBufferPointer++;
if( mBufferPointer >= mBuffer.length )
{
mBufferPointer = 0;
}
return oldestSample;
}
/**
* Creates a circular double buffer of the specified size and all entries filled with an initial value of zero.
* @param size of the buffer
*/
public DoubleCircularBuffer(int size)
{
this(size, 0.0);
}
/**
* Returns the maximum from the values currently in the buffer
*/
public double max()
{
double max = 0.0d;
for( int x = 0; x < mBuffer.length; x++ )
{
if( mBuffer[ x ] > max )
{
max = mBuffer[ x ];
}
}
return max;
}
/**
* Puts the new value into the buffer and returns the oldest buffer value that it replaced
*
* @param newValue to add to the buffer
* @return oldest value that was overwritten by the new value
*/
public double get(double newValue)
{
double oldestSample = mBuffer[mBufferPointer];
mBuffer[mBufferPointer] = newValue;
mBufferPointer++;
if(mBufferPointer >= mBuffer.length)
{
mBufferPointer = 0;
}
return oldestSample;
}
public double[] getAll()
{
int valuePointer = 0;
double[] values = new double[mBuffer.length];
int bufferPointer = mBufferPointer;
while(valuePointer < values.length)
{
values[valuePointer++] = mBuffer[bufferPointer++];
if(bufferPointer >= mBuffer.length)
{
bufferPointer = 0;
}
}
return values;
}
/**
* Places the new value into the buffer, overwriting the oldest value
* @param newValue to add to the buffer
*/
public void put(double newValue)
{
mBuffer[mBufferPointer] = newValue;
mBufferPointer++;
if(mBufferPointer >= mBuffer.length)
{
mBufferPointer = 0;
}
}
/**
* Returns the maximum from the values currently in the buffer
*/
public double max()
{
if(mMax == null)
{
mMax = new Max();
}
return mMax.evaluate(mBuffer, 0, mBuffer.length);
}
/**
* Returns the minimum from the values currently in the buffer
*/
public double min()
{
if(mMin == null)
{
mMin = new Min();
}
return mMin.evaluate(mBuffer, 0, mBuffer.length);
}
/**
* Calculates the variance of the values contained in this buffer
*/
public double variance()
{
if(mVariance == null)
{
mVariance = new Variance();
}
return mVariance.evaluate(mBuffer);
}
/**
* Calculates the average/mean of the values contained in this buffer
*/
public double mean()
{
if(mMean == null)
{
mMean = new Mean();
}
return mMean.evaluate(mBuffer, 0, mBuffer.length);
}
}