kopia lustrzana https://github.com/kosme/arduinoFFT
Remove new printing methods on examples
rodzic
e1831a9bdd
commit
0b3271b489
|
@ -45,6 +45,11 @@ Input vectors receive computed results from FFT
|
|||
double vReal[samples];
|
||||
double vImag[samples];
|
||||
|
||||
#define SCL_INDEX 0x00
|
||||
#define SCL_TIME 0x01
|
||||
#define SCL_FREQUENCY 0x02
|
||||
#define SCL_PLOT 0x03
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
|
@ -63,20 +68,46 @@ void loop()
|
|||
}
|
||||
/* Print the results of the simulated sampling according to time */
|
||||
Serial.println("Data:");
|
||||
FFT.PrintSignal(vReal, samples, samplingFrequency);
|
||||
PrintVector(vReal, samples, SCL_TIME);
|
||||
FFT.Windowing(vReal, samples, FFT_WIN_TYP_HAMMING, FFT_FORWARD); /* Weigh data */
|
||||
Serial.println("Weighed data:");
|
||||
FFT.PrintSignal(vReal, samples, samplingFrequency);
|
||||
PrintVector(vReal, samples, SCL_TIME);
|
||||
FFT.Compute(vReal, vImag, samples, FFT_FORWARD); /* Compute FFT */
|
||||
Serial.println("Computed Real values:");
|
||||
FFT.PrintVector(vReal, samples, samplingFrequency);
|
||||
PrintVector(vReal, samples, SCL_INDEX);
|
||||
Serial.println("Computed Imaginary values:");
|
||||
FFT.PrintVector(vImag, samples, samplingFrequency);
|
||||
PrintVector(vImag, samples, SCL_INDEX);
|
||||
FFT.ComplexToMagnitude(vReal, vImag, samples); /* Compute magnitudes */
|
||||
Serial.println("Computed magnitudes:");
|
||||
FFT.PrintSpectrum(vReal, samples, samplingFrequency);
|
||||
PrintVector(vReal, (samples >> 1), SCL_FREQUENCY);
|
||||
double x = FFT.MajorPeak(vReal, samples, samplingFrequency);
|
||||
Serial.println(x, 6);
|
||||
while(1); /* Run Once */
|
||||
// delay(2000); /* Repeat after delay */
|
||||
}
|
||||
|
||||
void PrintVector(double *vData, uint16_t bufferSize, uint8_t scaleType)
|
||||
{
|
||||
for (uint16_t i = 0; i < bufferSize; i++)
|
||||
{
|
||||
double abscissa;
|
||||
/* Print abscissa value */
|
||||
switch (scaleType)
|
||||
{
|
||||
case SCL_INDEX:
|
||||
abscissa = (i * 1.0);
|
||||
break;
|
||||
case SCL_TIME:
|
||||
abscissa = ((i * 1.0) / samplingFrequency);
|
||||
break;
|
||||
case SCL_FREQUENCY:
|
||||
abscissa = ((i * 1.0 * samplingFrequency) / samples);
|
||||
break;
|
||||
}
|
||||
Serial.print(abscissa, 6);
|
||||
if(scaleType==SCL_FREQUENCY)
|
||||
Serial.print(" Hz");
|
||||
Serial.println(vData[i], 4);
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
|
|
|
@ -45,6 +45,11 @@ double vImag[samples];
|
|||
|
||||
unsigned long time;
|
||||
|
||||
#define SCL_INDEX 0x00
|
||||
#define SCL_TIME 0x01
|
||||
#define SCL_FREQUENCY 0x02
|
||||
#define SCL_PLOT 0x03
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
|
@ -66,19 +71,19 @@ void loop()
|
|||
vImag[i] = 0; //Reset the imaginary values vector for each new frequency
|
||||
}
|
||||
/*Serial.println("Data:");
|
||||
FFT.PrintSignal(vReal, samples, samplingFrequency);*/
|
||||
PrintVector(vReal, samples, SCL_TIME);*/
|
||||
time=millis();
|
||||
FFT.Windowing(vReal, samples, FFT_WIN_TYP_HAMMING, FFT_FORWARD); /* Weigh data */
|
||||
/*Serial.println("Weighed data:");
|
||||
FFT.PrintSignal(vReal, samples, samplingFrequency);*/
|
||||
PrintVector(vReal, samples, SCL_TIME);*/
|
||||
FFT.Compute(vReal, vImag, samples, exponent, FFT_FORWARD); /* Compute FFT */
|
||||
/*Serial.println("Computed Real values:");
|
||||
FFT.PrintVector(vReal, samples, samplingFrequency);
|
||||
PrintVector(vReal, samples, SCL_INDEX);
|
||||
Serial.println("Computed Imaginary values:");
|
||||
FFT.PrintVector(vImag, samples, samplingFrequency);*/
|
||||
PrintVector(vImag, samples, SCL_INDEX);*/
|
||||
FFT.ComplexToMagnitude(vReal, vImag, samples); /* Compute magnitudes */
|
||||
/*Serial.println("Computed magnitudes:");
|
||||
FFT.PrintSpectrum(vReal, samples, samplingFrequency);*/
|
||||
PrintVector(vReal, (samples >> 1), SCL_FREQUENCY);*/
|
||||
double x = FFT.MajorPeak(vReal, samples, sampling);
|
||||
Serial.print(frequency);
|
||||
Serial.print(": \t\t");
|
||||
|
@ -90,3 +95,29 @@ void loop()
|
|||
}
|
||||
while(1); /* Run Once */
|
||||
}
|
||||
|
||||
void PrintVector(double *vData, uint16_t bufferSize, uint8_t scaleType)
|
||||
{
|
||||
for (uint16_t i = 0; i < bufferSize; i++)
|
||||
{
|
||||
double abscissa;
|
||||
/* Print abscissa value */
|
||||
switch (scaleType)
|
||||
{
|
||||
case SCL_INDEX:
|
||||
abscissa = (i * 1.0);
|
||||
break;
|
||||
case SCL_TIME:
|
||||
abscissa = ((i * 1.0) / samplingFrequency);
|
||||
break;
|
||||
case SCL_FREQUENCY:
|
||||
abscissa = ((i * 1.0 * samplingFrequency) / samples);
|
||||
break;
|
||||
}
|
||||
Serial.print(abscissa, 6);
|
||||
if(scaleType==SCL_FREQUENCY)
|
||||
Serial.print(" Hz");
|
||||
Serial.println(vData[i], 4);
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
|
|
|
@ -38,6 +38,11 @@ Input vectors receive computed results from FFT
|
|||
double vReal[samples];
|
||||
double vImag[samples];
|
||||
|
||||
#define SCL_INDEX 0x00
|
||||
#define SCL_TIME 0x01
|
||||
#define SCL_FREQUENCY 0x02
|
||||
#define SCL_PLOT 0x03
|
||||
|
||||
void setup()
|
||||
{
|
||||
sampling_period_us = round(1000000*(1.0/SAMPLING_FREQUENCY));
|
||||
|
@ -60,20 +65,46 @@ void loop()
|
|||
}
|
||||
/* Print the results of the sampling according to time */
|
||||
Serial.println("Data:");
|
||||
FFT.PrintSignal(vReal, samples, samplingFrequency);
|
||||
PrintVector(vReal, samples, SCL_TIME);
|
||||
FFT.Windowing(vReal, samples, FFT_WIN_TYP_HAMMING, FFT_FORWARD); /* Weigh data */
|
||||
Serial.println("Weighed data:");
|
||||
FFT.PrintSignal(vReal, samples, samplingFrequency);
|
||||
PrintVector(vReal, samples, SCL_TIME);
|
||||
FFT.Compute(vReal, vImag, samples, FFT_FORWARD); /* Compute FFT */
|
||||
Serial.println("Computed Real values:");
|
||||
FFT.PrintVector(vReal, samples, samplingFrequency);
|
||||
PrintVector(vReal, samples, SCL_INDEX);
|
||||
Serial.println("Computed Imaginary values:");
|
||||
FFT.PrintVector(vImag, samples, samplingFrequency);
|
||||
PrintVector(vImag, samples, SCL_INDEX);
|
||||
FFT.ComplexToMagnitude(vReal, vImag, samples); /* Compute magnitudes */
|
||||
Serial.println("Computed magnitudes:");
|
||||
FFT.PrintSpectrum(vReal, samples, samplingFrequency);
|
||||
PrintVector(vReal, (samples >> 1), SCL_FREQUENCY);
|
||||
double x = FFT.MajorPeak(vReal, samples, samplingFrequency);
|
||||
Serial.println(x, 6); //Print out what frequency is the most dominant.
|
||||
while(1); /* Run Once */
|
||||
// delay(2000); /* Repeat after delay */
|
||||
}
|
||||
|
||||
void PrintVector(double *vData, uint16_t bufferSize, uint8_t scaleType)
|
||||
{
|
||||
for (uint16_t i = 0; i < bufferSize; i++)
|
||||
{
|
||||
double abscissa;
|
||||
/* Print abscissa value */
|
||||
switch (scaleType)
|
||||
{
|
||||
case SCL_INDEX:
|
||||
abscissa = (i * 1.0);
|
||||
break;
|
||||
case SCL_TIME:
|
||||
abscissa = ((i * 1.0) / samplingFrequency);
|
||||
break;
|
||||
case SCL_FREQUENCY:
|
||||
abscissa = ((i * 1.0 * samplingFrequency) / samples);
|
||||
break;
|
||||
}
|
||||
Serial.print(abscissa, 6);
|
||||
if(scaleType==SCL_FREQUENCY)
|
||||
Serial.print(" Hz");
|
||||
Serial.println(vData[i], 4);
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
|
|
|
@ -46,6 +46,11 @@ Input vectors receive computed results from FFT
|
|||
double vReal[samples];
|
||||
double vImag[samples];
|
||||
|
||||
#define SCL_INDEX 0x00
|
||||
#define SCL_TIME 0x01
|
||||
#define SCL_FREQUENCY 0x02
|
||||
#define SCL_PLOT 0x03
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
|
@ -64,8 +69,36 @@ void loop()
|
|||
FFT.Windowing(vReal, samples, FFT_WIN_TYP_HAMMING, FFT_FORWARD); /* Weigh data */
|
||||
FFT.Compute(vReal, vImag, samples, FFT_FORWARD); /* Compute FFT */
|
||||
FFT.ComplexToMagnitude(vReal, vImag, samples); /* Compute magnitudes */
|
||||
FFT.PlotSpectrum(vReal, samples, samplingFrequency);
|
||||
PrintVector(vReal, samples>>1, SCL_PLOT);
|
||||
double x = FFT.MajorPeak(vReal, samples, samplingFrequency);
|
||||
while(1); /* Run Once */
|
||||
// delay(2000); /* Repeat after delay */
|
||||
}
|
||||
|
||||
void PrintVector(double *vData, uint16_t bufferSize, uint8_t scaleType)
|
||||
{
|
||||
for (uint16_t i = 0; i < bufferSize; i++)
|
||||
{
|
||||
double abscissa;
|
||||
/* Print abscissa value */
|
||||
switch (scaleType)
|
||||
{
|
||||
case SCL_INDEX:
|
||||
abscissa = (i * 1.0);
|
||||
break;
|
||||
case SCL_TIME:
|
||||
abscissa = ((i * 1.0) / samplingFrequency);
|
||||
break;
|
||||
case SCL_FREQUENCY:
|
||||
abscissa = ((i * 1.0 * samplingFrequency) / samples);
|
||||
break;
|
||||
}
|
||||
if(scaleType!=SCL_PLOT)
|
||||
{
|
||||
Serial.print(abscissa, 6);
|
||||
Serial.print(" ");
|
||||
}
|
||||
Serial.println(vData[i], 4);
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue