Hi, I'm using arduino mega2560 and sensor microwave Based on doppler effect and i applicated librairy fft To extract frequency and it's working perfectly, but i don't know how to calcluate the amplitude ?
Post your code (in code tags - use the </> icon).
Pete
Hi,Hi,thank you for replied
I'm using librairy fft posted by arduino
this is my code
#define LOG_OUT 1
#define FFT_N 256
#include <FFT.h>
int bin = 0;
int frequency = 0;
int resolution = 9615 / 256;
int maxLogOut = 0;
void setup() {
Serial.begin(9600);
ADCSRA |= (1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0); //set adc prescaler=128
ADMUX = 0x40; // use adc0
ADCSRA |= (1<<ADATE); //enable auto trigger
ADCSRA |= (1<<ADEN); //enable ADC
ADCSRA |= (1<<ADSC); //start ADC measurements
}
void loop()
{
cli();
for (int i = 0 ; i < 512 ; i += 2)
{
while(!(ADCSRA & 0x10));
ADCSRA |=(1<<ADSC);
byte m = ADCL;
byte j = ADCH;
int k = (j << 8) | m;
k -= 0x0200;
k <<= 6;
fft_input[i] = k;
fft_input[i+1] = 0;
}
fft_window(); // window the data for better frequency response
fft_reorder(); // reorder the data before doing the fft
fft_run(); // process the data in the fft
fft_mag_log(); // take the output of the fft
sei();
bin = 0;
int k=0;
int u =0;
int w =0;
int f =2;
for( f =2;f<128;f++)
{
if ( fft_log_out[f]>k)
{
k=fft_log_out[f];
w=f;
}
}
u = w*resolution;
Serial.print(" frequency is : ");
Serial.println(u);
delay(250);
for amplitude i don't know how i can calculated
According to a comment in FFT.h, fft_mag_log returns 16log2((img^2 + real^2)^0.5) where (img^2 + real^2)^0.5 is the amplitude. So we have:
k = 16log2((img^2 + real^2)^0.5)
k = 16*log2(amplitude)
k/16 = log2(amplitude)
amplitude = 2^(k/16)
k is an integer (uint8) so in C this would be
amplitude = 2 << (k/16);
Pete
Or use the LIN_OUT keyword and get the magnitude directly via the fft_mag_lin array.
I suggest to read the documentation of any code you wish to use. It will save everyone some time.
i'm grateful
i add just this instruction " amplitude = 2<<(x/16);" in my programme
fft_window(); // window the data for better frequency response
fft_reorder(); // reorder the data before doing the fft
fft_run(); // process the data in the fft
fft_mag_log(); // take the output of the fft
sei();
bin = 0;
uint8_t x=0;
int u =0;
int w =0;
int f =2;
for( f =2;f<128;f++)
{
if ( fft_log_out[f]>x)
{
x=fft_log_out[f];
w=f;
}
}
u = w*resolution;
amplitude = 2<<(x/16);
Serial.println(amplitude);
thank you all of you