mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-17 02:57:35 -05:00
Channel Spectral Display
- Adds Channel Spectrum tab to display FFT of the audio output of the currently selected channel - Upgrades to JTransforms 3.0 FFT library - Adds three new context menus to main and channel spectral displays: -- Baseline - affects the vertical rendering baseline of the FFT -- Amplification - affects the vertical height of each FFT bin -- Averaging - affects how many FFTs are averaged to produce the display
This commit is contained in:
62
src/spectrum/converter/ComplexDecibelConverter.java
Normal file
62
src/spectrum/converter/ComplexDecibelConverter.java
Normal file
@@ -0,0 +1,62 @@
|
||||
package spectrum.converter;
|
||||
|
||||
public class ComplexDecibelConverter extends DFTResultsConverter
|
||||
{
|
||||
/**
|
||||
* Converts the output of the JTransforms FloatFFT_1D.complexForward()
|
||||
* calculation into a normalized power spectrum in decibels, per description
|
||||
* in Lyons, Understanding Digital Signal Processing, 3e, page 141.
|
||||
*/
|
||||
@Override
|
||||
public void receive( float[] results )
|
||||
{
|
||||
float dc = Math.abs( results[ 0 ] );
|
||||
|
||||
/* Ensure we have power in the DC power bin (bin 0), otherwise don't
|
||||
* dispatch the results */
|
||||
if( dc > 0 )
|
||||
{
|
||||
float[] processed = new float[ results.length / 2 + 1 ];
|
||||
|
||||
/**
|
||||
* Output from JTransforms 3.0 has the lower and upper halves of the
|
||||
* spectrum swapped.
|
||||
*/
|
||||
int half = processed.length / 2;
|
||||
|
||||
for( int x = 0; x < processed.length - 2; x ++ )
|
||||
{
|
||||
int index = ( x + 1 ) * 2;
|
||||
|
||||
double magnitude2 = ( ( results[ index ] * results[ index ] ) +
|
||||
( results[ index + 1 ] * results[ index + 1 ] ) );
|
||||
|
||||
if( x < half )
|
||||
{
|
||||
processed[ x + half ] = 10.0f *
|
||||
(float)( Math.log10( magnitude2 / dc ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
processed[ x - half ] = 10.0f *
|
||||
(float)( Math.log10( magnitude2 / dc ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Place scaled dc component in last bin of processed array as
|
||||
* scaling reference
|
||||
*/
|
||||
processed[ results.length / 2 ] = processed[ half ];
|
||||
|
||||
/**
|
||||
* Repair the erroneous DC component bin by using the average of
|
||||
* the neighboring bins
|
||||
*/
|
||||
processed[ half ] = ( processed[ half - 1 ] +
|
||||
processed[ half + 1 ] / 2.0f );
|
||||
|
||||
dispatch( processed );
|
||||
}
|
||||
}
|
||||
}
|
||||
46
src/spectrum/converter/DFTResultsConverter.java
Normal file
46
src/spectrum/converter/DFTResultsConverter.java
Normal file
@@ -0,0 +1,46 @@
|
||||
package spectrum.converter;
|
||||
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import spectrum.DFTResultsListener;
|
||||
import spectrum.DFTResultsProvider;
|
||||
|
||||
public abstract class DFTResultsConverter
|
||||
implements DFTResultsListener, DFTResultsProvider
|
||||
{
|
||||
private CopyOnWriteArrayList<DFTResultsListener> mListeners =
|
||||
new CopyOnWriteArrayList<DFTResultsListener>();
|
||||
|
||||
/**
|
||||
* DFT Results Converter - for converting the output of the JTransforms
|
||||
* FFT library real and complex forward results
|
||||
*/
|
||||
public DFTResultsConverter()
|
||||
{
|
||||
}
|
||||
|
||||
public void dispose()
|
||||
{
|
||||
mListeners.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addListener( DFTResultsListener listener )
|
||||
{
|
||||
mListeners.add( listener );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeListener( DFTResultsListener listener )
|
||||
{
|
||||
mListeners.remove( listener );
|
||||
}
|
||||
|
||||
protected void dispatch( float[] results )
|
||||
{
|
||||
for( DFTResultsListener listener: mListeners )
|
||||
{
|
||||
listener.receive( results );
|
||||
}
|
||||
}
|
||||
}
|
||||
38
src/spectrum/converter/RealDecibelConverter.java
Normal file
38
src/spectrum/converter/RealDecibelConverter.java
Normal file
@@ -0,0 +1,38 @@
|
||||
package spectrum.converter;
|
||||
|
||||
public class RealDecibelConverter extends DFTResultsConverter
|
||||
{
|
||||
/**
|
||||
* Converts the output of the JTransforms FloatFFT_1D.realForward()
|
||||
* calculation into a normalized power spectrum in decibels, per description
|
||||
* in Lyons, Understanding Digital Signal Processing, 3e, page 141.
|
||||
*/
|
||||
@Override
|
||||
public void receive( float[] results )
|
||||
{
|
||||
float dc = Math.abs( results[ 0 ] );
|
||||
|
||||
/* Ensure we have power in the DC power bin (bin 0), otherwise don't
|
||||
* dispatch the results */
|
||||
if( dc != 0 )
|
||||
{
|
||||
/* Note: we're only processing 1/4 of the output samples */
|
||||
float[] processed = new float[ results.length / 4 + 1 ];
|
||||
|
||||
for( int x = 0; x < processed.length - 2; x ++ )
|
||||
{
|
||||
int index = ( x + 1 ) * 2;
|
||||
|
||||
double magnitude = ( ( results[ index ] * results[ index ] ) +
|
||||
( results[ index + 1 ] * results[ index + 1 ] ) );
|
||||
|
||||
processed[ x ] = 10.0f *
|
||||
(float)( Math.log10( magnitude / dc ) );
|
||||
}
|
||||
|
||||
processed[ processed.length - 1 ] = processed[ 0 ];
|
||||
|
||||
dispatch( processed );
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user