kopia lustrzana https://github.com/kosme/arduinoFFT
- Better documentation of example.
rodzic
81296ca08f
commit
0bb257ec70
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
|
|
||||||
Example of use of the FFT libray
|
Example of use of the FFT libray
|
||||||
Copyright (C) 2011 Didier Longueville
|
Copyright (C) 2014 Enrique Condes
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
@ -18,16 +18,16 @@
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "PlainFFT.h"
|
#include "arduinoFFT.h"
|
||||||
|
|
||||||
PlainFFT FFT = PlainFFT(); /* Create FFT object */
|
arduinoFFT FFT = arduinoFFT(); /* Create FFT object */
|
||||||
/*
|
/*
|
||||||
These values can be changed in order to evaluate the functions
|
These values can be changed in order to evaluate the functions
|
||||||
*/
|
*/
|
||||||
const uint16_t samples = 64;
|
const uint16_t samples = 64; //This value MUST ALWAYS be a power of 2
|
||||||
double signalFrequency = 1000;
|
double signalFrequency = 1000;
|
||||||
double samplingFrequency = 5000;
|
double samplingFrequency = 5000;
|
||||||
uint8_t signalIntensity = 100;
|
uint8_t amplitude = 100;
|
||||||
/*
|
/*
|
||||||
These are the input and output vectors
|
These are the input and output vectors
|
||||||
Input vectors receive computed results from FFT
|
Input vectors receive computed results from FFT
|
||||||
|
@ -39,7 +39,8 @@ double vImag[samples];
|
||||||
#define SCL_TIME 0x01
|
#define SCL_TIME 0x01
|
||||||
#define SCL_FREQUENCY 0x02
|
#define SCL_FREQUENCY 0x02
|
||||||
|
|
||||||
void setup(){
|
void setup()
|
||||||
|
{
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
Serial.println("Ready");
|
Serial.println("Ready");
|
||||||
}
|
}
|
||||||
|
@ -47,15 +48,21 @@ void setup(){
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
/* Build raw data */
|
/* Build raw data */
|
||||||
double cycles = (((samples-1) * signalFrequency) / samplingFrequency);
|
double cycles = (((samples-1) * signalFrequency) / samplingFrequency); //Number of signal cycles that the sampling will read
|
||||||
for (uint8_t i = 0; i < samples; i++) {
|
for (uint8_t i = 0; i < samples; i++)
|
||||||
vReal[i] = uint8_t((signalIntensity * (sin((i * (6.2831 * cycles)) / samples) + 1.0)) / 2.0);
|
{
|
||||||
|
vReal[i] = uint8_t((amplitude * (sin((i * (6.2831 * cycles)) / samples))) / 2.0);/* Build data with positive and negative values*/
|
||||||
|
//vReal[i] = uint8_t((amplitude * (sin((i * (6.2831 * cycles)) / samples) + 1.0)) / 2.0);/* Build data displaced on the Y axis to include only positive values*/
|
||||||
}
|
}
|
||||||
|
Serial.println("Data:");
|
||||||
PrintVector(vReal, samples, SCL_TIME);
|
PrintVector(vReal, samples, SCL_TIME);
|
||||||
FFT.Windowing(vReal, samples, FFT_WIN_TYP_HAMMING, FFT_FORWARD); /* Weigh data */
|
FFT.Windowing(vReal, samples, FFT_WIN_TYP_HAMMING, FFT_FORWARD); /* Weigh data */
|
||||||
|
Serial.println("Weighed data:");
|
||||||
PrintVector(vReal, samples, SCL_TIME);
|
PrintVector(vReal, samples, SCL_TIME);
|
||||||
FFT.Compute(vReal, vImag, samples, FFT_FORWARD); /* Compute FFT */
|
FFT.Compute(vReal, vImag, samples, FFT_FORWARD); /* Compute FFT */
|
||||||
|
Serial.println("Computed Real values:");
|
||||||
PrintVector(vReal, samples, SCL_INDEX);
|
PrintVector(vReal, samples, SCL_INDEX);
|
||||||
|
Serial.println("Computed Imaginary values:");
|
||||||
PrintVector(vImag, samples, SCL_INDEX);
|
PrintVector(vImag, samples, SCL_INDEX);
|
||||||
FFT.ComplexToMagnitude(vReal, vImag, samples); /* Compute magnitudes */
|
FFT.ComplexToMagnitude(vReal, vImag, samples); /* Compute magnitudes */
|
||||||
PrintVector(vReal, (samples >> 1), SCL_FREQUENCY);
|
PrintVector(vReal, (samples >> 1), SCL_FREQUENCY);
|
||||||
|
@ -67,10 +74,12 @@ void loop()
|
||||||
|
|
||||||
void PrintVector(double *vData, uint8_t bufferSize, uint8_t scaleType)
|
void PrintVector(double *vData, uint8_t bufferSize, uint8_t scaleType)
|
||||||
{
|
{
|
||||||
for (uint16_t i = 0; i < bufferSize; i++) {
|
for (uint16_t i = 0; i < bufferSize; i++)
|
||||||
|
{
|
||||||
double abscissa;
|
double abscissa;
|
||||||
/* Print abscissa value */
|
/* Print abscissa value */
|
||||||
switch (scaleType) {
|
switch (scaleType)
|
||||||
|
{
|
||||||
case SCL_INDEX:
|
case SCL_INDEX:
|
||||||
abscissa = (i * 1.0);
|
abscissa = (i * 1.0);
|
||||||
break;
|
break;
|
||||||
|
|
Ładowanie…
Reference in New Issue