Package de.gsi.math.spectra
Class SpectrumTools
- java.lang.Object
-
- de.gsi.math.spectra.SpectrumTools
-
public class SpectrumTools extends java.lang.ObjectClass implements frequency interpolation of spectral peaks. The main idea behind these algorithm is: The resolution of frequency estimates that are solely based on the value of the highest bin of an FFT or DTFT spectrum is limited by the binning of the frequency spectrum, which assuming an FFT spectrum is determined by the number of samples N that have been used to compute the spectra (resolution = 1/N). The functions in this class provide algorithms that fit this frequency by taking the value not only of the highest but also adjacent bins into account. While the peak shape strongly depends on the underlying process, the gaussian interpolation gives typically the best results in most cases.
-
-
Constructor Summary
Constructors Constructor Description SpectrumTools()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static double[]computeFrequencyScale(int nMag)compute equidistant frequency axis based on the length of the magnitude spectrumstatic float[]computeFrequencyScaleFloat(int nMag)compute equidistant frequency axis based on the length of the magnitude spectrumstatic double[]computeMagnitudeSpectrum(double[] data)compute magnitude power spectrastatic double[]computeMagnitudeSpectrum(double[] data, boolean truncateDCNyq)compute magnitude power spectrastatic voidcomputeMagnitudeSpectrum(double[] data, int fromPos, int length, double[] ret, int toPos, boolean truncateDCNyq)compute magnitude power spectrastatic float[]computeMagnitudeSpectrum(float[] data)compute magnitude power spectrastatic float[]computeMagnitudeSpectrum(float[] data, boolean truncateDCNyq)compute magnitude power spectrastatic voidcomputeMagnitudeSpectrum(float[] data, int fromPos, int length, float[] ret, int toPos, boolean truncateDCNyq)compute magnitude power spectrastatic double[]computeMagnitudeSpectrum_dB(double[] data, boolean truncateDCNyq)compute magnitude power spectra in decibelstatic voidcomputeMagnitudeSpectrum_dB(double[] data, int fromPos, int length, double[] ret, int toPos, boolean truncateDCNyq)compute magnitude power spectra in decibelstatic float[]computeMagnitudeSpectrum_dB(float[] data, boolean truncateDCNyq)compute magnitude power spectra in decibelstatic voidcomputeMagnitudeSpectrum_dB(float[] data, int fromPos, int length, float[] ret, int toPos, boolean truncateDCNyq)compute magnitude power spectra in decibelstatic double[][]computeMaxima(double[] data)compute maximastatic double[][]computeMinima(double[] data)compute minimastatic double[]computePhaseSpectrum(double[] data)compute phase spectra ([-PI,+PI])static float[]computePhaseSpectrum(float[] data)compute phase spectra ([-PI,+PI])static double[][]filterPeaksHarmonics(double[][] peaks, double[] magnitude, double estimate, boolean useRealAmplitudes)static double[][]filterPeaksSignalToNoise(double[][] peaks, double snRatio, boolean dBScale)static doubleinterpolateBaryCentre(double[] data, int index)interpolation using a bary-centre approachstatic doubleinterpolateGaussian(double[] data, int index)interpolation using a Gaussian interpolationstatic doubleinterpolateNAFF(double[] data, int index)interpolation using a NAFF/SUSSIX based approachstatic doubleinterpolateParabolic(double[] data, int index)interpolation using a parabolic interpolationstatic double[]interpolateSpectrum(double[] data, int noversampling)static voidmain(java.lang.String[] args)
-
-
-
Method Detail
-
computeFrequencyScale
public static double[] computeFrequencyScale(int nMag)
compute equidistant frequency axis based on the length of the magnitude spectrum- Parameters:
nMag- requested length of output vector- Returns:
- computed [0.0, 0.5] frequency scale
-
computeFrequencyScaleFloat
public static float[] computeFrequencyScaleFloat(int nMag)
compute equidistant frequency axis based on the length of the magnitude spectrum- Parameters:
nMag- requested length of output vector- Returns:
- computed [0.0, 0.5] frequency scale
-
computeMagnitudeSpectrum
public static double[] computeMagnitudeSpectrum(double[] data)
compute magnitude power spectra- Parameters:
data- the input data Since due to intrinsic uncertainties the DC and Nyquist frequency components are less representative for the given spectrum, their values are set to their adjacent frequency bins.- Returns:
- computed magnitude spectrum
- See Also:
for the expected spectra layout
-
computeMagnitudeSpectrum
public static double[] computeMagnitudeSpectrum(double[] data, boolean truncateDCNyq)compute magnitude power spectra- Parameters:
data- the input datatruncateDCNyq- true: whether to smooth spectra and to ZOH the DC and Nyquist frequencies- Returns:
- computed magnitude spectrum
- See Also:
for the expected spectra layout
-
computeMagnitudeSpectrum
public static void computeMagnitudeSpectrum(double[] data, int fromPos, int length, double[] ret, int toPos, boolean truncateDCNyq)compute magnitude power spectra- Parameters:
data- the input datafromPos- start of the data to readlength- length to read of the input dataret- the output datatoPos- the position to start writing the result totruncateDCNyq- true: whether to smooth spectra and to ZOH the DC and Nyquist frequencies- See Also:
for the expected spectra layout
-
computeMagnitudeSpectrum
public static float[] computeMagnitudeSpectrum(float[] data)
compute magnitude power spectra- Parameters:
data- the input data Since due to intrinsic uncertainties the DC and Nyquist frequency components are less representative for the given spectrum, their values are set to their adjacent frequency bins.- Returns:
- computed magnitude spectrum
- See Also:
for the expected spectra layout
-
computeMagnitudeSpectrum
public static float[] computeMagnitudeSpectrum(float[] data, boolean truncateDCNyq)compute magnitude power spectra- Parameters:
data- the input datatruncateDCNyq- true: whether to smooth spectra and to ZOH the DC and Nyquist frequencies- Returns:
- computed magnitude spectrum
- See Also:
for the expected spectra layout
-
computeMagnitudeSpectrum
public static void computeMagnitudeSpectrum(float[] data, int fromPos, int length, float[] ret, int toPos, boolean truncateDCNyq)compute magnitude power spectra- Parameters:
data- the input datafromPos- starting position of the datalength- length of the dataret- the output data, should be an array of data.length/2toPos- position to write to in the output arraytruncateDCNyq- true: whether to smooth spectra and to ZOH the DC and Nyquist frequencies- See Also:
for the expected spectra layout
-
computeMagnitudeSpectrum_dB
public static double[] computeMagnitudeSpectrum_dB(double[] data, boolean truncateDCNyq)compute magnitude power spectra in decibel- Parameters:
data- the input datatruncateDCNyq- true: whether to smooth spectra and to ZOH the DC and Nyquist frequencies- Returns:
- computed magnitude spectrum in [dB]
- See Also:
for the expected spectra layout
-
computeMagnitudeSpectrum_dB
public static void computeMagnitudeSpectrum_dB(double[] data, int fromPos, int length, double[] ret, int toPos, boolean truncateDCNyq)compute magnitude power spectra in decibel- Parameters:
data- the input datafromPos- starting position of the datalength- length of the dataret- the output data, should be an array of data.length/2toPos- position to write to in the output arraytruncateDCNyq- true: whether to smooth spectra and to ZOH the DC and Nyquist frequencies- See Also:
for the expected spectra layout
-
computeMagnitudeSpectrum_dB
public static float[] computeMagnitudeSpectrum_dB(float[] data, boolean truncateDCNyq)compute magnitude power spectra in decibel- Parameters:
data- the input datatruncateDCNyq- true: whether to smooth spectra and to ZOH the DC and Nyquist frequencies- Returns:
- computed magnitude spectrum in [dB]
- See Also:
for the expected spectra layout
-
computeMagnitudeSpectrum_dB
public static void computeMagnitudeSpectrum_dB(float[] data, int fromPos, int length, float[] ret, int toPos, boolean truncateDCNyq)compute magnitude power spectra in decibel- Parameters:
data- the input datafromPos- starting position of the datalength- length of the dataret- the output data, should be an array of data.length/2toPos- position to write to in the output arraytruncateDCNyq- true: whether to smooth spectra and to ZOH the DC and Nyquist frequencies- See Also:
for the expected spectra layout
-
computeMaxima
public static double[][] computeMaxima(double[] data)
compute maxima- Parameters:
data- input data- Returns:
- maxima locations
-
computeMinima
public static double[][] computeMinima(double[] data)
compute minima- Parameters:
data- input data- Returns:
- computed minima
-
computePhaseSpectrum
public static double[] computePhaseSpectrum(double[] data)
compute phase spectra ([-PI,+PI])- Parameters:
data- the input data- Returns:
- computed phase spectrum
- See Also:
for the expected spectra layout
-
computePhaseSpectrum
public static float[] computePhaseSpectrum(float[] data)
compute phase spectra ([-PI,+PI])- Parameters:
data- the input data- Returns:
- phase spectrum
- See Also:
for the expected spectra layout
-
filterPeaksHarmonics
public static double[][] filterPeaksHarmonics(double[][] peaks, double[] magnitude, double estimate, boolean useRealAmplitudes)
-
filterPeaksSignalToNoise
public static double[][] filterPeaksSignalToNoise(double[][] peaks, double snRatio, boolean dBScale)
-
interpolateBaryCentre
public static double interpolateBaryCentre(double[] data, int index)interpolation using a bary-centre approach- Parameters:
data- data arrayindex- 0< index < data.length, location of the to be interpolated peak- Returns:
- interpolated bary centre
-
interpolateGaussian
public static double interpolateGaussian(double[] data, int index)interpolation using a Gaussian interpolation- Parameters:
data- data arrayindex- 0< index < data.length, location of the to be interpolated peak- Returns:
- interpolated gauss index
-
interpolateNAFF
public static double interpolateNAFF(double[] data, int index)interpolation using a NAFF/SUSSIX based approach- Parameters:
data- data arrayindex- 0< index < data.length, location of the to be interpolated peak- Returns:
- NAFF-interpolated peak position
-
interpolateParabolic
public static double interpolateParabolic(double[] data, int index)interpolation using a parabolic interpolation- Parameters:
data- data arrayindex- 0< index < data.length, location of the to be interpolated peak- Returns:
- parabolic-interpolated peak position
-
interpolateSpectrum
public static double[] interpolateSpectrum(double[] data, int noversampling)
-
main
public static void main(java.lang.String[] args)
-
-