Необходимо исправить программу.
- Войдите на сайт для отправки комментариев
Сб, 23/03/2019 - 00:20
Здравствуйте
1. Серийный плоттер очень медленный по сравнению с оригиналом.
2. Программа не реагирует на изменение сигнала, она должна реагировать на изменение частоты = сдвиг фазы.
Предложения с ценой отправлять здесь.
galinakorczak@hotmail.com
Оригинальная программа
и моя модификация.
#include "arduinoFFT.h"
#include <math.h>
#define SAMPLES 128 //Must be a power of 2
#define SAMPLING_FREQUENCY 1000 //Hz, must be less than 10000 due to ADC
////////////////////
int i;
int A;
int amplitude;
const uint16_t samples = 64; //This value MUST ALWAYS be a power of 2
const double signalFrequency = 1000;
const double samplingFrequency = 5000;
//const uint8_t amplitude = 100;
///////////////////
arduinoFFT FFT = arduinoFFT();
unsigned int sampling_period_us;
unsigned long microseconds;
double vReal[SAMPLES];
double vImag[SAMPLES];
void setup() {
Serial.begin(115200);
sampling_period_us = round(1000000 * (1.0 / SAMPLING_FREQUENCY));
}
void loop() {
/*SAMPLING*/
for (int i = 0; i < SAMPLES; i++)
// for (uint16_t i = 0; i < SAMPLES; i++)
{
microseconds = micros(); //Overflows after around 70 minutes!
vReal[i] = analogRead(PA7);
vImag[i] = 0;
while (micros() < (microseconds + sampling_period_us)) {
}
////////////////////////
float A = atan( vImag[i] / vReal[i] );
double cycles = (((samples - 1) * signalFrequency) / samplingFrequency);
for (uint16_t i = 0; i < SAMPLES; i++)
{
// const uint8_t amplitude = analogRead(PA7);
uint8_t amplitude[i] = analogRead(PA7);
amplitude[i] = 0
// amplitude = analogRead(PA7);
vReal[i] = int8_t((amplitude * (sin((i * (twoPi * cycles)) / samples))) / 2.0);
vImag[i] = int8_t((amplitude * (cos((i * (twoPi * cycles)) / samples))) / 2.0);
}
////////////////////////
}
/*FFT*/
FFT.Windowing(vReal, SAMPLES, FFT_WIN_TYP_HAMMING, FFT_FORWARD);
FFT.Compute(vReal, vImag, SAMPLES, FFT_FORWARD);
FFT.ComplexToMagnitude(vReal, vImag, SAMPLES);
double peak = FFT.MajorPeak(vReal, SAMPLES, SAMPLING_FREQUENCY);
/*PRINT RESULTS*/
//Serial.println(peak); //Print out what frequency is the most dominant.
for (int i = 0; i < (SAMPLES / 2); i++)
// for (uint16_t i = 0; i < SAMPLES/2; i++)
{
/*View all these three lines in serial terminal to see which frequencies has which amplitudes*/
//Serial.print((i * 1.0 * SAMPLING_FREQUENCY) / SAMPLES, 1);
//Serial.print(" ");
// Serial.println(vReal[i], 1); //View only this line in serial plotter to visualize the bins
Serial.println(A);
}
}
Р е а л и з у е м о - maslachenko767@mail.ru , консультации, подбор компонентов бесплатно, гарантии