ADXL mm/s

frohr

Well-known member
Hi all,
I do not want to post my code because it is not important for now.
I wan to use Tennsy 4.0 and ADXL1005 (eval board) to measure mm/s.
I will read samples from pin A0 to buffer of size 16384. (every reading every 50 micros)
I will use alpha low and alpha hight to have filter bandpass 10-1000Hz.
I will use Arduino FFT library and process the buffer with Hanning window.
Then I will calculate m/s2 for every frequency and then total m/s2

BUT - arduino FFT library calculate magnitude - no amplitude - and the result is not ok.

How to calculate amplitude?
Any suggestion for this case?
Thak you!

Michal
 
First an accelerometer gives acceleration readings, m/s^2, not m/s

Secondly magnitude _is_ amplitude (without the phase).

To calculate totals you have to add magnitude-squared, which is proportional to power, which adds linearly (amplitudes
only add linearly for coherent waves, and different frequency bins are by definition non-coherent).
 
OK, I have

#define BUFFER_SIZE 16384

I use ADC

void START_ADC ()
{
pole=0;
startTimerValue = timer.begin(TIMER, period);
timer.priority (0);
ADC_ISR();

}
void TIMER()
{
adc->adc0->startSingleRead(readPin);
adc->adc0->enableInterrupts(ADC_ISR);
}
void ADC_ISR(void)
{
adc_val = adc->adc0->readSingle();
if (pole < BUFFER_SIZE) BUFFER_ADC[pole++] = adc_val;
asm volatile("dsb");
}

Then calculation:

void CALCULATE_MM ()
{

period = 50;
START_ADC ();
delay (2000);

alpha_LOW = 0.003;// 10hz
alpha_HIGH =0.145;// 1000 Hz

Arms = 0;
Vrms = 0;
SUM_Vrms = 0;
SUM_Vrms_2 = 0;
for(int i=0 ;i <(BUFFER_SIZE); i++)
{
micros_0 = 0;
Filter_LOWPASS = (BUFFER_ADC * alpha_LOW) + (Filter_LOWPASS * (1.0 - alpha_LOW));
Filter_HIGHPASS = (BUFFER_ADC* alpha_HIGH) + (Filter_HIGHPASS * (1.0 - alpha_HIGH));
Filter_BANDPASS = Filter_HIGHPASS-Filter_LOWPASS;
vReal = Filter_BANDPASS / BUFFER_SIZE;
vImag = 0;
while(micros_0 < period)
{
}
}
FFT.Windowing(vReal, BUFFER_SIZE, FFT_WIN_TYP_HANN, FFT_FORWARD);
FFT.Compute(vReal, vImag, BUFFER_SIZE, FFT_FORWARD);
FFT.ComplexToMagnitude(vReal, vImag,BUFFER_SIZE);

for(int i=1;i <(BUFFER_SIZE/16); i++)

{
//1 - frequency
f = (i * 1.0 * 20000) /BUFFER_SIZE;
//2 - m/s^2
Arms = vReal*9.8;
//3 - mm/s
Vrms = (1000*Arms)/(6.28*(f));
// 4 SUM
SUM_Vrms = SUM_Vrms + Vrms;
}
// 5 power2
SUM_Vrms_2 =sqrt(SUM_Vrms);
// 6 peak to peak
SUM_Vrms_PP= SUM_Vrms_2;
// 7 0 to peak
SUM_Vrms_0P= SUM_Vrms_PP/2;
// 8 RMS
SUM_Vrms_RMS= 0.707*SUM_Vrms_0P;
}


Any suggestion?
 
Back
Top