mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-16 10:37:26 -05:00
#90 [WIP] Resolves issue with MPT-1327 decoder which has apparently been broken for a long time.
This commit is contained in:
@@ -20,11 +20,15 @@ package channel.metadata;
|
|||||||
|
|
||||||
import channel.state.State;
|
import channel.state.State;
|
||||||
import module.decode.DecoderType;
|
import module.decode.DecoderType;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import sample.Broadcaster;
|
import sample.Broadcaster;
|
||||||
import sample.Listener;
|
import sample.Listener;
|
||||||
|
|
||||||
public class MutableMetadata extends Metadata implements Listener<AttributeChangeRequest>
|
public class MutableMetadata extends Metadata implements Listener<AttributeChangeRequest>
|
||||||
{
|
{
|
||||||
|
private final static Logger mLog = LoggerFactory.getLogger(MutableMetadata.class);
|
||||||
|
|
||||||
private Broadcaster<MutableMetadataChangeEvent> mMetadataChangeEventBroadcaster = new Broadcaster<>();
|
private Broadcaster<MutableMetadataChangeEvent> mMetadataChangeEventBroadcaster = new Broadcaster<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -138,7 +142,7 @@ public class MutableMetadata extends Metadata implements Listener<AttributeChang
|
|||||||
broadcast(Attribute.SECONDARY_ADDRESS_TO);
|
broadcast(Attribute.SECONDARY_ADDRESS_TO);
|
||||||
break;
|
break;
|
||||||
case CHANNEL_STATE:
|
case CHANNEL_STATE:
|
||||||
mState = (State)request.getValue();
|
mState = (State) request.getValue();
|
||||||
broadcast(Attribute.CHANNEL_STATE);
|
broadcast(Attribute.CHANNEL_STATE);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -121,8 +121,6 @@ public class ChannelState extends Module implements ICallEventProvider, IDecoder
|
|||||||
{
|
{
|
||||||
broadcast(new DecoderStateEvent(this, Event.RESET, State.IDLE));
|
broadcast(new DecoderStateEvent(this, Event.RESET, State.IDLE));
|
||||||
|
|
||||||
mMutableMetadata.resetTemporalAttributes();
|
|
||||||
|
|
||||||
mState = State.IDLE;
|
mState = State.IDLE;
|
||||||
mMutableMetadata.receive(new AttributeChangeRequest<State>(Attribute.CHANNEL_STATE, mState));
|
mMutableMetadata.receive(new AttributeChangeRequest<State>(Attribute.CHANNEL_STATE, mState));
|
||||||
}
|
}
|
||||||
@@ -475,6 +473,7 @@ public class ChannelState extends Module implements ICallEventProvider, IDecoder
|
|||||||
*/
|
*/
|
||||||
public void configureAsTrafficChannel(TrafficChannelManager manager, CallEvent callEvent)
|
public void configureAsTrafficChannel(TrafficChannelManager manager, CallEvent callEvent)
|
||||||
{
|
{
|
||||||
|
mLog.debug("Configuring for traffic channel: " + callEvent.toCSV());
|
||||||
mTrafficChannelEndListener = manager;
|
mTrafficChannelEndListener = manager;
|
||||||
|
|
||||||
mTrafficChannelCallEvent = callEvent;
|
mTrafficChannelCallEvent = callEvent;
|
||||||
@@ -487,30 +486,32 @@ public class ChannelState extends Module implements ICallEventProvider, IDecoder
|
|||||||
mMutableMetadata.receive(new AttributeChangeRequest<String>(Attribute.CHANNEL_FREQUENCY_LABEL, channel));
|
mMutableMetadata.receive(new AttributeChangeRequest<String>(Attribute.CHANNEL_FREQUENCY_LABEL, channel));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
long frequency = mTrafficChannelCallEvent.getFrequency();
|
||||||
|
|
||||||
|
if(frequency > 0)
|
||||||
|
{
|
||||||
|
mMutableMetadata.receive(new AttributeChangeRequest<Long>(Attribute.CHANNEL_FREQUENCY, frequency));
|
||||||
|
}
|
||||||
|
|
||||||
mMutableMetadata.receive(new AttributeChangeRequest<DecoderType>(Attribute.PRIMARY_DECODER_TYPE,
|
mMutableMetadata.receive(new AttributeChangeRequest<DecoderType>(Attribute.PRIMARY_DECODER_TYPE,
|
||||||
mTrafficChannelCallEvent.getDecoderType()));
|
mTrafficChannelCallEvent.getDecoderType()));
|
||||||
|
|
||||||
String details = mTrafficChannelCallEvent.getDetails();
|
mMutableMetadata.receive(new AttributeChangeRequest<String>(Attribute.CHANNEL_CONFIGURATION_LABEL_1, "TRAFFIC"));
|
||||||
|
|
||||||
String from = mTrafficChannelCallEvent.getFromID();
|
String from = mTrafficChannelCallEvent.getFromID();
|
||||||
|
|
||||||
if(from != null)
|
if(from != null)
|
||||||
{
|
{
|
||||||
mMutableMetadata.receive(new AttributeChangeRequest<String>(Attribute.PRIMARY_ADDRESS_FROM, from));
|
mMutableMetadata.receive(new AttributeChangeRequest<String>(Attribute.PRIMARY_ADDRESS_FROM, from,
|
||||||
|
mTrafficChannelCallEvent.getFromIDAlias()));
|
||||||
}
|
}
|
||||||
|
|
||||||
String to = mTrafficChannelCallEvent.getToID();
|
String to = mTrafficChannelCallEvent.getToID();
|
||||||
|
|
||||||
if(to != null)
|
if(to != null)
|
||||||
{
|
{
|
||||||
mMutableMetadata.receive(new AttributeChangeRequest<String>(Attribute.PRIMARY_ADDRESS_TO, to));
|
mMutableMetadata.receive(new AttributeChangeRequest<String>(Attribute.PRIMARY_ADDRESS_TO, to,
|
||||||
}
|
mTrafficChannelCallEvent.getToIDAlias()));
|
||||||
|
|
||||||
long frequency = mTrafficChannelCallEvent.getFrequency();
|
|
||||||
|
|
||||||
if(frequency > 0)
|
|
||||||
{
|
|
||||||
mMutableMetadata.receive(new AttributeChangeRequest<Long>(Attribute.CHANNEL_FREQUENCY, frequency));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Rebroadcast the allocation event so that the internal decoder states
|
/* Rebroadcast the allocation event so that the internal decoder states
|
||||||
|
|||||||
@@ -194,8 +194,7 @@ public class ChannelProcessingManager implements ChannelEventListener
|
|||||||
|
|
||||||
if(processingChain == null)
|
if(processingChain == null)
|
||||||
{
|
{
|
||||||
processingChain = new ProcessingChain(channel.getName(),
|
processingChain = new ProcessingChain(channel.getName(), channel.getChannelType());
|
||||||
channel.getChannelType());
|
|
||||||
|
|
||||||
/* Register global listeners */
|
/* Register global listeners */
|
||||||
for(Listener<AudioPacket> listener : mAudioPacketListeners)
|
for(Listener<AudioPacket> listener : mAudioPacketListeners)
|
||||||
|
|||||||
@@ -1,18 +1,20 @@
|
|||||||
package controller.channel.map;
|
package controller.channel.map;
|
||||||
|
|
||||||
|
import controller.channel.map.ChannelMapEvent.Event;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import sample.Broadcaster;
|
||||||
|
import sample.Listener;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.swing.AbstractListModel;
|
|
||||||
|
|
||||||
import controller.channel.map.ChannelMapEvent.Event;
|
|
||||||
import sample.Broadcaster;
|
|
||||||
import sample.Listener;
|
|
||||||
|
|
||||||
public class ChannelMapModel extends AbstractListModel<ChannelMap>
|
public class ChannelMapModel extends AbstractListModel<ChannelMap>
|
||||||
{
|
{
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
private final static Logger mLog = LoggerFactory.getLogger(ChannelMapModel.class);
|
||||||
|
|
||||||
private List<ChannelMap> mChannelMaps = new ArrayList<>();
|
private List<ChannelMap> mChannelMaps = new ArrayList<>();
|
||||||
private Broadcaster<ChannelMapEvent> mEventBroadcaster = new Broadcaster<>();
|
private Broadcaster<ChannelMapEvent> mEventBroadcaster = new Broadcaster<>();
|
||||||
@@ -26,17 +28,17 @@ public class ChannelMapModel extends AbstractListModel<ChannelMap>
|
|||||||
*/
|
*/
|
||||||
public List<ChannelMap> getChannelMaps()
|
public List<ChannelMap> getChannelMaps()
|
||||||
{
|
{
|
||||||
return Collections.unmodifiableList( mChannelMaps );
|
return Collections.unmodifiableList(mChannelMaps);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the channel map with a matching name or null
|
* Returns the channel map with a matching name or null
|
||||||
*/
|
*/
|
||||||
public ChannelMap getChannelMap( String name )
|
public ChannelMap getChannelMap(String name)
|
||||||
{
|
{
|
||||||
for( ChannelMap channelMap: mChannelMaps )
|
for(ChannelMap channelMap : mChannelMaps)
|
||||||
{
|
{
|
||||||
if( channelMap.getName().equalsIgnoreCase( name ) )
|
if(channelMap.getName().equalsIgnoreCase(name))
|
||||||
{
|
{
|
||||||
return channelMap;
|
return channelMap;
|
||||||
}
|
}
|
||||||
@@ -48,17 +50,17 @@ public class ChannelMapModel extends AbstractListModel<ChannelMap>
|
|||||||
/**
|
/**
|
||||||
* Adds a listener to receive notifications when channel map updates occur
|
* Adds a listener to receive notifications when channel map updates occur
|
||||||
*/
|
*/
|
||||||
public void addListener( Listener<ChannelMapEvent> listener )
|
public void addListener(Listener<ChannelMapEvent> listener)
|
||||||
{
|
{
|
||||||
mEventBroadcaster.addListener( listener );
|
mEventBroadcaster.addListener(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes the channel map update notification listener
|
* Removes the channel map update notification listener
|
||||||
*/
|
*/
|
||||||
public void removeListener( Listener<ChannelMapEvent> listener )
|
public void removeListener(Listener<ChannelMapEvent> listener)
|
||||||
{
|
{
|
||||||
mEventBroadcaster.removeListener( listener );
|
mEventBroadcaster.removeListener(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -68,47 +70,47 @@ public class ChannelMapModel extends AbstractListModel<ChannelMap>
|
|||||||
* model. When using those methods, an add or delete event will automatically
|
* model. When using those methods, an add or delete event will automatically
|
||||||
* be generated.
|
* be generated.
|
||||||
*/
|
*/
|
||||||
public void broadcast( ChannelMapEvent event )
|
public void broadcast(ChannelMapEvent event)
|
||||||
{
|
{
|
||||||
if( event.getEvent() == ChannelMapEvent.Event.CHANGE ||
|
if(event.getEvent() == ChannelMapEvent.Event.CHANGE ||
|
||||||
event.getEvent() == ChannelMapEvent.Event.RENAME )
|
event.getEvent() == ChannelMapEvent.Event.RENAME)
|
||||||
{
|
{
|
||||||
int index = mChannelMaps.indexOf( event.getChannelMap() );
|
int index = mChannelMaps.indexOf(event.getChannelMap());
|
||||||
|
|
||||||
if( index >= 0 )
|
if(index >= 0)
|
||||||
{
|
{
|
||||||
fireContentsChanged( this, index, index );
|
fireContentsChanged(this, index, index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mEventBroadcaster.broadcast( event );
|
mEventBroadcaster.broadcast(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a list of channel maps to this model
|
* Adds a list of channel maps to this model
|
||||||
*/
|
*/
|
||||||
public void addChannelMaps( List<ChannelMap> channelMaps )
|
public void addChannelMaps(List<ChannelMap> channelMaps)
|
||||||
{
|
{
|
||||||
for( ChannelMap channelMap: channelMaps )
|
for(ChannelMap channelMap : channelMaps)
|
||||||
{
|
{
|
||||||
addChannelMap( channelMap );
|
addChannelMap(channelMap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the channel map to this model
|
* Adds the channel map to this model
|
||||||
*/
|
*/
|
||||||
public void addChannelMap( ChannelMap channelMap )
|
public void addChannelMap(ChannelMap channelMap)
|
||||||
{
|
{
|
||||||
if( !mChannelMaps.contains( channelMap ) )
|
if(!mChannelMaps.contains(channelMap))
|
||||||
{
|
{
|
||||||
mChannelMaps.add( channelMap );
|
mChannelMaps.add(channelMap);
|
||||||
|
|
||||||
int index = mChannelMaps.indexOf( channelMap );
|
int index = mChannelMaps.indexOf(channelMap);
|
||||||
|
|
||||||
fireIntervalAdded( this, index, index );
|
fireIntervalAdded(this, index, index);
|
||||||
|
|
||||||
broadcast( new ChannelMapEvent( channelMap, Event.ADD ) );
|
broadcast(new ChannelMapEvent(channelMap, Event.ADD));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -116,17 +118,17 @@ public class ChannelMapModel extends AbstractListModel<ChannelMap>
|
|||||||
/**
|
/**
|
||||||
* Removes the channel map from this model
|
* Removes the channel map from this model
|
||||||
*/
|
*/
|
||||||
public void removeChannelMap( ChannelMap channelMap )
|
public void removeChannelMap(ChannelMap channelMap)
|
||||||
{
|
{
|
||||||
if( mChannelMaps.contains( channelMap ) )
|
if(mChannelMaps.contains(channelMap))
|
||||||
{
|
{
|
||||||
int index = mChannelMaps.indexOf( channelMap );
|
int index = mChannelMaps.indexOf(channelMap);
|
||||||
|
|
||||||
mChannelMaps.remove( channelMap );
|
mChannelMaps.remove(channelMap);
|
||||||
|
|
||||||
fireIntervalRemoved( this, index, index );
|
fireIntervalRemoved(this, index, index);
|
||||||
|
|
||||||
broadcast( new ChannelMapEvent( channelMap, Event.DELETE ) );
|
broadcast(new ChannelMapEvent(channelMap, Event.DELETE));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,11 +145,11 @@ public class ChannelMapModel extends AbstractListModel<ChannelMap>
|
|||||||
* Returns the channel map at the specified index
|
* Returns the channel map at the specified index
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public ChannelMap getElementAt( int index )
|
public ChannelMap getElementAt(int index)
|
||||||
{
|
{
|
||||||
if( index <= mChannelMaps.size() )
|
if(index <= mChannelMaps.size())
|
||||||
{
|
{
|
||||||
return mChannelMaps.get( index );
|
return mChannelMaps.get(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -22,66 +22,69 @@
|
|||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package dsp.filter;
|
package dsp.filter;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import dsp.filter.Window.WindowType;
|
||||||
import java.util.Set;
|
import dsp.filter.cic.ComplexPrimeCICDecimate;
|
||||||
import java.util.TreeSet;
|
import dsp.filter.design.FilterDesignException;
|
||||||
|
import dsp.filter.fir.FIRFilterSpecification;
|
||||||
|
import dsp.filter.fir.remez.RemezFIRFilterDesigner;
|
||||||
import org.jtransforms.fft.FloatFFT_1D;
|
import org.jtransforms.fft.FloatFFT_1D;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import dsp.filter.Window.WindowType;
|
import java.util.Arrays;
|
||||||
import dsp.filter.cic.ComplexPrimeCICDecimate;
|
import java.util.Set;
|
||||||
|
import java.util.TreeSet;
|
||||||
|
|
||||||
public class FilterFactory
|
public class FilterFactory
|
||||||
{
|
{
|
||||||
private final static Logger mLog =
|
private final static Logger mLog =
|
||||||
LoggerFactory.getLogger( FilterFactory.class );
|
LoggerFactory.getLogger(FilterFactory.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates coefficients for a unity-gain, windowed low-pass filter
|
* Generates coefficients for a unity-gain, windowed low-pass filter
|
||||||
|
*
|
||||||
* @param sampleRate - hertz
|
* @param sampleRate - hertz
|
||||||
* @param frequency - cutoff in hertz
|
* @param frequency - cutoff in hertz
|
||||||
* @param length - filter length
|
* @param length - filter length
|
||||||
* @param window - to apply against the coefficients
|
* @param window - to apply against the coefficients
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static float[] getSinc( int sampleRate,
|
public static float[] getSinc(int sampleRate,
|
||||||
long frequency,
|
long frequency,
|
||||||
int length,
|
int length,
|
||||||
WindowType window )
|
WindowType window)
|
||||||
{
|
{
|
||||||
//Ensure we have an odd length
|
//Ensure we have an odd length
|
||||||
assert( length % 2 == 0 );
|
assert (length % 2 == 0);
|
||||||
|
|
||||||
//Get unity response array (one element longer to align with IDFT size)
|
//Get unity response array (one element longer to align with IDFT size)
|
||||||
float[] frequencyResponse = getUnityResponseArray( sampleRate, frequency, length + 1 );
|
float[] frequencyResponse = getUnityResponseArray(sampleRate, frequency, length + 1);
|
||||||
|
|
||||||
//Apply Inverse DFT against frequency response unity values, leaving the
|
//Apply Inverse DFT against frequency response unity values, leaving the
|
||||||
//IDFT bin results in the frequency response array
|
//IDFT bin results in the frequency response array
|
||||||
FloatFFT_1D idft = new FloatFFT_1D( length + 1 );
|
FloatFFT_1D idft = new FloatFFT_1D(length + 1);
|
||||||
idft.realInverseFull( frequencyResponse, false );
|
idft.realInverseFull(frequencyResponse, false);
|
||||||
|
|
||||||
//Transfer the IDFT results to the return array
|
//Transfer the IDFT results to the return array
|
||||||
float[] coefficients = new float[ length ];
|
float[] coefficients = new float[length];
|
||||||
int middleCoefficient = (int)( length / 2 );
|
int middleCoefficient = (int) (length / 2);
|
||||||
|
|
||||||
//Bin 0 of the idft is our center coefficient
|
//Bin 0 of the idft is our center coefficient
|
||||||
coefficients[ middleCoefficient ] = frequencyResponse[ 0 ];
|
coefficients[middleCoefficient] = frequencyResponse[0];
|
||||||
|
|
||||||
//The remaining idft bins from 1 to (middle - 1) are the mirror image
|
//The remaining idft bins from 1 to (middle - 1) are the mirror image
|
||||||
//coefficients
|
//coefficients
|
||||||
for( int x = 1; x < middleCoefficient; x++ )
|
for(int x = 1; x < middleCoefficient; x++)
|
||||||
{
|
{
|
||||||
coefficients[ middleCoefficient + x ] = frequencyResponse[ 2 * x ];
|
coefficients[middleCoefficient + x] = frequencyResponse[2 * x];
|
||||||
coefficients[ middleCoefficient - x ] = frequencyResponse[ 2 * x ];
|
coefficients[middleCoefficient - x] = frequencyResponse[2 * x];
|
||||||
}
|
}
|
||||||
|
|
||||||
//Apply the window against the coefficients
|
//Apply the window against the coefficients
|
||||||
coefficients = Window.apply( window, coefficients );
|
coefficients = Window.apply(window, coefficients);
|
||||||
|
|
||||||
//Normalize to unity (1) gain
|
//Normalize to unity (1) gain
|
||||||
coefficients = normalize( coefficients );
|
coefficients = normalize(coefficients);
|
||||||
|
|
||||||
return coefficients;
|
return coefficients;
|
||||||
}
|
}
|
||||||
@@ -89,21 +92,22 @@ public class FilterFactory
|
|||||||
/**
|
/**
|
||||||
* Normalizes all filter coefficients to achieve unity (1) gain, by ensuring
|
* Normalizes all filter coefficients to achieve unity (1) gain, by ensuring
|
||||||
* that the sum of the absolute value of all coefficients adds up to 1.
|
* that the sum of the absolute value of all coefficients adds up to 1.
|
||||||
|
*
|
||||||
* @param coefficients
|
* @param coefficients
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private static float[] normalize( float[] coefficients )
|
private static float[] normalize(float[] coefficients)
|
||||||
{
|
{
|
||||||
float accumulator = 0;
|
float accumulator = 0;
|
||||||
|
|
||||||
for( int x = 0; x < coefficients.length; x++ )
|
for(int x = 0; x < coefficients.length; x++)
|
||||||
{
|
{
|
||||||
accumulator += Math.abs( coefficients[ x ] );
|
accumulator += Math.abs(coefficients[x]);
|
||||||
}
|
}
|
||||||
|
|
||||||
for( int x = 0; x < coefficients.length; x++ )
|
for(int x = 0; x < coefficients.length; x++)
|
||||||
{
|
{
|
||||||
coefficients[ x ] = coefficients[ x ] / accumulator;
|
coefficients[x] = coefficients[x] / accumulator;
|
||||||
}
|
}
|
||||||
|
|
||||||
return coefficients;
|
return coefficients;
|
||||||
@@ -125,51 +129,51 @@ public class FilterFactory
|
|||||||
* @param length
|
* @param length
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static float[] getUnityResponseArray( int sampleRate,
|
public static float[] getUnityResponseArray(int sampleRate,
|
||||||
long frequency,
|
long frequency,
|
||||||
int length )
|
int length)
|
||||||
{
|
{
|
||||||
float[] unityArray = new float[ length * 2 ];
|
float[] unityArray = new float[length * 2];
|
||||||
|
|
||||||
int binCount = (int)( ( Math.round(
|
int binCount = (int) ((Math.round(
|
||||||
(float)frequency / (float)sampleRate * (float)length ) ) );
|
(float) frequency / (float) sampleRate * (float) length)));
|
||||||
|
|
||||||
if( length % 2 == 0 ) //even length
|
if(length % 2 == 0) //even length
|
||||||
{
|
{
|
||||||
for( int x = 0; x < binCount; x++ )
|
for(int x = 0; x < binCount; x++)
|
||||||
{
|
{
|
||||||
unityArray[ x ] = 1.0f;
|
unityArray[x] = 1.0f;
|
||||||
unityArray[ length - 1 - x ] = 1.0f;
|
unityArray[length - 1 - x] = 1.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else //odd length
|
else //odd length
|
||||||
{
|
{
|
||||||
unityArray[ 0 ] = 1.0f;
|
unityArray[0] = 1.0f;
|
||||||
|
|
||||||
for( int x = 1; x <= binCount; x++ )
|
for(int x = 1; x <= binCount; x++)
|
||||||
{
|
{
|
||||||
unityArray[ x ] = 1.0f;
|
unityArray[x] = 1.0f;
|
||||||
unityArray[ length - x ] = 1.0f;
|
unityArray[length - x] = 1.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return unityArray;
|
return unityArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float[] getSine( float sampleRate, float frequency, int length )
|
public static float[] getSine(float sampleRate, float frequency, int length)
|
||||||
{
|
{
|
||||||
float[] retVal = new float[ length ];
|
float[] retVal = new float[length];
|
||||||
|
|
||||||
float radianFrequency = (float)( 2.0d * Math.PI * ( frequency / sampleRate ) );
|
float radianFrequency = (float) (2.0d * Math.PI * (frequency / sampleRate));
|
||||||
|
|
||||||
int middle = (int)( length / 2 );
|
int middle = (int) (length / 2);
|
||||||
|
|
||||||
for( int x = 0; x < middle; x++ )
|
for(int x = 0; x < middle; x++)
|
||||||
{
|
{
|
||||||
float val = (float)Math.sin( radianFrequency * x );
|
float val = (float) Math.sin(radianFrequency * x);
|
||||||
|
|
||||||
retVal[ middle + x ] = val;
|
retVal[middle + x] = val;
|
||||||
retVal[ middle - x ] = -val;
|
retVal[middle - x] = -val;
|
||||||
}
|
}
|
||||||
|
|
||||||
return retVal;
|
return retVal;
|
||||||
@@ -188,11 +192,11 @@ public class FilterFactory
|
|||||||
* ...
|
* ...
|
||||||
* Index length - 1: same
|
* Index length - 1: same
|
||||||
*/
|
*/
|
||||||
public static float[] invert( float[] coefficients )
|
public static float[] invert(float[] coefficients)
|
||||||
{
|
{
|
||||||
for( int x = 1; x < coefficients.length; x += 2 )
|
for(int x = 1; x < coefficients.length; x += 2)
|
||||||
{
|
{
|
||||||
coefficients[ x ] = -coefficients[ x ];
|
coefficients[x] = -coefficients[x];
|
||||||
}
|
}
|
||||||
|
|
||||||
return coefficients;
|
return coefficients;
|
||||||
@@ -208,24 +212,24 @@ public class FilterFactory
|
|||||||
* @param windowType - window to apply against the generated coefficients
|
* @param windowType - window to apply against the generated coefficients
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static float[] getLowPass( int sampleRate,
|
public static float[] getLowPass(int sampleRate,
|
||||||
long cutoff,
|
long cutoff,
|
||||||
int filterLength,
|
int filterLength,
|
||||||
WindowType windowType )
|
WindowType windowType)
|
||||||
{
|
{
|
||||||
if( filterLength % 2 == 0 ) //even length
|
if(filterLength % 2 == 0) //even length
|
||||||
{
|
{
|
||||||
float[] values = getSinc( sampleRate, cutoff, filterLength + 2, windowType );
|
float[] values = getSinc(sampleRate, cutoff, filterLength + 2, windowType);
|
||||||
|
|
||||||
//throw away the 0 index and the last index
|
//throw away the 0 index and the last index
|
||||||
return Arrays.copyOfRange( values, 1, values.length - 2 );
|
return Arrays.copyOfRange(values, 1, values.length - 2);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
float[] values = getSinc( sampleRate, cutoff, filterLength + 1, windowType );
|
float[] values = getSinc(sampleRate, cutoff, filterLength + 1, windowType);
|
||||||
|
|
||||||
//throw away the 0 index
|
//throw away the 0 index
|
||||||
return Arrays.copyOfRange( values, 1, values.length );
|
return Arrays.copyOfRange(values, 1, values.length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -243,36 +247,36 @@ public class FilterFactory
|
|||||||
* - passFrequency < stopFrequency
|
* - passFrequency < stopFrequency
|
||||||
* - stopFrequency <= sampleRate/2
|
* - stopFrequency <= sampleRate/2
|
||||||
*/
|
*/
|
||||||
public static float[] getLowPass( int sampleRate,
|
public static float[] getLowPass(int sampleRate,
|
||||||
int passFrequency,
|
int passFrequency,
|
||||||
int stopFrequency,
|
int stopFrequency,
|
||||||
int attenuation,
|
int attenuation,
|
||||||
WindowType windowType,
|
WindowType windowType,
|
||||||
boolean forceOddLength )
|
boolean forceOddLength)
|
||||||
{
|
{
|
||||||
if( stopFrequency < passFrequency || stopFrequency > ( sampleRate / 2 ) )
|
if(stopFrequency < passFrequency || stopFrequency > (sampleRate / 2))
|
||||||
{
|
{
|
||||||
throw new IllegalArgumentException( "FilterFactory - low pass "
|
throw new IllegalArgumentException("FilterFactory - low pass "
|
||||||
+ "filter pass frequency [" + passFrequency + "] must be "
|
+ "filter pass frequency [" + passFrequency + "] must be "
|
||||||
+ "less than the stop frequency [" + stopFrequency + "] "
|
+ "less than the stop frequency [" + stopFrequency + "] "
|
||||||
+ "and must be less than half [" + (int)( sampleRate / 2 ) +
|
+ "and must be less than half [" + (int) (sampleRate / 2) +
|
||||||
"] of the sample rate [" + sampleRate + "]" );
|
"] of the sample rate [" + sampleRate + "]");
|
||||||
}
|
}
|
||||||
|
|
||||||
int tapCount = getTapCount( sampleRate,
|
int tapCount = getTapCount(sampleRate,
|
||||||
passFrequency,
|
passFrequency,
|
||||||
stopFrequency,
|
stopFrequency,
|
||||||
attenuation );
|
attenuation);
|
||||||
|
|
||||||
if( forceOddLength )
|
if(forceOddLength)
|
||||||
{
|
{
|
||||||
if( tapCount % 2 == 0 )
|
if(tapCount % 2 == 0)
|
||||||
{
|
{
|
||||||
tapCount--;
|
tapCount--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return getLowPass( sampleRate, passFrequency, tapCount, windowType );
|
return getLowPass(sampleRate, passFrequency, tapCount, windowType);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -286,69 +290,69 @@ public class FilterFactory
|
|||||||
* @param windowType - window to apply against the generated coefficients
|
* @param windowType - window to apply against the generated coefficients
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static float[] getHighPass( int sampleRate,
|
public static float[] getHighPass(int sampleRate,
|
||||||
long cutoff,
|
long cutoff,
|
||||||
int filterLength,
|
int filterLength,
|
||||||
WindowType windowType )
|
WindowType windowType)
|
||||||
{
|
{
|
||||||
//Convert the high frequency cutoff to its low frequency cutoff
|
//Convert the high frequency cutoff to its low frequency cutoff
|
||||||
//equivalent, so that when we generate the low pass filter, prior to
|
//equivalent, so that when we generate the low pass filter, prior to
|
||||||
//inversion, its at the correct frequency
|
//inversion, its at the correct frequency
|
||||||
long convertedCutoff = sampleRate / 2 - cutoff;
|
long convertedCutoff = sampleRate / 2 - cutoff;
|
||||||
|
|
||||||
return invert( getSinc( sampleRate,
|
return invert(getSinc(sampleRate,
|
||||||
convertedCutoff,
|
convertedCutoff,
|
||||||
filterLength,
|
filterLength,
|
||||||
windowType ) );
|
windowType));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float[] getHighPass( int sampleRate,
|
public static float[] getHighPass(int sampleRate,
|
||||||
long stopFrequency,
|
long stopFrequency,
|
||||||
long passFrequency,
|
long passFrequency,
|
||||||
int attenuation,
|
int attenuation,
|
||||||
WindowType windowType,
|
WindowType windowType,
|
||||||
boolean forceOddLength )
|
boolean forceOddLength)
|
||||||
{
|
{
|
||||||
/* reverse the stop and pass frequency to get the low pass variant */
|
/* reverse the stop and pass frequency to get the low pass variant */
|
||||||
int tapCount = getTapCount( sampleRate,
|
int tapCount = getTapCount(sampleRate,
|
||||||
stopFrequency,
|
stopFrequency,
|
||||||
passFrequency,
|
passFrequency,
|
||||||
attenuation );
|
attenuation);
|
||||||
|
|
||||||
if( forceOddLength )
|
if(forceOddLength)
|
||||||
{
|
{
|
||||||
if( tapCount % 2 == 0 )
|
if(tapCount % 2 == 0)
|
||||||
{
|
{
|
||||||
tapCount--;
|
tapCount--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return invert( getLowPass( sampleRate, stopFrequency, tapCount, windowType ) );
|
return invert(getLowPass(sampleRate, stopFrequency, tapCount, windowType));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility to log the arrays of doubles with line breaks
|
* Utility to log the arrays of doubles with line breaks
|
||||||
*/
|
*/
|
||||||
public static String arrayToString( float[] array, boolean breaks )
|
public static String arrayToString(float[] array, boolean breaks)
|
||||||
{
|
{
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
for( int x = 0; x < array.length; x++ )
|
for(int x = 0; x < array.length; x++)
|
||||||
{
|
{
|
||||||
sb.append( x + ": " + array[ x ] );
|
sb.append(x + ": " + array[x]);
|
||||||
|
|
||||||
if( breaks )
|
if(breaks)
|
||||||
{
|
{
|
||||||
sb.append( "\n" );
|
sb.append("\n");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if( x % 8 == 7 )
|
if(x % 8 == 7)
|
||||||
{
|
{
|
||||||
sb.append( "\n" );
|
sb.append("\n");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sb.append( "\t" );
|
sb.append("\t");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -369,24 +373,24 @@ public class FilterFactory
|
|||||||
* @param attenuation in dB
|
* @param attenuation in dB
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static int getTapCount( int sampleRate,
|
public static int getTapCount(int sampleRate,
|
||||||
long pass,
|
long pass,
|
||||||
long stop,
|
long stop,
|
||||||
int attenuation )
|
int attenuation)
|
||||||
{
|
{
|
||||||
double frequency = ( (double)stop - (double)pass ) / (double)sampleRate;
|
double frequency = ((double) stop - (double) pass) / (double) sampleRate;
|
||||||
|
|
||||||
return (int)( Math.round( (double)attenuation / ( 22.0d * frequency ) ) );
|
return (int) (Math.round((double) attenuation / (22.0d * frequency)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ComplexPrimeCICDecimate getDecimationFilter( int sampleRate,
|
public static ComplexPrimeCICDecimate getDecimationFilter(int sampleRate,
|
||||||
int decimatedRate, int order, int passFrequency, int attenuation,
|
int decimatedRate, int order, int passFrequency, int attenuation,
|
||||||
WindowType windowType )
|
WindowType windowType)
|
||||||
{
|
{
|
||||||
int decimationRate = (int)( sampleRate / decimatedRate );
|
int decimationRate = (int) (sampleRate / decimatedRate);
|
||||||
|
|
||||||
return new ComplexPrimeCICDecimate( decimationRate, order,
|
return new ComplexPrimeCICDecimate(decimationRate, order,
|
||||||
passFrequency, attenuation, windowType );
|
passFrequency, attenuation, windowType);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -398,63 +402,63 @@ public class FilterFactory
|
|||||||
* polyphase filter decimation chain
|
* polyphase filter decimation chain
|
||||||
* @throws - AssertionException if sample rate is not a multiple of 48 kHz
|
* @throws - AssertionException if sample rate is not a multiple of 48 kHz
|
||||||
*/
|
*/
|
||||||
public static int[] getPolyphaseDecimationRates( int sampleRate,
|
public static int[] getPolyphaseDecimationRates(int sampleRate,
|
||||||
int decimatedRate,
|
int decimatedRate,
|
||||||
long passFrequency,
|
long passFrequency,
|
||||||
long stopFrequency )
|
long stopFrequency)
|
||||||
{
|
{
|
||||||
int[] rates;
|
int[] rates;
|
||||||
|
|
||||||
if( sampleRate % decimatedRate != 0 )
|
if(sampleRate % decimatedRate != 0)
|
||||||
{
|
{
|
||||||
throw new IllegalArgumentException( "Decimated rate must be an "
|
throw new IllegalArgumentException("Decimated rate must be an "
|
||||||
+ "integer multiple of sample rate" );
|
+ "integer multiple of sample rate");
|
||||||
}
|
}
|
||||||
|
|
||||||
int decimation = (int)( sampleRate / decimatedRate );
|
int decimation = (int) (sampleRate / decimatedRate);
|
||||||
|
|
||||||
//Decimation rates below 20 will use single stage polyphase filter
|
//Decimation rates below 20 will use single stage polyphase filter
|
||||||
if( decimation < 20 )
|
if(decimation < 20)
|
||||||
{
|
{
|
||||||
rates = new int[ 1 ];
|
rates = new int[1];
|
||||||
rates[ 0 ] = decimation;
|
rates[0] = decimation;
|
||||||
return rates;
|
return rates;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int optimalStage1 =
|
int optimalStage1 =
|
||||||
getOptimalStageOneRate( sampleRate, decimation, passFrequency, stopFrequency );
|
getOptimalStageOneRate(sampleRate, decimation, passFrequency, stopFrequency);
|
||||||
|
|
||||||
Set<Integer> factors = getFactors( decimation );
|
Set<Integer> factors = getFactors(decimation);
|
||||||
|
|
||||||
int stage1 = findClosest( optimalStage1, factors );
|
int stage1 = findClosest(optimalStage1, factors);
|
||||||
|
|
||||||
// mLog.info( "Decimation rate [" + decimation +
|
// mLog.info( "Decimation rate [" + decimation +
|
||||||
// "] stage1 optimal [" + optimalStage1 +
|
// "] stage1 optimal [" + optimalStage1 +
|
||||||
// "] stage1 actual [" + stage1 +
|
// "] stage1 actual [" + stage1 +
|
||||||
// "]");
|
// "]");
|
||||||
|
|
||||||
if( stage1 == decimation || stage1 == 1 )
|
if(stage1 == decimation || stage1 == 1)
|
||||||
{
|
{
|
||||||
rates = new int[ 1 ];
|
rates = new int[1];
|
||||||
rates[ 0 ] = decimation;
|
rates[0] = decimation;
|
||||||
return rates;
|
return rates;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rates = new int[ 2 ];
|
rates = new int[2];
|
||||||
|
|
||||||
int stage2 = (int)( decimation / stage1);
|
int stage2 = (int) (decimation / stage1);
|
||||||
|
|
||||||
if( stage1 > stage2 )
|
if(stage1 > stage2)
|
||||||
{
|
{
|
||||||
rates[ 0 ] = stage1;
|
rates[0] = stage1;
|
||||||
rates[ 1 ] = stage2;
|
rates[1] = stage2;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rates[ 0 ] = stage2;
|
rates[0] = stage2;
|
||||||
rates[ 1 ] = stage1;
|
rates[1] = stage1;
|
||||||
}
|
}
|
||||||
return rates;
|
return rates;
|
||||||
}
|
}
|
||||||
@@ -465,16 +469,16 @@ public class FilterFactory
|
|||||||
* Finds the factor that is closest to the desired factor, from an ordered
|
* Finds the factor that is closest to the desired factor, from an ordered
|
||||||
* list of factors.
|
* list of factors.
|
||||||
*/
|
*/
|
||||||
private static int findClosest( int desiredFactor, Set<Integer> factors )
|
private static int findClosest(int desiredFactor, Set<Integer> factors)
|
||||||
{
|
{
|
||||||
int bestFactor = 1;
|
int bestFactor = 1;
|
||||||
int bestDelta = desiredFactor;
|
int bestDelta = desiredFactor;
|
||||||
|
|
||||||
for( Integer factor: factors )
|
for(Integer factor : factors)
|
||||||
{
|
{
|
||||||
int testDelta = Math.abs( desiredFactor - factor );
|
int testDelta = Math.abs(desiredFactor - factor);
|
||||||
|
|
||||||
if( testDelta < bestDelta )
|
if(testDelta < bestDelta)
|
||||||
{
|
{
|
||||||
bestDelta = testDelta;
|
bestDelta = testDelta;
|
||||||
bestFactor = factor;
|
bestFactor = factor;
|
||||||
@@ -492,18 +496,18 @@ public class FilterFactory
|
|||||||
* @param value - integer decimation value
|
* @param value - integer decimation value
|
||||||
* @return - ordered set of factors for value
|
* @return - ordered set of factors for value
|
||||||
*/
|
*/
|
||||||
private static Set<Integer> getFactors( int value )
|
private static Set<Integer> getFactors(int value)
|
||||||
{
|
{
|
||||||
Set<Integer> factors = new TreeSet<Integer>();
|
Set<Integer> factors = new TreeSet<Integer>();
|
||||||
|
|
||||||
/* Brute force */
|
/* Brute force */
|
||||||
for( int x = 1; x <= value; x++ )
|
for(int x = 1; x <= value; x++)
|
||||||
{
|
{
|
||||||
int remainder = (int)( value / x );
|
int remainder = (int) (value / x);
|
||||||
|
|
||||||
if( remainder * x == value )
|
if(remainder * x == value)
|
||||||
{
|
{
|
||||||
factors.add( x );
|
factors.add(x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -526,19 +530,19 @@ public class FilterFactory
|
|||||||
* @return optimum integer decimation rate for the first stage decimation
|
* @return optimum integer decimation rate for the first stage decimation
|
||||||
* filter
|
* filter
|
||||||
*/
|
*/
|
||||||
public static int getOptimalStageOneRate( int sampleRate,
|
public static int getOptimalStageOneRate(int sampleRate,
|
||||||
int decimation,
|
int decimation,
|
||||||
long passFrequency,
|
long passFrequency,
|
||||||
long stopFrequency )
|
long stopFrequency)
|
||||||
{
|
{
|
||||||
double ratio = getBandwidthRatio( passFrequency, stopFrequency );
|
double ratio = getBandwidthRatio(passFrequency, stopFrequency);
|
||||||
|
|
||||||
double numerator = 1.0d - (
|
double numerator = 1.0d - (
|
||||||
Math.sqrt( (double)decimation * ratio / ( 2.0d - ratio ) ) );
|
Math.sqrt((double) decimation * ratio / (2.0d - ratio)));
|
||||||
|
|
||||||
double denominator = 2.0d - ( ratio * ( decimation + 1.0d ) );
|
double denominator = 2.0d - (ratio * (decimation + 1.0d));
|
||||||
|
|
||||||
int retVal = (int)( 2.0d * decimation * ( numerator / denominator ) );
|
int retVal = (int) (2.0d * decimation * (numerator / denominator));
|
||||||
|
|
||||||
// mLog.info( "Optimal Stage 1 Decimation - rate [" + sampleRate +
|
// mLog.info( "Optimal Stage 1 Decimation - rate [" + sampleRate +
|
||||||
// "] pass [" + passFrequency +
|
// "] pass [" + passFrequency +
|
||||||
@@ -556,90 +560,90 @@ public class FilterFactory
|
|||||||
* Used in conjunction with the optimal stage one decimation rate method
|
* Used in conjunction with the optimal stage one decimation rate method
|
||||||
* above.
|
* above.
|
||||||
*/
|
*/
|
||||||
private static double getBandwidthRatio( long passFrequency, long stopFrequency )
|
private static double getBandwidthRatio(long passFrequency, long stopFrequency)
|
||||||
{
|
{
|
||||||
assert( passFrequency < stopFrequency );
|
assert (passFrequency < stopFrequency);
|
||||||
|
|
||||||
return ( (double)( stopFrequency - passFrequency ) /
|
return ((double) (stopFrequency - passFrequency) /
|
||||||
(double)stopFrequency );
|
(double) stopFrequency);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assumes that the pass band is 1/4 of the output sample rate.
|
* Assumes that the pass band is 1/4 of the output sample rate.
|
||||||
*
|
*
|
||||||
* Assumes the stop band is: pass + (pass * .25).
|
* Assumes the stop band is: pass + (pass * .25).
|
||||||
|
*
|
||||||
* @param outputSampleRate
|
* @param outputSampleRate
|
||||||
* @param stageCount
|
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static float[] getCICCleanupFilter( int outputSampleRate,
|
public static float[] getCICCleanupFilter(int outputSampleRate,
|
||||||
int passFrequency,
|
int passFrequency,
|
||||||
int attenuation,
|
int attenuation,
|
||||||
WindowType window )
|
WindowType window)
|
||||||
{
|
{
|
||||||
int taps = getTapCount( outputSampleRate, passFrequency, passFrequency + 1500,
|
int taps = getTapCount(outputSampleRate, passFrequency, passFrequency + 1500,
|
||||||
attenuation );
|
attenuation);
|
||||||
|
|
||||||
/* Make tap count odd */
|
/* Make tap count odd */
|
||||||
if( taps% 2 == 0 )
|
if(taps % 2 == 0)
|
||||||
{
|
{
|
||||||
taps ++;
|
taps++;
|
||||||
}
|
}
|
||||||
|
|
||||||
float[] frequencyResponse =
|
float[] frequencyResponse =
|
||||||
getCICResponseArray( outputSampleRate, passFrequency, taps );
|
getCICResponseArray(outputSampleRate, passFrequency, taps);
|
||||||
|
|
||||||
//Apply Inverse DFT against frequency response unity values, leaving the
|
//Apply Inverse DFT against frequency response unity values, leaving the
|
||||||
//IDFT bin results in the frequency response array
|
//IDFT bin results in the frequency response array
|
||||||
FloatFFT_1D idft = new FloatFFT_1D( taps );
|
FloatFFT_1D idft = new FloatFFT_1D(taps);
|
||||||
idft.realInverseFull( frequencyResponse, false );
|
idft.realInverseFull(frequencyResponse, false);
|
||||||
|
|
||||||
//Transfer the IDFT results to the odd length return array
|
//Transfer the IDFT results to the odd length return array
|
||||||
float[] coefficients = new float[ taps ];
|
float[] coefficients = new float[taps];
|
||||||
int middleCoefficient = (int)( taps / 2 );
|
int middleCoefficient = (int) (taps / 2);
|
||||||
|
|
||||||
//Bin 0 of the idft is our center coefficient
|
//Bin 0 of the idft is our center coefficient
|
||||||
coefficients[ middleCoefficient ] = frequencyResponse[ 0 ];
|
coefficients[middleCoefficient] = frequencyResponse[0];
|
||||||
|
|
||||||
//The remaining idft bins from 1 to (middle - 1) are the mirror image
|
//The remaining idft bins from 1 to (middle - 1) are the mirror image
|
||||||
//coefficients
|
//coefficients
|
||||||
for( int x = 1; x <= middleCoefficient; x++ )
|
for(int x = 1; x <= middleCoefficient; x++)
|
||||||
{
|
{
|
||||||
coefficients[ middleCoefficient + x ] = frequencyResponse[ 2 * x ];
|
coefficients[middleCoefficient + x] = frequencyResponse[2 * x];
|
||||||
coefficients[ middleCoefficient - x ] = frequencyResponse[ 2 * x ];
|
coefficients[middleCoefficient - x] = frequencyResponse[2 * x];
|
||||||
}
|
}
|
||||||
|
|
||||||
//Apply the window against the coefficients
|
//Apply the window against the coefficients
|
||||||
// coefficients = Window.apply( window, coefficients );
|
// coefficients = Window.apply( window, coefficients );
|
||||||
|
|
||||||
normalize( coefficients );
|
normalize(coefficients);
|
||||||
|
|
||||||
return coefficients;
|
return coefficients;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float[] getCICResponseArray( int sampleRate,
|
public static float[] getCICResponseArray(int sampleRate,
|
||||||
int frequency,
|
int frequency,
|
||||||
int length )
|
int length)
|
||||||
{
|
{
|
||||||
float[] cicArray = new float[ length * 2 ];
|
float[] cicArray = new float[length * 2];
|
||||||
|
|
||||||
int binCount = (int)( ( Math.round(
|
int binCount = (int) ((Math.round(
|
||||||
(double)frequency / (double)sampleRate * 2.0d * (double)length ) ) );
|
(double) frequency / (double) sampleRate * 2.0d * (double) length)));
|
||||||
|
|
||||||
cicArray[ 0 ] = 1.0f;
|
cicArray[0] = 1.0f;
|
||||||
|
|
||||||
float unityResponse = (float)( Math.sin( 1.0d / (double)length ) /
|
float unityResponse = (float) (Math.sin(1.0d / (double) length) /
|
||||||
( 1.0d / (double)length ) );
|
(1.0d / (double) length));
|
||||||
|
|
||||||
for( int x = 1; x <= binCount; x++ )
|
for(int x = 1; x <= binCount; x++)
|
||||||
{
|
{
|
||||||
/* Calculate unity response plus amplification for droop */
|
/* Calculate unity response plus amplification for droop */
|
||||||
float compensated = 1.0f + ( unityResponse -
|
float compensated = 1.0f + (unityResponse -
|
||||||
(float)( Math.sin( (double)x / (double)length ) /
|
(float) (Math.sin((double) x / (double) length) /
|
||||||
( (double)x / (double)length ) ) );
|
((double) x / (double) length)));
|
||||||
|
|
||||||
cicArray[ x ] = compensated;
|
cicArray[x] = compensated;
|
||||||
cicArray[ length - x ] = compensated;
|
cicArray[length - x] = compensated;
|
||||||
}
|
}
|
||||||
|
|
||||||
return cicArray;
|
return cicArray;
|
||||||
@@ -661,79 +665,97 @@ public class FilterFactory
|
|||||||
* @param samplesPerSymbol - number of samples per symbol
|
* @param samplesPerSymbol - number of samples per symbol
|
||||||
* @param symbols - number of symbols - must be even
|
* @param symbols - number of symbols - must be even
|
||||||
* @param alpha - roll-off factor
|
* @param alpha - roll-off factor
|
||||||
*
|
|
||||||
* @return - filter coefficients
|
* @return - filter coefficients
|
||||||
*/
|
*/
|
||||||
public static float[] getRootRaisedCosine( int samplesPerSymbol,
|
public static float[] getRootRaisedCosine(int samplesPerSymbol,
|
||||||
int symbols,
|
int symbols,
|
||||||
float alpha )
|
float alpha)
|
||||||
{
|
{
|
||||||
int taps = samplesPerSymbol * symbols + 1;
|
int taps = samplesPerSymbol * symbols + 1;
|
||||||
|
|
||||||
float scale = 0;
|
float scale = 0;
|
||||||
|
|
||||||
float[] coefficients = new float[ taps ];
|
float[] coefficients = new float[taps];
|
||||||
|
|
||||||
for( int x = 0; x < taps; x++ )
|
for(int x = 0; x < taps; x++)
|
||||||
{
|
{
|
||||||
float index = (float)x - ( (float)taps / 2.0f );
|
float index = (float) x - ((float) taps / 2.0f);
|
||||||
|
|
||||||
float x1 = (float)Math.PI * index / (float)samplesPerSymbol;
|
float x1 = (float) Math.PI * index / (float) samplesPerSymbol;
|
||||||
float x2 = 4.0f * alpha * index / (float)samplesPerSymbol;
|
float x2 = 4.0f * alpha * index / (float) samplesPerSymbol;
|
||||||
float x3 = x2 * x2 - 1.0f;
|
float x3 = x2 * x2 - 1.0f;
|
||||||
|
|
||||||
float numerator, denominator;
|
float numerator, denominator;
|
||||||
|
|
||||||
if( Math.abs( x3 ) >= 0.000001 )
|
if(Math.abs(x3) >= 0.000001)
|
||||||
{
|
{
|
||||||
if( x != taps / 2 )
|
if(x != taps / 2)
|
||||||
{
|
{
|
||||||
numerator = (float)Math.cos( ( 1.0 + alpha ) * x1 ) +
|
numerator = (float) Math.cos((1.0 + alpha) * x1) +
|
||||||
(float)Math.sin( ( 1.0f - alpha ) * x1 ) /
|
(float) Math.sin((1.0f - alpha) * x1) /
|
||||||
( 4.0f * alpha * index / (float)samplesPerSymbol );
|
(4.0f * alpha * index / (float) samplesPerSymbol);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
numerator = (float)Math.cos( ( 1.0f + alpha ) * x1 ) +
|
numerator = (float) Math.cos((1.0f + alpha) * x1) +
|
||||||
( 1.0f - alpha ) * (float)Math.PI / ( 4.0f * alpha );
|
(1.0f - alpha) * (float) Math.PI / (4.0f * alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
denominator = x3 * (float)Math.PI;
|
denominator = x3 * (float) Math.PI;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if( alpha == 1.0f )
|
if(alpha == 1.0f)
|
||||||
{
|
{
|
||||||
coefficients[ x ] = -1.0f;
|
coefficients[x] = -1.0f;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
x3 = ( 1.0f - alpha ) * x1;
|
x3 = (1.0f - alpha) * x1;
|
||||||
x2 = ( 1.0f + alpha ) * x1;
|
x2 = (1.0f + alpha) * x1;
|
||||||
|
|
||||||
numerator = (float)( Math.sin( x2 ) * ( 1.0f + alpha ) * Math.PI -
|
numerator = (float) (Math.sin(x2) * (1.0f + alpha) * Math.PI -
|
||||||
Math.cos( x3 ) * ( ( 1.0 - alpha ) * Math.PI *
|
Math.cos(x3) * ((1.0 - alpha) * Math.PI *
|
||||||
(double)samplesPerSymbol ) / ( 4 * alpha * index ) +
|
(double) samplesPerSymbol) / (4 * alpha * index) +
|
||||||
Math.sin( x3 ) * (double)samplesPerSymbol *
|
Math.sin(x3) * (double) samplesPerSymbol *
|
||||||
(double)samplesPerSymbol / ( 4.0 * alpha * index * index ) );
|
(double) samplesPerSymbol / (4.0 * alpha * index * index));
|
||||||
|
|
||||||
denominator = (float)( -32.0 * Math.PI * alpha * alpha * index /
|
denominator = (float) (-32.0 * Math.PI * alpha * alpha * index /
|
||||||
(double)samplesPerSymbol );
|
(double) samplesPerSymbol);
|
||||||
}
|
}
|
||||||
|
|
||||||
coefficients[ x ] = 4.0f * alpha * numerator / denominator;
|
coefficients[x] = 4.0f * alpha * numerator / denominator;
|
||||||
|
|
||||||
scale += coefficients[ x ];
|
scale += coefficients[x];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Normalize (scale) coefficients to 1.0 sum and apply gain
|
* Normalize (scale) coefficients to 1.0 sum and apply gain
|
||||||
*/
|
*/
|
||||||
for( int x = 0; x < taps; x++ )
|
for(int x = 0; x < taps; x++)
|
||||||
{
|
{
|
||||||
coefficients[ x ] = coefficients[ x ] / scale;
|
coefficients[x] = coefficients[x] / scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
return coefficients;
|
return coefficients;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a filter from the filter specification
|
||||||
|
*
|
||||||
|
* @param specification
|
||||||
|
* @return
|
||||||
|
* @throws FilterDesignException if the filter cannot be designed
|
||||||
|
*/
|
||||||
|
public static float[] getTaps(FIRFilterSpecification specification) throws FilterDesignException
|
||||||
|
{
|
||||||
|
RemezFIRFilterDesigner designer = new RemezFIRFilterDesigner(specification);
|
||||||
|
|
||||||
|
if(designer.isValid())
|
||||||
|
{
|
||||||
|
return designer.getImpulseResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,26 +51,26 @@ public class FilterViewer extends Application
|
|||||||
// .stopBandRipple( 0.027 )
|
// .stopBandRipple( 0.027 )
|
||||||
// .build();
|
// .build();
|
||||||
|
|
||||||
FIRFilterSpecification specification = FIRFilterSpecification.highPassBuilder()
|
// FIRFilterSpecification specification = FIRFilterSpecification.highPassBuilder()
|
||||||
.sampleRate( 8000 )
|
// .sampleRate( 8000 )
|
||||||
.stopBandCutoff( 250 )
|
// .stopBandCutoff( 250 )
|
||||||
.stopBandAmplitude( 0.0 )
|
// .stopBandAmplitude( 0.0 )
|
||||||
.stopBandRipple( 0.01 )
|
// .stopBandRipple( 0.01 )
|
||||||
.passBandStart( 300 )
|
// .passBandStart( 300 )
|
||||||
.passBandAmplitude( 1.0 )
|
// .passBandAmplitude( 1.0 )
|
||||||
.passBandRipple( 0.01 )
|
// .passBandRipple( 0.01 )
|
||||||
.build();
|
|
||||||
|
|
||||||
// FIRFilterSpecification specification = FIRFilterSpecification.bandPassBuilder()
|
|
||||||
// .sampleRate( 48000 )
|
|
||||||
// .stopFrequency1( 150 )
|
|
||||||
// .passFrequencyBegin( 200 )
|
|
||||||
// .passFrequencyEnd( 3950 )
|
|
||||||
// .stopFrequency2( 4000 )
|
|
||||||
// .stopRipple( 0.0005 )
|
|
||||||
// .passRipple( 0.003)
|
|
||||||
// .build();
|
// .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;
|
float[] taps = null;
|
||||||
|
|
||||||
// taps = FilterFactory.getLowPass( 16000, 2400, 73, WindowType.HANNING );
|
// taps = FilterFactory.getLowPass( 16000, 2400, 73, WindowType.HANNING );
|
||||||
|
|||||||
@@ -17,21 +17,22 @@
|
|||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package dsp.fsk;
|
package dsp.fsk;
|
||||||
|
|
||||||
|
import buffer.BooleanAveragingBuffer;
|
||||||
|
import dsp.symbol.SymbolEvent;
|
||||||
|
import dsp.symbol.SymbolEvent.Shift;
|
||||||
import instrument.Instrumentable;
|
import instrument.Instrumentable;
|
||||||
import instrument.tap.Tap;
|
import instrument.tap.Tap;
|
||||||
import instrument.tap.TapGroup;
|
import instrument.tap.TapGroup;
|
||||||
import instrument.tap.stream.SymbolEventTap;
|
import instrument.tap.stream.SymbolEventTap;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import sample.Listener;
|
||||||
|
import sample.real.RealBuffer;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.BitSet;
|
import java.util.BitSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import sample.Listener;
|
|
||||||
import sample.real.RealBuffer;
|
|
||||||
import buffer.BooleanAveragingBuffer;
|
|
||||||
import dsp.symbol.SymbolEvent;
|
|
||||||
import dsp.symbol.SymbolEvent.Shift;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Binary Frequency Shift Keying (FSK) decoder. Implements a BFSK correlation
|
* Binary Frequency Shift Keying (FSK) decoder. Implements a BFSK correlation
|
||||||
* decoder. Provides normal or inverted decoded output. Requires the symbol
|
* decoder. Provides normal or inverted decoded output. Requires the symbol
|
||||||
@@ -54,7 +55,12 @@ import dsp.symbol.SymbolEvent.Shift;
|
|||||||
*/
|
*/
|
||||||
public class FSK2Decoder implements Instrumentable, Listener<RealBuffer>
|
public class FSK2Decoder implements Instrumentable, Listener<RealBuffer>
|
||||||
{
|
{
|
||||||
public enum Output{ NORMAL, INVERTED };
|
private final static Logger mLog = LoggerFactory.getLogger(FSK2Decoder.class);
|
||||||
|
|
||||||
|
public enum Output
|
||||||
|
{
|
||||||
|
NORMAL, INVERTED
|
||||||
|
}
|
||||||
|
|
||||||
/* Instrumentation taps */
|
/* Instrumentation taps */
|
||||||
private static final String INSTRUMENT_DECISION =
|
private static final String INSTRUMENT_DECISION =
|
||||||
@@ -70,18 +76,18 @@ public class FSK2Decoder implements Instrumentable, Listener<RealBuffer>
|
|||||||
private int mSamplesPerSymbol;
|
private int mSamplesPerSymbol;
|
||||||
private int mSymbolRate;
|
private int mSymbolRate;
|
||||||
|
|
||||||
public FSK2Decoder( int sampleRate, int symbolRate, Output output )
|
public FSK2Decoder(int sampleRate, int symbolRate, Output output)
|
||||||
{
|
{
|
||||||
/* Ensure we're using an integral symbolRate of the sampleRate */
|
/* Ensure we're using an integral symbolRate of the sampleRate */
|
||||||
assert( sampleRate % symbolRate == 0 );
|
assert (sampleRate % symbolRate == 0);
|
||||||
|
|
||||||
mSamplesPerSymbol = (int)( sampleRate / symbolRate );
|
mSamplesPerSymbol = (int) (sampleRate / symbolRate);
|
||||||
mNormalOutput = ( output == Output.NORMAL );
|
mNormalOutput = (output == Output.NORMAL);
|
||||||
mSymbolRate = symbolRate;
|
mSymbolRate = symbolRate;
|
||||||
|
|
||||||
mDelayBuffer = new BooleanAveragingBuffer( mSamplesPerSymbol );
|
mDelayBuffer = new BooleanAveragingBuffer(mSamplesPerSymbol);
|
||||||
mLowPassFilter = new BooleanAveragingBuffer( mSamplesPerSymbol );
|
mLowPassFilter = new BooleanAveragingBuffer(mSamplesPerSymbol);
|
||||||
mSlicer = new Slicer( mSamplesPerSymbol );
|
mSlicer = new Slicer(mSamplesPerSymbol);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -96,32 +102,32 @@ public class FSK2Decoder implements Instrumentable, Listener<RealBuffer>
|
|||||||
* Primary sample input
|
* Primary sample input
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void receive( RealBuffer buffer )
|
public void receive(RealBuffer buffer)
|
||||||
{
|
{
|
||||||
for( float sample: buffer.getSamples() )
|
for(float sample : buffer.getSamples())
|
||||||
{
|
{
|
||||||
/* Square the sample. Greater than zero is a 1 (true) and less than
|
/* Square the sample. Greater than zero is a 1 (true) and less than
|
||||||
* zero is a 0 (false) */
|
* zero is a 0 (false) */
|
||||||
boolean bitSample = ( sample >= 0.0f );
|
boolean bitSample = (sample >= 0.0f);
|
||||||
|
|
||||||
/* Feed the delay buffer and fetch the one-baud delayed sample */
|
/* Feed the delay buffer and fetch the one-baud delayed sample */
|
||||||
boolean delayedBitSample = mDelayBuffer.get( bitSample );
|
boolean delayedBitSample = mDelayBuffer.get(bitSample);
|
||||||
|
|
||||||
/* Correlation: xor current bit with delayed bit */
|
/* Correlation: xor current bit with delayed bit */
|
||||||
boolean softBit = bitSample ^ delayedBitSample;
|
boolean softBit = bitSample ^ delayedBitSample;
|
||||||
|
|
||||||
/* Low pass filter to smooth the correlated values */
|
/* Low pass filter to smooth the correlated values */
|
||||||
boolean filteredSoftBit = mLowPassFilter.getAverage( softBit );
|
boolean filteredSoftBit = mLowPassFilter.getAverage(softBit);
|
||||||
|
|
||||||
/* Send the filtered correlated bit to the slicer */
|
/* Send the filtered correlated bit to the slicer */
|
||||||
mSlicer.receive( filteredSoftBit );
|
mSlicer.receive(filteredSoftBit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a listener to receive the decoded FSK bits
|
* Registers a listener to receive the decoded FSK bits
|
||||||
*/
|
*/
|
||||||
public void setListener( Listener<Boolean> listener )
|
public void setListener(Listener<Boolean> listener)
|
||||||
{
|
{
|
||||||
mListener = listener;
|
mListener = listener;
|
||||||
}
|
}
|
||||||
@@ -129,7 +135,7 @@ public class FSK2Decoder implements Instrumentable, Listener<RealBuffer>
|
|||||||
/**
|
/**
|
||||||
* Removes the listener
|
* Removes the listener
|
||||||
*/
|
*/
|
||||||
public void removeListener( Listener<Boolean> listener )
|
public void removeListener(Listener<Boolean> listener)
|
||||||
{
|
{
|
||||||
mListener = null;
|
mListener = null;
|
||||||
}
|
}
|
||||||
@@ -144,47 +150,47 @@ public class FSK2Decoder implements Instrumentable, Listener<RealBuffer>
|
|||||||
private int mDecisionThreshold;
|
private int mDecisionThreshold;
|
||||||
private int mSampleCounter;
|
private int mSampleCounter;
|
||||||
|
|
||||||
public Slicer( int samplesPerSymbol )
|
public Slicer(int samplesPerSymbol)
|
||||||
{
|
{
|
||||||
mSymbolLength = samplesPerSymbol;
|
mSymbolLength = samplesPerSymbol;
|
||||||
|
|
||||||
mDecisionThreshold = (int)( mSymbolLength / 2 );
|
mDecisionThreshold = (int) (mSymbolLength / 2);
|
||||||
|
|
||||||
/* Adjust for an odd number of samples per baud */
|
/* Adjust for an odd number of samples per baud */
|
||||||
if( mSymbolLength % 2 == 1 )
|
if(mSymbolLength % 2 == 1)
|
||||||
{
|
{
|
||||||
mDecisionThreshold++;
|
mDecisionThreshold++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void receive( boolean softBit )
|
public void receive(boolean softBit)
|
||||||
{
|
{
|
||||||
if( mSampleCounter >= 0 )
|
if(mSampleCounter >= 0)
|
||||||
{
|
{
|
||||||
if( softBit )
|
if(softBit)
|
||||||
{
|
{
|
||||||
mBitSet.set( mSampleCounter );
|
mBitSet.set(mSampleCounter);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mBitSet.clear( mSampleCounter );
|
mBitSet.clear(mSampleCounter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mSampleCounter++;
|
mSampleCounter++;
|
||||||
|
|
||||||
if( mSampleCounter >= mSymbolLength )
|
if(mSampleCounter >= mSymbolLength)
|
||||||
{
|
{
|
||||||
boolean decision = mBitSet.cardinality() >= mDecisionThreshold;
|
boolean decision = mBitSet.cardinality() >= mDecisionThreshold;
|
||||||
|
|
||||||
send( decision );
|
send(decision);
|
||||||
|
|
||||||
/* Shift timing left if the left bit in the bitset is opposite
|
/* Shift timing left if the left bit in the bitset is opposite
|
||||||
* the decision and the right bit is the same */
|
* the decision and the right bit is the same */
|
||||||
if( ( mBitSet.get( 0 ) ^ decision ) &&
|
if((mBitSet.get(0) ^ decision) &&
|
||||||
( !( mBitSet.get( mSymbolLength - 1 ) ^ decision ) ) )
|
(!(mBitSet.get(mSymbolLength - 1) ^ decision)))
|
||||||
{
|
{
|
||||||
sendTapEvent( mBitSet, Shift.LEFT, decision );
|
sendTapEvent(mBitSet, Shift.LEFT, decision);
|
||||||
|
|
||||||
reset();
|
reset();
|
||||||
|
|
||||||
@@ -192,19 +198,19 @@ public class FSK2Decoder implements Instrumentable, Listener<RealBuffer>
|
|||||||
}
|
}
|
||||||
/* Shift timing right if the left bit is the same as the
|
/* Shift timing right if the left bit is the same as the
|
||||||
* decision and the right bit is opposite */
|
* decision and the right bit is opposite */
|
||||||
else if( ( !( mBitSet.get( 0 ) ^ decision ) ) &&
|
else if((!(mBitSet.get(0) ^ decision)) &&
|
||||||
( mBitSet.get( mSymbolLength - 1 ) ^ decision ) )
|
(mBitSet.get(mSymbolLength - 1) ^ decision))
|
||||||
{
|
{
|
||||||
sendTapEvent( mBitSet, Shift.RIGHT, decision );
|
sendTapEvent(mBitSet, Shift.RIGHT, decision);
|
||||||
|
|
||||||
/* Last bit from previous symbol to pre-fill next symbol */
|
/* Last bit from previous symbol to pre-fill next symbol */
|
||||||
boolean previousSoftBit = mBitSet.get( mSymbolLength - 1 );
|
boolean previousSoftBit = mBitSet.get(mSymbolLength - 1);
|
||||||
|
|
||||||
reset();
|
reset();
|
||||||
|
|
||||||
if( previousSoftBit )
|
if(previousSoftBit)
|
||||||
{
|
{
|
||||||
mBitSet.set( 0 );
|
mBitSet.set(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
mSampleCounter++;
|
mSampleCounter++;
|
||||||
@@ -212,7 +218,7 @@ public class FSK2Decoder implements Instrumentable, Listener<RealBuffer>
|
|||||||
/* No shift */
|
/* No shift */
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sendTapEvent( mBitSet, Shift.NONE, decision );
|
sendTapEvent(mBitSet, Shift.NONE, decision);
|
||||||
|
|
||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
@@ -222,11 +228,11 @@ public class FSK2Decoder implements Instrumentable, Listener<RealBuffer>
|
|||||||
/**
|
/**
|
||||||
* Sends the bit decision to the listener
|
* Sends the bit decision to the listener
|
||||||
*/
|
*/
|
||||||
private void send( boolean decision )
|
private void send(boolean decision)
|
||||||
{
|
{
|
||||||
if( mListener != null )
|
if(mListener != null)
|
||||||
{
|
{
|
||||||
mListener.receive( mNormalOutput ? decision : !decision );
|
mListener.receive(mNormalOutput ? decision : !decision);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -239,17 +245,17 @@ public class FSK2Decoder implements Instrumentable, Listener<RealBuffer>
|
|||||||
/**
|
/**
|
||||||
* Sends instrumentation tap event to all registered listeners
|
* Sends instrumentation tap event to all registered listeners
|
||||||
*/
|
*/
|
||||||
private void sendTapEvent( BitSet bitset, Shift shift, boolean decision )
|
private void sendTapEvent(BitSet bitset, Shift shift, boolean decision)
|
||||||
{
|
{
|
||||||
for( SymbolEventTap tap: mTaps )
|
for(SymbolEventTap tap : mTaps)
|
||||||
{
|
{
|
||||||
SymbolEvent event =
|
SymbolEvent event =
|
||||||
new SymbolEvent( bitset.get( 0, mSymbolLength ),
|
new SymbolEvent(bitset.get(0, mSymbolLength),
|
||||||
mSymbolLength,
|
mSymbolLength,
|
||||||
decision,
|
decision,
|
||||||
shift );
|
shift);
|
||||||
|
|
||||||
tap.receive( event );
|
tap.receive(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -260,14 +266,14 @@ public class FSK2Decoder implements Instrumentable, Listener<RealBuffer>
|
|||||||
@Override
|
@Override
|
||||||
public List<TapGroup> getTapGroups()
|
public List<TapGroup> getTapGroups()
|
||||||
{
|
{
|
||||||
if( mAvailableTaps == null )
|
if(mAvailableTaps == null)
|
||||||
{
|
{
|
||||||
mAvailableTaps = new ArrayList<TapGroup>();
|
mAvailableTaps = new ArrayList<TapGroup>();
|
||||||
|
|
||||||
TapGroup tapGroup = new TapGroup( "FSK2 Decoder" );
|
TapGroup tapGroup = new TapGroup("FSK2 Decoder");
|
||||||
tapGroup.add( new SymbolEventTap( INSTRUMENT_DECISION, 0, .025f ) );
|
tapGroup.add(new SymbolEventTap(INSTRUMENT_DECISION, 0, .025f));
|
||||||
|
|
||||||
mAvailableTaps.add( tapGroup );
|
mAvailableTaps.add(tapGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
return mAvailableTaps;
|
return mAvailableTaps;
|
||||||
@@ -277,11 +283,11 @@ public class FSK2Decoder implements Instrumentable, Listener<RealBuffer>
|
|||||||
* Add instrumentation tap
|
* Add instrumentation tap
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void registerTap( Tap tap )
|
public void registerTap(Tap tap)
|
||||||
{
|
{
|
||||||
if( tap instanceof SymbolEventTap && !mTaps.contains( tap ) )
|
if(tap instanceof SymbolEventTap && !mTaps.contains(tap))
|
||||||
{
|
{
|
||||||
mTaps.add( (SymbolEventTap)tap );
|
mTaps.add((SymbolEventTap) tap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -289,8 +295,8 @@ public class FSK2Decoder implements Instrumentable, Listener<RealBuffer>
|
|||||||
* Remove instrumentation tap
|
* Remove instrumentation tap
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void unregisterTap( Tap tap )
|
public void unregisterTap(Tap tap)
|
||||||
{
|
{
|
||||||
mTaps.remove( tap );
|
mTaps.remove(tap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -386,7 +386,7 @@ public class SDRTrunk implements Listener<TunerEvent>
|
|||||||
if(mBroadcastStatusPanel == null)
|
if(mBroadcastStatusPanel == null)
|
||||||
{
|
{
|
||||||
mBroadcastStatusPanel = new BroadcastStatusPanel(mBroadcastModel);
|
mBroadcastStatusPanel = new BroadcastStatusPanel(mBroadcastModel);
|
||||||
mBroadcastStatusPanel.setPreferredSize(new Dimension(880, 100));
|
mBroadcastStatusPanel.setPreferredSize(new Dimension(880, 70));
|
||||||
mBroadcastStatusPanel.getTable().setEnabled(false);
|
mBroadcastStatusPanel.getTable().setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ import controller.channel.ChannelModel;
|
|||||||
import controller.channel.ChannelProcessingManager;
|
import controller.channel.ChannelProcessingManager;
|
||||||
import controller.channel.map.ChannelMap;
|
import controller.channel.map.ChannelMap;
|
||||||
import controller.channel.map.ChannelMapModel;
|
import controller.channel.map.ChannelMapModel;
|
||||||
|
import dsp.filter.FilterFactory;
|
||||||
|
import dsp.filter.fir.FIRFilterSpecification;
|
||||||
import filter.AllPassFilter;
|
import filter.AllPassFilter;
|
||||||
import filter.FilterSet;
|
import filter.FilterSet;
|
||||||
import filter.IFilter;
|
import filter.IFilter;
|
||||||
@@ -89,12 +91,34 @@ import module.decode.tait.Tait1200DecoderState;
|
|||||||
import module.demodulate.am.AMDemodulatorModule;
|
import module.demodulate.am.AMDemodulatorModule;
|
||||||
import module.demodulate.audio.DemodulatedAudioFilterModule;
|
import module.demodulate.audio.DemodulatedAudioFilterModule;
|
||||||
import module.demodulate.fm.FMDemodulatorModule;
|
import module.demodulate.fm.FMDemodulatorModule;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class DecoderFactory
|
public class DecoderFactory
|
||||||
{
|
{
|
||||||
|
private final static Logger mLog = LoggerFactory.getLogger(DecoderFactory.class);
|
||||||
|
|
||||||
|
private static final FIRFilterSpecification MPT1327_FILTER_SPECIFICATION = FIRFilterSpecification.bandPassBuilder()
|
||||||
|
.sampleRate(48000).stopFrequency1(200).passFrequencyBegin(400).passFrequencyEnd(3200)
|
||||||
|
.stopFrequency2(3400).stopRipple(0.0003).passRipple(0.008).build();
|
||||||
|
|
||||||
|
private static float[] MPT1327_BANDPASS_FILTER;
|
||||||
|
|
||||||
|
static
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
MPT1327_BANDPASS_FILTER = FilterFactory.getTaps(MPT1327_FILTER_SPECIFICATION);
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
mLog.error("Couldn't design MPT1327 bandpass filter");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static final boolean NO_REMOVE_DC = false;
|
public static final boolean NO_REMOVE_DC = false;
|
||||||
public static final boolean REMOVE_DC = true;
|
public static final boolean REMOVE_DC = true;
|
||||||
|
|
||||||
@@ -197,7 +221,7 @@ public class DecoderFactory
|
|||||||
}
|
}
|
||||||
|
|
||||||
modules.add(new FMDemodulatorModule(iqPass, iqStop));
|
modules.add(new FMDemodulatorModule(iqPass, iqStop));
|
||||||
modules.add(new DemodulatedAudioFilterModule(4000, 6000));
|
modules.add(new DemodulatedAudioFilterModule(MPT1327_BANDPASS_FILTER, 2.0f));
|
||||||
modules.add(new AudioModule(metadata));
|
modules.add(new AudioModule(metadata));
|
||||||
break;
|
break;
|
||||||
case PASSPORT:
|
case PASSPORT:
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* SDR Trunk
|
* sdrtrunk
|
||||||
* Copyright (C) 2014 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,51 +14,46 @@
|
|||||||
*
|
*
|
||||||
* 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 module.decode.mpt1327;
|
package module.decode.mpt1327;
|
||||||
|
|
||||||
|
import alias.AliasList;
|
||||||
|
import bits.MessageFramer;
|
||||||
|
import bits.SyncPattern;
|
||||||
|
import dsp.filter.Filters;
|
||||||
|
import dsp.filter.dc.DCRemovalFilterLyons;
|
||||||
|
import dsp.filter.fir.real.RealFIRFilter_RB_RB;
|
||||||
|
import dsp.filter.halfband.real.HalfBandFilter_RB_RB;
|
||||||
|
import dsp.fsk.FSK2Decoder;
|
||||||
|
import dsp.fsk.FSK2Decoder.Output;
|
||||||
import instrument.Instrumentable;
|
import instrument.Instrumentable;
|
||||||
import instrument.tap.Tap;
|
import instrument.tap.Tap;
|
||||||
import instrument.tap.TapGroup;
|
import instrument.tap.TapGroup;
|
||||||
import instrument.tap.stream.BinaryTap;
|
import instrument.tap.stream.BinaryTap;
|
||||||
import instrument.tap.stream.FloatBufferTap;
|
import instrument.tap.stream.FloatBufferTap;
|
||||||
import instrument.tap.stream.FloatTap;
|
import instrument.tap.stream.FloatTap;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
|
||||||
|
|
||||||
import module.decode.Decoder;
|
import module.decode.Decoder;
|
||||||
import module.decode.DecoderType;
|
import module.decode.DecoderType;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import sample.Broadcaster;
|
import sample.Broadcaster;
|
||||||
import sample.Listener;
|
import sample.Listener;
|
||||||
import sample.real.IFilteredRealBufferListener;
|
import sample.real.IFilteredRealBufferListener;
|
||||||
import sample.real.RealBuffer;
|
import sample.real.RealBuffer;
|
||||||
import alias.AliasList;
|
|
||||||
import bits.MessageFramer;
|
import java.util.ArrayList;
|
||||||
import bits.SyncPattern;
|
import java.util.List;
|
||||||
import dsp.filter.FilterFactory;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import dsp.filter.Filters;
|
|
||||||
import dsp.filter.Window.WindowType;
|
|
||||||
import dsp.filter.dc.DCRemovalFilterLyons;
|
|
||||||
import dsp.filter.fir.real.RealFIRFilter_RB_RB;
|
|
||||||
import dsp.filter.halfband.real.HalfBandFilter_RB_RB;
|
|
||||||
import dsp.fsk.FSK2Decoder;
|
|
||||||
import dsp.fsk.FSK2Decoder.Output;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MPT1327 Decoder - 1200 baud 2FSK decoder that can process 48k sample rate
|
* MPT1327 Decoder - 1200 baud 2FSK decoder that can process 48k sample rate
|
||||||
* complex or floating point samples and output fully framed MPT1327 control and
|
* complex or floating point samples and output fully framed MPT1327 control and
|
||||||
* traffic messages.
|
* traffic messages.
|
||||||
*/
|
*/
|
||||||
public class MPT1327Decoder extends Decoder
|
public class MPT1327Decoder extends Decoder implements IFilteredRealBufferListener, Instrumentable
|
||||||
implements IFilteredRealBufferListener, Instrumentable
|
|
||||||
{
|
{
|
||||||
private final static Logger mLog = LoggerFactory.getLogger( MPT1327Decoder.class );
|
private final static Logger mLog = LoggerFactory.getLogger(MPT1327Decoder.class);
|
||||||
|
|
||||||
/* Decimated sample rate ( 48,000 / 2 = 24,000 ) feeding the decoder */
|
/* Decimated sample rate ( 48,000 / 2 = 24,000 ) feeding the decoder */
|
||||||
private static final int sDECIMATED_SAMPLE_RATE = 24000;
|
private static final int sDECIMATED_SAMPLE_RATE = 24000;
|
||||||
@@ -88,62 +83,46 @@ public class MPT1327Decoder extends Decoder
|
|||||||
private MessageFramer mTrafficMessageFramer;
|
private MessageFramer mTrafficMessageFramer;
|
||||||
private MPT1327MessageProcessor mMessageProcessor;
|
private MPT1327MessageProcessor mMessageProcessor;
|
||||||
|
|
||||||
public MPT1327Decoder( AliasList aliasList, Sync sync )
|
public MPT1327Decoder(AliasList aliasList, Sync sync)
|
||||||
{
|
{
|
||||||
|
|
||||||
/* Decimation filter - 48000 / 2 = 24000 output */
|
/* Decimation filter - 48000 / 2 = 24000 output */
|
||||||
mDecimationFilter = new HalfBandFilter_RB_RB(
|
mDecimationFilter = new HalfBandFilter_RB_RB(Filters.FIR_HALF_BAND_31T_ONE_EIGHTH_FCO.getCoefficients(), 1.0002f, true);
|
||||||
Filters.FIR_HALF_BAND_31T_ONE_EIGHTH_FCO.getCoefficients(), 1.0002f, true );
|
|
||||||
|
|
||||||
/* Low pass filter: 2kHz to pass the 1200 & 1800 Hz FSK */
|
|
||||||
mLowPassFilter = new RealFIRFilter_RB_RB(
|
|
||||||
FilterFactory.getLowPass( 24000, //sampleRate,
|
|
||||||
2000, //passFrequency,
|
|
||||||
4000, //stopFrequency,
|
|
||||||
60, //attenuation,
|
|
||||||
WindowType.HANNING, //windowType,
|
|
||||||
true ) //forceOddLength
|
|
||||||
, 2.0f ); //Gain
|
|
||||||
mDecimationFilter.setListener( mLowPassFilter );
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Normal: 2FSK Decoder with inverted output
|
* Normal: 2FSK Decoder with inverted output
|
||||||
* French: 2FSK Decoder with normal output
|
* French: 2FSK Decoder with normal output
|
||||||
*/
|
*/
|
||||||
if( sync == Sync.NORMAL )
|
if(sync == Sync.NORMAL)
|
||||||
{
|
{
|
||||||
mFSKDecoder = new FSK2Decoder( 24000, 1200, Output.INVERTED );
|
mFSKDecoder = new FSK2Decoder(24000, 1200, Output.INVERTED);
|
||||||
}
|
}
|
||||||
else if( sync == Sync.FRENCH )
|
else if(sync == Sync.FRENCH)
|
||||||
{
|
{
|
||||||
mFSKDecoder = new FSK2Decoder( 24000, 1200, Output.NORMAL );
|
mFSKDecoder = new FSK2Decoder(24000, 1200, Output.NORMAL);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new IllegalArgumentException( "MPT1327 Decoder - unrecognized Sync type" );
|
throw new IllegalArgumentException("MPT1327 Decoder - unrecognized Sync type");
|
||||||
}
|
}
|
||||||
mLowPassFilter.setListener( mFSKDecoder );
|
|
||||||
|
mDecimationFilter.setListener(mFSKDecoder);
|
||||||
|
|
||||||
mSymbolBroadcaster = new Broadcaster<Boolean>();
|
mSymbolBroadcaster = new Broadcaster<Boolean>();
|
||||||
mFSKDecoder.setListener( mSymbolBroadcaster );
|
mFSKDecoder.setListener(mSymbolBroadcaster);
|
||||||
|
|
||||||
/* Message framer for control channel messages */
|
/* Message framer for control channel messages */
|
||||||
mControlMessageFramer =
|
mControlMessageFramer = new MessageFramer(sync.getControlSyncPattern().getPattern(), sMESSAGE_LENGTH);
|
||||||
new MessageFramer( sync.getControlSyncPattern().getPattern(),
|
mSymbolBroadcaster.addListener(mControlMessageFramer);
|
||||||
sMESSAGE_LENGTH );
|
|
||||||
mSymbolBroadcaster.addListener( mControlMessageFramer );
|
|
||||||
|
|
||||||
/* Message framer for traffic channel massages */
|
/* Message framer for traffic channel massages */
|
||||||
mTrafficMessageFramer =
|
mTrafficMessageFramer = new MessageFramer(sync.getTrafficSyncPattern().getPattern(), sMESSAGE_LENGTH);
|
||||||
new MessageFramer( sync.getTrafficSyncPattern().getPattern(),
|
mSymbolBroadcaster.addListener(mTrafficMessageFramer);
|
||||||
sMESSAGE_LENGTH );
|
|
||||||
mSymbolBroadcaster.addListener( mTrafficMessageFramer );
|
|
||||||
|
|
||||||
/* Fully decoded and framed messages processor */
|
/* Fully decoded and framed messages processor */
|
||||||
mMessageProcessor = new MPT1327MessageProcessor( aliasList );
|
mMessageProcessor = new MPT1327MessageProcessor(aliasList);
|
||||||
mMessageProcessor.setMessageListener( this );
|
mMessageProcessor.setMessageListener(this);
|
||||||
mControlMessageFramer.addMessageListener( mMessageProcessor );
|
mControlMessageFramer.addMessageListener(mMessageProcessor);
|
||||||
mTrafficMessageFramer.addMessageListener( mMessageProcessor );
|
mTrafficMessageFramer.addMessageListener(mMessageProcessor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -169,7 +148,7 @@ public class MPT1327Decoder extends Decoder
|
|||||||
|
|
||||||
mControlMessageFramer.dispose();
|
mControlMessageFramer.dispose();
|
||||||
|
|
||||||
if( mDCRemovalFilter != null )
|
if(mDCRemovalFilter != null)
|
||||||
{
|
{
|
||||||
mDCRemovalFilter.dispose();
|
mDCRemovalFilter.dispose();
|
||||||
}
|
}
|
||||||
@@ -189,89 +168,80 @@ public class MPT1327Decoder extends Decoder
|
|||||||
@Override
|
@Override
|
||||||
public List<TapGroup> getTapGroups()
|
public List<TapGroup> getTapGroups()
|
||||||
{
|
{
|
||||||
if( mAvailableTaps == null )
|
if(mAvailableTaps == null)
|
||||||
{
|
{
|
||||||
mAvailableTaps = new ArrayList<TapGroup>();
|
mAvailableTaps = new ArrayList<TapGroup>();
|
||||||
|
|
||||||
TapGroup group = new TapGroup( "MPT-1327 Decoder" );
|
TapGroup group = new TapGroup("MPT-1327 Decoder");
|
||||||
|
|
||||||
group.add(
|
group.add(new FloatTap(INSTRUMENT_HB1_FILTER_TO_LOW_PASS, 0, 0.5f));
|
||||||
new FloatTap( INSTRUMENT_HB1_FILTER_TO_LOW_PASS, 0, 0.5f ) );
|
group.add(new FloatTap(INSTRUMENT_LOW_PASS_TO_DECODER, 0, 0.5f));
|
||||||
group.add(
|
group.add(new BinaryTap(INSTRUMENT_DECODER_TO_FRAMER, 0, 0.025f));
|
||||||
new FloatTap( INSTRUMENT_LOW_PASS_TO_DECODER, 0, 0.5f ) );
|
|
||||||
group.add(
|
|
||||||
new BinaryTap( INSTRUMENT_DECODER_TO_FRAMER, 0, 0.025f ) );
|
|
||||||
|
|
||||||
mAvailableTaps.add( group );
|
mAvailableTaps.add(group);
|
||||||
|
|
||||||
/* Add the taps from the FSK decoder */
|
/* Add the taps from the FSK decoder */
|
||||||
mAvailableTaps.addAll( mFSKDecoder.getTapGroups() );
|
mAvailableTaps.addAll(mFSKDecoder.getTapGroups());
|
||||||
}
|
}
|
||||||
|
|
||||||
return mAvailableTaps;
|
return mAvailableTaps;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerTap( Tap tap )
|
public void registerTap(Tap tap)
|
||||||
{
|
{
|
||||||
/* Send request to decoder */
|
/* Send request to decoder */
|
||||||
mFSKDecoder.registerTap( tap );
|
mFSKDecoder.registerTap(tap);
|
||||||
|
|
||||||
switch( tap.getName() )
|
switch(tap.getName())
|
||||||
{
|
{
|
||||||
case INSTRUMENT_HB1_FILTER_TO_LOW_PASS:
|
case INSTRUMENT_HB1_FILTER_TO_LOW_PASS:
|
||||||
FloatBufferTap hb1Tap = (FloatBufferTap)tap;
|
FloatBufferTap hb1Tap = (FloatBufferTap) tap;
|
||||||
mDecimationFilter.setListener( hb1Tap );
|
mDecimationFilter.setListener(hb1Tap);
|
||||||
hb1Tap.setListener( mLowPassFilter );
|
hb1Tap.setListener(mLowPassFilter);
|
||||||
break;
|
break;
|
||||||
case INSTRUMENT_LOW_PASS_TO_DECODER:
|
case INSTRUMENT_LOW_PASS_TO_DECODER:
|
||||||
FloatBufferTap lowTap = (FloatBufferTap)tap;
|
FloatBufferTap lowTap = (FloatBufferTap) tap;
|
||||||
mLowPassFilter.setListener( lowTap );
|
mLowPassFilter.setListener(lowTap);
|
||||||
lowTap.setListener( mFSKDecoder );
|
lowTap.setListener(mFSKDecoder);
|
||||||
break;
|
break;
|
||||||
case INSTRUMENT_DECODER_TO_FRAMER:
|
case INSTRUMENT_DECODER_TO_FRAMER:
|
||||||
BinaryTap decoderTap = (BinaryTap)tap;
|
BinaryTap decoderTap = (BinaryTap) tap;
|
||||||
mFSKDecoder.setListener( decoderTap );
|
mFSKDecoder.setListener(decoderTap);
|
||||||
decoderTap.setListener( mSymbolBroadcaster );
|
decoderTap.setListener(mSymbolBroadcaster);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void unregisterTap( Tap tap )
|
public void unregisterTap(Tap tap)
|
||||||
{
|
{
|
||||||
mFSKDecoder.unregisterTap( tap );
|
mFSKDecoder.unregisterTap(tap);
|
||||||
|
|
||||||
switch( tap.getName() )
|
switch(tap.getName())
|
||||||
{
|
{
|
||||||
case INSTRUMENT_HB1_FILTER_TO_LOW_PASS:
|
case INSTRUMENT_HB1_FILTER_TO_LOW_PASS:
|
||||||
mDecimationFilter.setListener( mLowPassFilter );
|
mDecimationFilter.setListener(mLowPassFilter);
|
||||||
break;
|
break;
|
||||||
case INSTRUMENT_LOW_PASS_TO_DECODER:
|
case INSTRUMENT_LOW_PASS_TO_DECODER:
|
||||||
mLowPassFilter.setListener( mFSKDecoder );
|
mLowPassFilter.setListener(mFSKDecoder);
|
||||||
break;
|
break;
|
||||||
case INSTRUMENT_DECODER_TO_FRAMER:
|
case INSTRUMENT_DECODER_TO_FRAMER:
|
||||||
mFSKDecoder.setListener( mSymbolBroadcaster );
|
mFSKDecoder.setListener(mSymbolBroadcaster);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum Sync
|
public enum Sync
|
||||||
{
|
{
|
||||||
NORMAL( "Normal",
|
NORMAL("Normal", SyncPattern.MPT1327_CONTROL, SyncPattern.MPT1327_TRAFFIC),
|
||||||
SyncPattern.MPT1327_CONTROL,
|
FRENCH("French", SyncPattern.MPT1327_CONTROL_FRENCH, SyncPattern.MPT1327_TRAFFIC_FRENCH);
|
||||||
SyncPattern.MPT1327_TRAFFIC ),
|
|
||||||
FRENCH( "French",
|
|
||||||
SyncPattern.MPT1327_CONTROL_FRENCH,
|
|
||||||
SyncPattern.MPT1327_TRAFFIC_FRENCH );
|
|
||||||
|
|
||||||
private String mLabel;
|
private String mLabel;
|
||||||
private SyncPattern mControlSyncPattern;
|
private SyncPattern mControlSyncPattern;
|
||||||
private SyncPattern mTrafficSyncPattern;
|
private SyncPattern mTrafficSyncPattern;
|
||||||
|
|
||||||
private Sync( String label,
|
private Sync(String label, SyncPattern controlPattern, SyncPattern trafficPattern)
|
||||||
SyncPattern controlPattern,
|
|
||||||
SyncPattern trafficPattern )
|
|
||||||
{
|
{
|
||||||
mLabel = label;
|
mLabel = label;
|
||||||
mControlSyncPattern = controlPattern;
|
mControlSyncPattern = controlPattern;
|
||||||
@@ -307,16 +277,14 @@ public class MPT1327Decoder extends Decoder
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start( ScheduledExecutorService executor )
|
public void start(ScheduledExecutorService executor)
|
||||||
{
|
{
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stop()
|
public void stop()
|
||||||
{
|
{
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* SDR Trunk
|
* sdrtrunk
|
||||||
* Copyright (C) 2014-2016 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,47 +14,56 @@
|
|||||||
*
|
*
|
||||||
* 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 module.demodulate.audio;
|
package module.demodulate.audio;
|
||||||
|
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
|
||||||
|
|
||||||
import module.Module;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import sample.Listener;
|
|
||||||
import sample.real.IFilteredRealBufferProvider;
|
|
||||||
import sample.real.IUnFilteredRealBufferListener;
|
|
||||||
import sample.real.RealBuffer;
|
|
||||||
import dsp.filter.FilterFactory;
|
import dsp.filter.FilterFactory;
|
||||||
import dsp.filter.Window.WindowType;
|
import dsp.filter.Window.WindowType;
|
||||||
import dsp.filter.dc.DCRemovalFilter_RealBuffer;
|
import dsp.filter.dc.DCRemovalFilter_RealBuffer;
|
||||||
import dsp.filter.fir.real.RealFIRFilter_RB_RB;
|
import dsp.filter.fir.real.RealFIRFilter_RB_RB;
|
||||||
|
import module.Module;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import sample.Listener;
|
||||||
|
import sample.real.IFilteredRealBufferProvider;
|
||||||
|
import sample.real.IUnFilteredRealBufferListener;
|
||||||
|
import sample.real.RealBuffer;
|
||||||
|
|
||||||
public class DemodulatedAudioFilterModule extends Module
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
implements IUnFilteredRealBufferListener, IFilteredRealBufferProvider
|
|
||||||
|
public class DemodulatedAudioFilterModule extends Module implements IUnFilteredRealBufferListener, IFilteredRealBufferProvider
|
||||||
{
|
{
|
||||||
private final static Logger mLog = LoggerFactory.getLogger( DemodulatedAudioFilterModule.class );
|
private final static Logger mLog = LoggerFactory.getLogger(DemodulatedAudioFilterModule.class);
|
||||||
|
|
||||||
private DCRemovalFilter_RealBuffer mDCFilter = new DCRemovalFilter_RealBuffer();
|
private DCRemovalFilter_RealBuffer mDCFilter;
|
||||||
private RealFIRFilter_RB_RB mBandPassFilter;
|
private RealFIRFilter_RB_RB mBandPassFilter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filters demodulated audio and removes any DC component from the buffer
|
* Filters demodulated audio and removes any DC component from the buffer
|
||||||
*
|
*
|
||||||
* @param pass - audio pass band pass frequency
|
* @param pass - audio pass band pass frequency
|
||||||
* @param stop - audio pass band stop frequency
|
* @param stop - audio pass band stop frequency
|
||||||
*/
|
*/
|
||||||
public DemodulatedAudioFilterModule( int pass, int stop )
|
public DemodulatedAudioFilterModule(int pass, int stop)
|
||||||
{
|
{
|
||||||
assert( stop > pass );
|
assert (stop > pass);
|
||||||
|
|
||||||
//TODO: change this to a band pass filter
|
mDCFilter = new DCRemovalFilter_RealBuffer();
|
||||||
mBandPassFilter = new RealFIRFilter_RB_RB( FilterFactory.getLowPass( 48000, pass, stop, 60,
|
|
||||||
WindowType.HANNING, true ), 1.0f );
|
|
||||||
|
|
||||||
mDCFilter.setListener( mBandPassFilter );
|
//TODO: change this to a band pass filter
|
||||||
|
mBandPassFilter = new RealFIRFilter_RB_RB(FilterFactory.getLowPass(48000, pass, stop, 60,
|
||||||
|
WindowType.HANNING, true), 1.0f);
|
||||||
|
|
||||||
|
mDCFilter.setListener(mBandPassFilter);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a demodulated audio filter using the filter taps and gain provided
|
||||||
|
*/
|
||||||
|
public DemodulatedAudioFilterModule(float[] taps, float gain)
|
||||||
|
{
|
||||||
|
mBandPassFilter = new RealFIRFilter_RB_RB(taps, gain);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -73,9 +82,9 @@ public class DemodulatedAudioFilterModule extends Module
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setFilteredRealBufferListener( Listener<RealBuffer> listener )
|
public void setFilteredRealBufferListener(Listener<RealBuffer> listener)
|
||||||
{
|
{
|
||||||
mBandPassFilter.setListener( listener );
|
mBandPassFilter.setListener(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -85,7 +94,7 @@ public class DemodulatedAudioFilterModule extends Module
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start( ScheduledExecutorService executor )
|
public void start(ScheduledExecutorService executor)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,7 +105,14 @@ public class DemodulatedAudioFilterModule extends Module
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Listener<RealBuffer> getUnFilteredRealBufferListener()
|
public Listener<RealBuffer> getUnFilteredRealBufferListener()
|
||||||
|
{
|
||||||
|
if(mDCFilter != null)
|
||||||
{
|
{
|
||||||
return mDCFilter;
|
return mDCFilter;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return mBandPassFilter;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,27 +17,24 @@
|
|||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package module.demodulate.fm;
|
package module.demodulate.fm;
|
||||||
|
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import dsp.filter.FilterFactory;
|
||||||
|
import dsp.filter.Window.WindowType;
|
||||||
|
import dsp.filter.fir.complex.ComplexFIRFilter_CB_CB;
|
||||||
|
import dsp.fm.FMDemodulator_CB;
|
||||||
import module.Module;
|
import module.Module;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import sample.Listener;
|
import sample.Listener;
|
||||||
import sample.complex.ComplexBuffer;
|
import sample.complex.ComplexBuffer;
|
||||||
import sample.complex.IComplexBufferListener;
|
import sample.complex.IComplexBufferListener;
|
||||||
import sample.real.IUnFilteredRealBufferProvider;
|
import sample.real.IUnFilteredRealBufferProvider;
|
||||||
import sample.real.RealBuffer;
|
import sample.real.RealBuffer;
|
||||||
import dsp.filter.FilterFactory;
|
|
||||||
import dsp.filter.Window.WindowType;
|
|
||||||
import dsp.filter.fir.complex.ComplexFIRFilter_CB_CB;
|
|
||||||
import dsp.fm.FMDemodulator_CB;
|
|
||||||
|
|
||||||
public class FMDemodulatorModule extends Module
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
implements IComplexBufferListener, IUnFilteredRealBufferProvider
|
|
||||||
|
public class FMDemodulatorModule extends Module implements IComplexBufferListener, IUnFilteredRealBufferProvider
|
||||||
{
|
{
|
||||||
private final static Logger mLog = LoggerFactory.getLogger( FMDemodulatorModule.class );
|
private final static Logger mLog = LoggerFactory.getLogger(FMDemodulatorModule.class);
|
||||||
|
|
||||||
private static final int SAMPLE_RATE = 48000;
|
private static final int SAMPLE_RATE = 48000;
|
||||||
|
|
||||||
@@ -52,18 +49,17 @@ public class FMDemodulatorModule extends Module
|
|||||||
* frequency should be half of the signal bandwidth since the filter will
|
* frequency should be half of the signal bandwidth since the filter will
|
||||||
* be applied against each of the inphase and quadrature signals and the
|
* be applied against each of the inphase and quadrature signals and the
|
||||||
* combined pass bandwidth will be twice this value.
|
* combined pass bandwidth will be twice this value.
|
||||||
*
|
|
||||||
* @param stop - stop frequency for IQ filtering prior to demodulation.
|
* @param stop - stop frequency for IQ filtering prior to demodulation.
|
||||||
*/
|
*/
|
||||||
public FMDemodulatorModule( int pass, int stop )
|
public FMDemodulatorModule(int pass, int stop)
|
||||||
{
|
{
|
||||||
assert( stop > pass );
|
assert (stop > pass);
|
||||||
|
|
||||||
mIQFilter = new ComplexFIRFilter_CB_CB( FilterFactory.getLowPass(
|
mIQFilter = new ComplexFIRFilter_CB_CB(FilterFactory.getLowPass(
|
||||||
SAMPLE_RATE, pass, stop, 60, WindowType.HAMMING, true ), 1.0f );
|
SAMPLE_RATE, pass, stop, 60, WindowType.HAMMING, true), 1.0f);
|
||||||
|
|
||||||
mDemodulator = new FMDemodulator_CB( 1.0f );
|
mDemodulator = new FMDemodulator_CB(1.0f);
|
||||||
mIQFilter.setListener( mDemodulator );
|
mIQFilter.setListener(mDemodulator);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -89,9 +85,9 @@ public class FMDemodulatorModule extends Module
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setUnFilteredRealBufferListener( Listener<RealBuffer> listener )
|
public void setUnFilteredRealBufferListener(Listener<RealBuffer> listener)
|
||||||
{
|
{
|
||||||
mDemodulator.setListener( listener );
|
mDemodulator.setListener(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -101,7 +97,7 @@ public class FMDemodulatorModule extends Module
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start( ScheduledExecutorService executor )
|
public void start(ScheduledExecutorService executor)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -166,9 +166,11 @@ public class PlaylistManager implements ChannelEventListener
|
|||||||
|
|
||||||
mAliasModel.addAliases(playlist.getAliases());
|
mAliasModel.addAliases(playlist.getAliases());
|
||||||
mBroadcastModel.addBroadcastConfigurations(playlist.getBroadcastConfigurations());
|
mBroadcastModel.addBroadcastConfigurations(playlist.getBroadcastConfigurations());
|
||||||
mChannelModel.addChannels(playlist.getChannels());
|
|
||||||
mChannelMapModel.addChannelMaps(playlist.getChannelMaps());
|
mChannelMapModel.addChannelMaps(playlist.getChannelMaps());
|
||||||
|
|
||||||
|
//Channel model has to be loaded last since it will auto-start channels that are enabled
|
||||||
|
mChannelModel.addChannels(playlist.getChannels());
|
||||||
|
|
||||||
mPlaylistLoading = false;
|
mPlaylistLoading = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user