Files
sdrtrunk/src/spectrum/converter/RealDecibelConverter.java
denny 7455077cfa Spectrum/Waterfall display zoom feature - work in progress (issue #33)
Implements zoom in/out by mouse scroll wheel and by right-click context
menu.

Still have to add ability to drag spectrum left/right when zoomed in.
2015-11-11 20:07:37 -05:00

42 lines
1.0 KiB
Java

package spectrum.converter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class RealDecibelConverter extends DFTResultsConverter
{
private static final Logger mLog = LoggerFactory.getLogger( RealDecibelConverter.class );
public RealDecibelConverter()
{
}
/**
* 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.
*
* Note: this is only calculating the lower half of the spectrum
*/
@Override
public void receive( float[] results )
{
float dftBinSizeScalor = 1.0f / (float)results.length;
float[] processed = new float[ results.length / 4 ];
int index = 0;
for( int x = 0; x < processed.length; x ++ )
{
index = x * 2;
processed[ x ] = 20.0f * (float)Math.log10(
( ( results[ index ] * results[ index ] ) +
( results[ index + 1 ] * results[ index + 1 ] ) ) * dftBinSizeScalor );
}
dispatch( processed );
}
}