kopia lustrzana https://github.com/kosme/arduinoFFT
Add clearer printing and ploting functions
rodzic
7ace8062ea
commit
934ff09b95
|
@ -148,6 +148,26 @@ void arduinoFFT::Windowing(double *vData, uint16_t samples, uint8_t windowType,
|
|||
}
|
||||
}
|
||||
|
||||
void arduinoFFT::PrintVector(double *vData, uint16_t samples, double samplingFrequency)
|
||||
{
|
||||
PrintArray(vData,samples, samplingFrequency, SCL_INDEX);
|
||||
}
|
||||
|
||||
void arduinoFFT::PrintSignal(double *vData, uint16_t samples, double samplingFrequency)
|
||||
{
|
||||
PrintArray(vData,samples, samplingFrequency, SCL_TIME);
|
||||
}
|
||||
|
||||
void arduinoFFT::PrintSpectrum(double *vData, uint16_t samples, double samplingFrequency)
|
||||
{
|
||||
PrintArray(vData,samples, samplingFrequency, SCL_FREQUENCY);
|
||||
}
|
||||
|
||||
void arduinoFFT::PlotSpectrum(double *vData, uint16_t samples, double samplingFrequency)
|
||||
{
|
||||
PrintArray(vData,samples, samplingFrequency, SCL_PLOT);
|
||||
}
|
||||
|
||||
double arduinoFFT::MajorPeak(double *vD, uint16_t samples, double samplingFrequency)
|
||||
{
|
||||
double maxY = 0;
|
||||
|
@ -166,6 +186,14 @@ double arduinoFFT::MajorPeak(double *vD, uint16_t samples, double samplingFreque
|
|||
return(interpolatedX);
|
||||
}
|
||||
|
||||
uint8_t arduinoFFT::Exponent(uint16_t value)
|
||||
{
|
||||
/* Calculates the base 2 logarithm of a value */
|
||||
uint8_t result = 0;
|
||||
while (((value >> result) & 1) != 1) result++;
|
||||
return(result);
|
||||
}
|
||||
|
||||
/* Private functions */
|
||||
|
||||
void arduinoFFT::Swap(double *x, double *y)
|
||||
|
@ -175,10 +203,34 @@ void arduinoFFT::Swap(double *x, double *y)
|
|||
*y = temp;
|
||||
}
|
||||
|
||||
uint8_t arduinoFFT::Exponent(uint16_t value)
|
||||
void arduinoFFT::PrintArray(double *vData, uint16_t samples, double samplingFrequency, uint8_t scaleType)
|
||||
{
|
||||
/* Calculates the base 2 logarithm of a value */
|
||||
uint8_t result = 0;
|
||||
while (((value >> result) & 1) != 1) result++;
|
||||
return(result);
|
||||
uint16_t bufferSize = samples;
|
||||
if((scaleType == SCL_FREQUENCY)||(scaleType == SCL_PLOT))
|
||||
bufferSize = bufferSize>>1;
|
||||
for (uint16_t i = 0; i < bufferSize; i++)
|
||||
{
|
||||
double abscissa;
|
||||
switch (scaleType)
|
||||
{
|
||||
case SCL_INDEX:
|
||||
abscissa = (i * 1.0);
|
||||
break;
|
||||
case SCL_TIME:
|
||||
abscissa = ((i * 1.0) / samplingFrequency);
|
||||
break;
|
||||
case SCL_FREQUENCY:
|
||||
case SCL_PLOT:
|
||||
abscissa = ((i * 1.0 * samplingFrequency) / samples);
|
||||
break;
|
||||
}
|
||||
if(scaleType!=SCL_PLOT){
|
||||
Serial.print(abscissa, 6);
|
||||
if(scaleType==SCL_FREQUENCY)
|
||||
Serial.print(" Hz");
|
||||
Serial.print(" ");
|
||||
}
|
||||
Serial.println(vData[i], 4);
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
|
|
|
@ -38,10 +38,14 @@
|
|||
#include "types.h"
|
||||
#endif
|
||||
|
||||
#define FFT_LIB_REV 0x02c
|
||||
#define FFT_LIB_REV 0x14
|
||||
/* Custom constants */
|
||||
#define FFT_FORWARD 0x01
|
||||
#define FFT_REVERSE 0x00
|
||||
#define SCL_INDEX 0x00
|
||||
#define SCL_TIME 0x01
|
||||
#define SCL_FREQUENCY 0x02
|
||||
#define SCL_PLOT 0x03
|
||||
/* Windowing type */
|
||||
#define FFT_WIN_TYP_RECTANGLE 0x00 /* rectangle (Box car) */
|
||||
#define FFT_WIN_TYP_HAMMING 0x01 /* hamming */
|
||||
|
@ -64,6 +68,10 @@ public:
|
|||
void ComplexToMagnitude(double *vReal, double *vImag, uint16_t samples);
|
||||
void Compute(double *vReal, double *vImag, uint16_t samples, uint8_t dir);
|
||||
void Compute(double *vReal, double *vImag, uint16_t samples, uint8_t power, uint8_t dir);
|
||||
void PrintVector(double *vData, uint16_t samples, double samplingFrequency);
|
||||
void PrintSignal(double *vData, uint16_t samples, double samplingFrequency);
|
||||
void PrintSpectrum(double *vData, uint16_t samples, double samplingFrequency);
|
||||
void PlotSpectrum(double *vData, uint16_t samples, double samplingFrequency);
|
||||
double MajorPeak(double *vD, uint16_t samples, double samplingFrequency);
|
||||
uint8_t Revision(void);
|
||||
void Windowing(double *vData, uint16_t samples, uint8_t windowType, uint8_t dir);
|
||||
|
@ -72,6 +80,7 @@ public:
|
|||
private:
|
||||
/* Functions */
|
||||
void Swap(double *x, double *y);
|
||||
void PrintArray(double *vData, uint16_t samples, double samplingFrequency, uint8_t scaleType);
|
||||
|
||||
};
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue