From f38184fd83d50263320861f7675752f6e6625d19 Mon Sep 17 00:00:00 2001 From: Denny Date: Sun, 10 Dec 2017 06:26:44 -0500 Subject: [PATCH] #39 WIP - finishes polyphase channel source processing of frequency offset calculation and updating for channel frequency correction. --- .../channelizer/PolyphaseChannelManager.java | 5 +- .../channelizer/PolyphaseChannelSource.java | 60 +++++++++++++------ .../output/ChannelOutputProcessor.java | 29 +++------ .../IPolyphaseChannelOutputProcessor.java | 19 ++---- 4 files changed, 56 insertions(+), 57 deletions(-) diff --git a/src/dsp/filter/channelizer/PolyphaseChannelManager.java b/src/dsp/filter/channelizer/PolyphaseChannelManager.java index aa95a3c3..985174a7 100644 --- a/src/dsp/filter/channelizer/PolyphaseChannelManager.java +++ b/src/dsp/filter/channelizer/PolyphaseChannelManager.java @@ -303,14 +303,17 @@ public class PolyphaseChannelManager implements Listener { List indexes = mChannelCalculator.getChannelIndexes(channelSource.getTunerChannel()); + long centerFrequency = mChannelCalculator.getCenterFrequencyForIndexes(indexes); + //If the indexes size is the same then update the current processor, otherwise create a new one if(channelSource.getPolyphaseChannelOutputProcessor().getInputChannelCount() == indexes.size()) { channelSource.getPolyphaseChannelOutputProcessor().setPolyphaseChannelIndices(indexes); + channelSource.setFrequency(centerFrequency); } else { - channelSource.setPolyphaseChannelOutputProcessor(getOutputProcessor(indexes)); + channelSource.setPolyphaseChannelOutputProcessor(getOutputProcessor(indexes), centerFrequency); } } catch(IllegalArgumentException iae) diff --git a/src/dsp/filter/channelizer/PolyphaseChannelSource.java b/src/dsp/filter/channelizer/PolyphaseChannelSource.java index fea1ce78..6fa882f7 100644 --- a/src/dsp/filter/channelizer/PolyphaseChannelSource.java +++ b/src/dsp/filter/channelizer/PolyphaseChannelSource.java @@ -36,6 +36,8 @@ public class PolyphaseChannelSource extends TunerChannelSource private ComplexToComplexBufferAssembler mComplexBufferAssembler = new ComplexToComplexBufferAssembler(2500); private IPolyphaseChannelOutputProcessor mPolyphaseChannelOutputProcessor; private double mChannelSampleRate; + private long mCenterFrequency; + private long mFrequencyCorrection; /** * Polyphase channelizer tuner channel source implementation. Adapts the channel array output samples from the @@ -84,8 +86,11 @@ public class PolyphaseChannelSource extends TunerChannelSource /** * Sets/updates the output processor for this channel source, replacing the existing output processor. + * + * @param outputProcessor to use + * @param frequency center for the channels processed by the output processor */ - public void setPolyphaseChannelOutputProcessor(IPolyphaseChannelOutputProcessor outputProcessor) + public void setPolyphaseChannelOutputProcessor(IPolyphaseChannelOutputProcessor outputProcessor, long frequency) { //Lock on the channel output processor to block the channel results processor thread from servicing the //channel output processor's buffer while we change out the processors. @@ -108,6 +113,13 @@ public class PolyphaseChannelSource extends TunerChannelSource { existingProcessor.processChannelResults(mComplexBufferAssembler); } + + //Finally, setup the frequency offset for the output processor and reset the frequency correction value + //to allow consumers to adjust and calculate a new frequency correction value, if needed. + mCenterFrequency = frequency; + mFrequencyCorrection = 0; + mPolyphaseChannelOutputProcessor.setFrequencyOffset(getFrequencyOffset()); + broadcastConsumerSourceEvent(SourceEvent.frequencyCorrectionChange(mFrequencyCorrection)); } } @@ -153,14 +165,7 @@ public class PolyphaseChannelSource extends TunerChannelSource @Override public long getFrequencyCorrection() { - IPolyphaseChannelOutputProcessor processor = mPolyphaseChannelOutputProcessor; - - if(processor != null) - { - return processor.getFrequencyCorrection(); - } - - return 0; + return mFrequencyCorrection; } /** @@ -171,24 +176,20 @@ public class PolyphaseChannelSource extends TunerChannelSource */ protected void setFrequencyCorrection(long value) { - if(mPolyphaseChannelOutputProcessor != null) - { - mPolyphaseChannelOutputProcessor.setFrequencyCorrection(value); - broadcastConsumerSourceEvent(SourceEvent.frequencyCorrectionChange(value)); - } + mFrequencyCorrection = value; + updateFrequencyOffset(); + broadcastConsumerSourceEvent(SourceEvent.frequencyCorrectionChange(mFrequencyCorrection)); } /** - * Sets the center frequency for the incoming sample stream channel results + * Sets the center frequency for the incoming sample stream channel results and resets frequency correction to zero. * @param frequency in hertz */ @Override protected void setFrequency(long frequency) { - if(mPolyphaseChannelOutputProcessor != null) - { - mPolyphaseChannelOutputProcessor.setFrequency(frequency); - } + mCenterFrequency = frequency; + setFrequencyCorrection(0); } @Override @@ -200,4 +201,25 @@ public class PolyphaseChannelSource extends TunerChannelSource mPolyphaseChannelOutputProcessor.processChannelResults(mComplexBufferAssembler); } } + + /** + * Calculates the frequency offset required to mix the incoming signal to the desired output baseband + */ + private long getFrequencyOffset() + { + return getTunerChannel().getFrequency() - mCenterFrequency + mFrequencyCorrection; + } + + /** + * Updates the frequency offset being applied by the output processor. Calculates the offset using the center + * frequency of the incoming polyphase channel results and the desired output channel frequency adjusted by any + * requested frequency correction value. + */ + private void updateFrequencyOffset() + { + synchronized(mPolyphaseChannelOutputProcessor) + { + mPolyphaseChannelOutputProcessor.setFrequencyOffset(getFrequencyOffset()); + } + } } diff --git a/src/dsp/filter/channelizer/output/ChannelOutputProcessor.java b/src/dsp/filter/channelizer/output/ChannelOutputProcessor.java index d4f9a095..c1504f7f 100644 --- a/src/dsp/filter/channelizer/output/ChannelOutputProcessor.java +++ b/src/dsp/filter/channelizer/output/ChannelOutputProcessor.java @@ -60,16 +60,15 @@ public abstract class ChannelOutputProcessor implements IPolyphaseChannelOutputP mChannelResultsQueue = new OverflowableTransferQueue<>((int)(sampleRate * 3), (int)(sampleRate * 0.5)); } + /** + * Sets the frequency offset to apply to the incoming samples to mix the desired signal to baseband. + * @param frequencyOffset in hertz + */ @Override - public void setFrequency(long frequency) + public void setFrequencyOffset(long frequencyOffset) { - - } - - @Override - public long getFrequencyCorrection() - { - return 0; + mFrequencyCorrectionMixer.setFrequency(frequencyOffset); + mFrequencyCorrectionEnabled = (frequencyOffset != 0); } @Override @@ -160,20 +159,6 @@ public abstract class ChannelOutputProcessor implements IPolyphaseChannelOutputP mFrequencyCorrectionMixer.quadrature()); } - /** - * Specifies a frequency correction value to be applied to channel samples output from this polyphase channelizer - * output processor. - * - * @param frequencyCorrection offset value - */ - @Override - public void setFrequencyCorrection(long frequencyCorrection) - { - mFrequencyCorrectionMixer.setFrequency(frequencyCorrection); - - mFrequencyCorrectionEnabled = (frequencyCorrection != 0); - } - /** * Indicates if this channel has a frequency correction offset */ diff --git a/src/dsp/filter/channelizer/output/IPolyphaseChannelOutputProcessor.java b/src/dsp/filter/channelizer/output/IPolyphaseChannelOutputProcessor.java index 2dd26684..e285fd70 100644 --- a/src/dsp/filter/channelizer/output/IPolyphaseChannelOutputProcessor.java +++ b/src/dsp/filter/channelizer/output/IPolyphaseChannelOutputProcessor.java @@ -40,23 +40,12 @@ public interface IPolyphaseChannelOutputProcessor void processChannelResults(ComplexSampleListener listener); /** - * Sets the center frequency of the incoming channel results samples + * Sets the desired frequency offset from center. The samples will be mixed with an oscillator set to this offset + * frequency to produce an output where the desired signal is centered in the passband. + * * @param frequency in hertz */ - void setFrequency(long frequency); - - /** - * Specifies the frequency correction (+/-) that should be applied to samples extracted from the polyphase - * channelizer output results. - * - * @param frequencyCorrection correction value - */ - void setFrequencyCorrection(long frequencyCorrection); - - /** - * Current frequency correction value. - */ - long getFrequencyCorrection(); + void setFrequencyOffset(long frequency); /** * Indicates the number of input channels processed by this output processor