Removes cic cleanup filter from processing chain.

This commit is contained in:
Denny
2017-03-11 11:53:12 -05:00
parent 1aa85a86ca
commit ae8a44caed

View File

@@ -1,6 +1,6 @@
/******************************************************************************* /*******************************************************************************
* SDR Trunk * sdrtrunk
* Copyright (C) 2015 Dennis Sheirer * Copyright (C) 2014-2017 Dennis Sheirer
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -14,33 +14,34 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/> * along with this program. If not, see <http://www.gnu.org/licenses/>
*
******************************************************************************/ ******************************************************************************/
package dsp.filter.cic; package dsp.filter.cic;
import java.util.ArrayList; import dsp.filter.FilterFactory;
import java.util.List; import dsp.filter.Filters;
import dsp.filter.Window.WindowType;
import dsp.filter.fir.complex.ComplexFIRFilter_CB_CB;
import dsp.filter.halfband.complex.HalfBandFilter_CB_CB;
import org.apache.commons.lang3.Validate; import org.apache.commons.lang3.Validate;
import sample.Listener; import sample.Listener;
import sample.complex.ComplexBuffer; import sample.complex.ComplexBuffer;
import sample.complex.ComplexSampleListener; import sample.complex.ComplexSampleListener;
import sample.complex.ComplexToComplexBufferAssembler; import sample.complex.ComplexToComplexBufferAssembler;
import sample.decimator.ComplexDecimator; import sample.decimator.ComplexDecimator;
import dsp.filter.FilterFactory;
import dsp.filter.Filters; import java.util.ArrayList;
import dsp.filter.Window.WindowType; import java.util.List;
import dsp.filter.fir.complex.ComplexFIRFilter_CB_CB;
import dsp.filter.halfband.complex.HalfBandFilter_CB_CB;
public class ComplexPrimeCICDecimate implements Listener<ComplexBuffer> public class ComplexPrimeCICDecimate implements Listener<ComplexBuffer>
{ {
public static int[] PRIMES = { 2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53, public static int[] PRIMES = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53,
59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151,
157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251,
257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359,
367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463,
467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593,
599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691 }; 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691};
private ArrayList<DecimatingStage> mDecimatingStages = private ArrayList<DecimatingStage> mDecimatingStages =
new ArrayList<DecimatingStage>(); new ArrayList<DecimatingStage>();
@@ -65,21 +66,21 @@ public class ComplexPrimeCICDecimate implements Listener<ComplexBuffer>
* @param decimation - overall decimation rate * @param decimation - overall decimation rate
* @param order - filter order * @param order - filter order
*/ */
public ComplexPrimeCICDecimate( int decimation, int order, public ComplexPrimeCICDecimate(int decimation, int order,
int passFrequency, int attenuation, WindowType windowType ) int passFrequency, int attenuation, WindowType windowType)
{ {
Validate.isTrue(decimation <= 700); Validate.isTrue(decimation <= 700);
List<Integer> stageSizes = getPrimeFactors( decimation ); List<Integer> stageSizes = getPrimeFactors(decimation);
for( int x = 0; x < stageSizes.size(); x++ ) for(int x = 0; x < stageSizes.size(); x++)
{ {
DecimatingStage stage = new DecimatingStage( stageSizes.get( x ), order ); DecimatingStage stage = new DecimatingStage(stageSizes.get(x), order);
mDecimatingStages.add( stage ); mDecimatingStages.add(stage);
if( x == 0 ) if(x == 0)
{ {
/* Reference to first stage -- will receive all samples */ /* Reference to first stage -- will receive all samples */
mFirstDecimatingStage = stage; mFirstDecimatingStage = stage;
@@ -87,19 +88,19 @@ public class ComplexPrimeCICDecimate implements Listener<ComplexBuffer>
else else
{ {
/* Wire the current stage to the previous stage */ /* Wire the current stage to the previous stage */
mDecimatingStages.get( x - 1 ).setListener( stage ); mDecimatingStages.get(x - 1).setListener(stage);
} }
} }
mOutput = new Output( 48000, passFrequency, attenuation, windowType ); mOutput = new Output(48000, passFrequency, attenuation, windowType);
mDecimatingStages.get( mDecimatingStages.size() - 1 ) mDecimatingStages.get(mDecimatingStages.size() - 1)
.setListener( mOutput ); .setListener(mOutput);
} }
public void dispose() public void dispose()
{ {
for( DecimatingStage stage: mDecimatingStages ) for(DecimatingStage stage : mDecimatingStages)
{ {
stage.dispose(); stage.dispose();
} }
@@ -115,9 +116,9 @@ public class ComplexPrimeCICDecimate implements Listener<ComplexBuffer>
/** /**
* Adds a listener to receive the output of this CIC decimation filter * Adds a listener to receive the output of this CIC decimation filter
*/ */
public void setListener( Listener<ComplexBuffer> listener ) public void setListener(Listener<ComplexBuffer> listener)
{ {
mOutput.setListener( listener ); mOutput.setListener(listener);
} }
/** /**
@@ -136,19 +137,19 @@ public class ComplexPrimeCICDecimate implements Listener<ComplexBuffer>
* @param decimation - integral decimation rate * @param decimation - integral decimation rate
* @return - ordered list (smallest to largest) of prime factors * @return - ordered list (smallest to largest) of prime factors
*/ */
public static List<Integer> getPrimeFactors( int decimation ) public static List<Integer> getPrimeFactors(int decimation)
{ {
ArrayList<Integer> stages = new ArrayList<Integer>(); ArrayList<Integer> stages = new ArrayList<Integer>();
int pointer = 0; int pointer = 0;
while( decimation > 0 && pointer < PRIMES.length ) while(decimation > 0 && pointer < PRIMES.length)
{ {
int prime = PRIMES[ pointer ]; int prime = PRIMES[pointer];
if( decimation % prime == 0 ) if(decimation % prime == 0)
{ {
stages.add( prime ); stages.add(prime);
decimation /= prime; decimation /= prime;
} }
@@ -165,15 +166,15 @@ public class ComplexPrimeCICDecimate implements Listener<ComplexBuffer>
* Primary input method for receiving sample arrays composed as I,Q,I,Q, etc. * Primary input method for receiving sample arrays composed as I,Q,I,Q, etc.
*/ */
@Override @Override
public void receive( ComplexBuffer buffer ) public void receive(ComplexBuffer buffer)
{ {
if( mFirstDecimatingStage != null ) if(mFirstDecimatingStage != null)
{ {
float[] samples = buffer.getSamples(); float[] samples = buffer.getSamples();
for( int x = 0; x < samples.length; x += 2 ) for(int x = 0; x < samples.length; x += 2)
{ {
mFirstDecimatingStage.receive( samples[ x ], samples[ x + 1 ] ); mFirstDecimatingStage.receive(samples[x], samples[x + 1]);
} }
} }
} }
@@ -189,41 +190,41 @@ public class ComplexPrimeCICDecimate implements Listener<ComplexBuffer>
private Stage mFirstStage; private Stage mFirstStage;
private ComplexDecimator mDecimator; private ComplexDecimator mDecimator;
public DecimatingStage( int size, int order ) public DecimatingStage(int size, int order)
{ {
for( int x = 0; x < order; x++ ) for(int x = 0; x < order; x++)
{ {
Stage stage; Stage stage;
if( size == 2 ) if(size == 2)
{ {
stage = new TwoStage(); stage = new TwoStage();
} }
else else
{ {
stage = new Stage( size ); stage = new Stage(size);
} }
mStages.add( stage ); mStages.add(stage);
if( x == 0 ) if(x == 0)
{ {
mFirstStage = stage; mFirstStage = stage;
} }
else else
{ {
mStages.get( x - 1 ).setListener( stage ); mStages.get(x - 1).setListener(stage);
} }
} }
mDecimator = new ComplexDecimator( size ); mDecimator = new ComplexDecimator(size);
mStages.get( mStages.size() - 1 ).setListener( mDecimator ); mStages.get(mStages.size() - 1).setListener(mDecimator);
} }
public void dispose() public void dispose()
{ {
for( Stage stage: mStages ) for(Stage stage : mStages)
{ {
stage.dispose(); stage.dispose();
} }
@@ -236,14 +237,14 @@ public class ComplexPrimeCICDecimate implements Listener<ComplexBuffer>
} }
@Override @Override
public void receive( float i, float q ) public void receive(float i, float q)
{ {
mFirstStage.receive( i, q ); mFirstStage.receive(i, q);
} }
public void setListener( ComplexSampleListener listener ) public void setListener(ComplexSampleListener listener)
{ {
mDecimator.setListener( listener ); mDecimator.setListener(listener);
} }
} }
@@ -271,12 +272,12 @@ public class ComplexPrimeCICDecimate implements Listener<ComplexBuffer>
{ {
} }
public Stage( int size ) public Stage(int size)
{ {
mSize = size - 1; mSize = size - 1;
mISamples = new float[ mSize ]; mISamples = new float[mSize];
mQSamples = new float[ mSize ]; mQSamples = new float[mSize];
mGain = 1.0f / (float)size; mGain = 1.0f / (float)size;
} }
@@ -286,30 +287,30 @@ public class ComplexPrimeCICDecimate implements Listener<ComplexBuffer>
mListener = null; mListener = null;
} }
public void receive( float i, float q ) public void receive(float i, float q)
{ {
/* Subtract the oldest sample and add back in the newest */ /* Subtract the oldest sample and add back in the newest */
mISum = mISum - mISamples[ mSamplePointer ] + i; mISum = mISum - mISamples[mSamplePointer] + i;
mQSum = mQSum - mQSamples[ mSamplePointer ] + q; mQSum = mQSum - mQSamples[mSamplePointer] + q;
/* Overwrite the oldest sample with the newest */ /* Overwrite the oldest sample with the newest */
mISamples[ mSamplePointer ] = i; mISamples[mSamplePointer] = i;
mQSamples[ mSamplePointer ] = q; mQSamples[mSamplePointer] = q;
mSamplePointer++; mSamplePointer++;
if( mSamplePointer >= mSize ) if(mSamplePointer >= mSize)
{ {
mSamplePointer = 0; mSamplePointer = 0;
} }
if( mListener != null ) if(mListener != null)
{ {
mListener.receive( ( mISum * mGain ), ( mQSum * mGain ) ); mListener.receive((mISum * mGain), (mQSum * mGain));
} }
} }
public void setListener( ComplexSampleListener listener ) public void setListener(ComplexSampleListener listener)
{ {
mListener = listener; mListener = listener;
} }
@@ -328,7 +329,7 @@ public class ComplexPrimeCICDecimate implements Listener<ComplexBuffer>
mGain = 0.5f; mGain = 0.5f;
} }
public void receive( float i, float q ) public void receive(float i, float q)
{ {
float iSum = mISum + i; float iSum = mISum + i;
float qSum = mQSum + q; float qSum = mQSum + q;
@@ -336,9 +337,9 @@ public class ComplexPrimeCICDecimate implements Listener<ComplexBuffer>
mISum = i; mISum = i;
mQSum = q; mQSum = q;
if( mListener != null ) if(mListener != null)
{ {
mListener.receive( ( iSum * mGain ), ( qSum * mGain ) ); mListener.receive((iSum * mGain), (qSum * mGain));
} }
} }
} }
@@ -352,23 +353,26 @@ public class ComplexPrimeCICDecimate implements Listener<ComplexBuffer>
{ {
/* Decimated output buffers will contain 1024 samples */ /* Decimated output buffers will contain 1024 samples */
private ComplexToComplexBufferAssembler mAssembler = private ComplexToComplexBufferAssembler mAssembler =
new ComplexToComplexBufferAssembler( 2048 ); new ComplexToComplexBufferAssembler(2048);
private ComplexFIRFilter_CB_CB mCleanupFilter; private ComplexFIRFilter_CB_CB mCleanupFilter;
private HalfBandFilter_CB_CB mHalfBandFilter = new HalfBandFilter_CB_CB( private HalfBandFilter_CB_CB mHalfBandFilter = new HalfBandFilter_CB_CB(
Filters.FIR_HALF_BAND_31T_ONE_EIGHTH_FCO.getCoefficients(), 0.4f, false ); Filters.FIR_HALF_BAND_31T_ONE_EIGHTH_FCO.getCoefficients(), 0.4f, false);
public Output( int outputSampleRate, int passFrequency, int attenuation, public Output(int outputSampleRate, int passFrequency, int attenuation,
WindowType windowType ) WindowType windowType)
{ {
mCleanupFilter = new ComplexFIRFilter_CB_CB( FilterFactory mCleanupFilter = new ComplexFIRFilter_CB_CB(FilterFactory
.getCICCleanupFilter( outputSampleRate, .getCICCleanupFilter(outputSampleRate,
passFrequency, passFrequency,
attenuation, attenuation,
windowType ), 0.4f ); windowType), 0.4f);
mAssembler.setListener( mCleanupFilter ); //Bypassing the CIC cleanup filter for now
mCleanupFilter.setListener( mHalfBandFilter ); mAssembler.setListener(mHalfBandFilter);
// mAssembler.setListener( mCleanupFilter );
// mCleanupFilter.setListener( mHalfBandFilter );
} }
public void dispose() public void dispose()
@@ -384,17 +388,17 @@ public class ComplexPrimeCICDecimate implements Listener<ComplexBuffer>
* and output the sample values as a complex sample. * and output the sample values as a complex sample.
*/ */
@Override @Override
public void receive( float inphase, float quadrature ) public void receive(float inphase, float quadrature)
{ {
mAssembler.receive( inphase, quadrature ); mAssembler.receive(inphase, quadrature);
} }
/** /**
* Adds a listener to receive output samples * Adds a listener to receive output samples
*/ */
public void setListener( Listener<ComplexBuffer> listener ) public void setListener(Listener<ComplexBuffer> listener)
{ {
mHalfBandFilter.setListener( listener ); mHalfBandFilter.setListener(listener);
} }
/** /**