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:
dennis.sheirer
2014-09-06 14:58:05 +00:00
parent 5ddf538e2a
commit 4e0fd9b7b0
44 changed files with 1986 additions and 549 deletions

View 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 );
}
}
}

View 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 );
}
}
}

View 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 );
}
}
}