mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-12 08:37:25 -05:00
Improved LTR FSK decoder for LTR, LTR-Net and Passport decoders. Added IIR DC blocking filter and used improved slicer from the FSK decoder.
Added instrumentation to Passport decoder and updated some of the instrumentation components.
This commit is contained in:
107
src/buffer/BooleanAveragingBuffer.java
Normal file
107
src/buffer/BooleanAveragingBuffer.java
Normal file
@@ -0,0 +1,107 @@
|
||||
/*******************************************************************************
|
||||
* 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 buffer;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
|
||||
/**
|
||||
* Circular Buffer - implements a circular buffer with a method to get the
|
||||
* current head of the buffer, and put a new value in its place at the same
|
||||
* time
|
||||
*
|
||||
* Also provides averaging over the elements in the buffer
|
||||
*/
|
||||
public class BooleanAveragingBuffer {
|
||||
|
||||
private boolean[] mBuffer;
|
||||
private int mBufferPointer;
|
||||
|
||||
public BooleanAveragingBuffer( int length )
|
||||
{
|
||||
mBuffer = new boolean[ length ];
|
||||
|
||||
//Preload the array with false values
|
||||
Arrays.fill( mBuffer, false );
|
||||
}
|
||||
|
||||
public boolean get( boolean newValue )
|
||||
{
|
||||
//Fetch current boolean value
|
||||
boolean retVal = mBuffer[ mBufferPointer ];
|
||||
|
||||
//Load the new value into the buffer
|
||||
put( newValue );
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the newValue into this buffer and adjusts the buffer pointer
|
||||
* to prepare for the next get/put cycle
|
||||
*/
|
||||
private void put( boolean newValue )
|
||||
{
|
||||
//Store the new value to the buffer
|
||||
mBuffer[ mBufferPointer ] = newValue;
|
||||
|
||||
//Increment the buffer pointer
|
||||
mBufferPointer++;
|
||||
|
||||
//Wrap the buffer pointer around to 0 when necessary
|
||||
if( mBufferPointer >= mBuffer.length )
|
||||
{
|
||||
mBufferPointer = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the newValue into the buffer, calculates the average
|
||||
* and returns that average from this method
|
||||
*
|
||||
* This effectively performs low-pass filtering
|
||||
*/
|
||||
public boolean getAverage( boolean newValue )
|
||||
{
|
||||
//Load the new value into the buffer
|
||||
put( newValue );
|
||||
|
||||
int trueCount = 0;
|
||||
|
||||
for( int x = 0; x < mBuffer.length; x++ )
|
||||
{
|
||||
if( mBuffer[ x ] )
|
||||
{
|
||||
trueCount++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If the number of true values in the buffer is
|
||||
* more than half, return true, otherwise, false
|
||||
*/
|
||||
if( trueCount > (int)( mBuffer.length / 2 ) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user