Skip to content

KickFFT unable to handle values less than 1V? #2

@Luke-Sgp

Description

@Luke-Sgp

Hi, I am using hall effect sensors and a ESP32 to sense for leakage flux on an induction motor. Currently, the code is designed to, among other things, read the summation of sine wave inputs from the hall effect sensors, convert it using the ESP32's onboard ADC. The inputs are 50Hz with Vmax less than 1V. The ADC is able to read values less than 1V - this was tested out by serial printing out the RMS values. But KickFFT seems unable to work with values less than 1V as the corresponding output I get is 0.

Is there such a limitation in KickFFT or would there be a way to work around this?

Thank you.

`#include <SPI.h>
#include <WiFi.h>
#include <ESPmDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include "KickFFT.h"

//**************Sampling frequency//
const float samplingFrequency = 2000.0; //Hz, must be less than 10000 due to ADC
float samples=2048.0;

uint16_t flux_FFT_samples=512;
float flux_samplingFrequency=500.0;
//Machine parameters//
float st_freq_mean;
float ed_freq_mean;
float funda_mean;
//Sensor sensitivity and amplification factors//
float amp_fact=1.0;
float ADC_factor=(amp_fact)
(3.3/4095.0);
//FFT variables
//

unsigned int sampling_period_us;
unsigned long microseconds;

float ind_FFT_real[512];
float sum_FFT_real[512];
uint32_t ind_mag[512];
uint32_t sum_mag[512];

uint16_t startIndex = 0;
uint16_t endIndex = 0;

float max_freq[2]; float max_mag[2];
float l_limit_freq;float u_limit_freq;
float maxi; float maxif;

int j;
int offlne_count=0;
uint16_t down_sample_count = 0;

//Sum flux variables******//
int SUM_SEL_A=17; ///A
int SUM_SEL_B=18; ///B
int SUM_SEL_C=19; ///C
//Individual flux variables//
int IND_SEL_A=21; ///D
int IND_SEL_B=22; ///E
int IND_SEL_C=23; ///F
//**********************************************************************************************************************************//
void setup()
{

pinMode(SUM_SEL_A, OUTPUT);
pinMode(SUM_SEL_B, OUTPUT);
pinMode(SUM_SEL_C, OUTPUT);
pinMode(IND_SEL_A, OUTPUT);
pinMode(IND_SEL_B, OUTPUT);
pinMode(IND_SEL_C, OUTPUT);

analogReadResolution(12);
sampling_period_us = round(1000000*(1.0/samplingFrequency));
Serial.begin(115200);

digitalWrite(SUM_SEL_A,HIGH);
digitalWrite(SUM_SEL_B,HIGH);
digitalWrite(SUM_SEL_C,HIGH);

digitalWrite(IND_SEL_A,LOW);
digitalWrite(IND_SEL_B,LOW);
digitalWrite(IND_SEL_C,LOW);

}

void loop()
{

microseconds = micros();
uint16_t m=0;
down_sample_count=0;
for(int i=0; i<samples; i++)
{
if(down_sample_count==0)
{

  ind_FFT_real[m]=ADC_factor*analogRead(33);         //Individual flux
  sum_FFT_real[m]=ADC_factor*analogRead(32);         //Summation flux
  m=m+1;
  
}
down_sample_count=down_sample_count+1;
if(down_sample_count==4){down_sample_count=0;}    

  while(micros() - microseconds < sampling_period_us){}
  microseconds += sampling_period_us;

}

Serial.print("m value:"); Serial.print("\t");Serial.println(m);

max_mag[0]=0.0;max_freq[0]=0.0;
max_mag[1]=0.0;max_freq[1]=0.0;
//Motor Fundamental Frequency****************************//
for(int i=0; i<flux_FFT_samples; i++)
{ind_mag[i] = 0;sum_mag[i] = 0;}

KickFFT::fft(flux_samplingFrequency, 5.0, 100.0, flux_FFT_samples, ind_FFT_real, ind_mag, startIndex, endIndex);
KickFFT::fft(flux_samplingFrequency, 5.0, 100.0, flux_FFT_samples, sum_FFT_real, sum_mag);

maxi=0.0; maxif=0.0;
for(uint16_t iii = startIndex; iii < endIndex; iii++)
{
if(ind_mag[iii]>maxi)
{
maxi = ind_mag[iii]; maxif = iii;
}
}
max_freq[0]=(flux_samplingFrequency/flux_FFT_samples)*(maxif);
max_mag[0]=(2.0/512.0)*maxi;

//mean calculation**************//
maxi=0.0;
st_freq_mean=round((max_freq[0]-5.0)/(flux_samplingFrequency/flux_FFT_samples));
ed_freq_mean=round((max_freq[0]+5.0)/(flux_samplingFrequency/flux_FFT_samples));

for(uint16_t iii = st_freq_mean; iii <= ed_freq_mean; iii++)
{
maxi = maxi+ind_mag[iii];
}
funda_mean=0.0;
funda_mean=(2.0/flux_FFT_samples)*(maxi/((ed_freq_mean-st_freq_mean)+1.0));

startIndex=0; endIndex=0;
l_limit_freq = max_freq[0] - 2.0;
u_limit_freq = max_freq[0]+ 2.0;

for (j = 0; j<(flux_FFT_samples/2); j++)
{
if((flux_samplingFrequencyj/flux_FFT_samples)<= l_limit_freq){startIndex=j;}
if(u_limit_freq>=(flux_samplingFrequency
j/flux_FFT_samples)){endIndex=j;}
}

 maxi=0.0; maxif=0.0;

for (j = startIndex; j<=endIndex; j++)
{
if(sum_mag[j]>maxi)
{
maxi = sum_mag[j];
maxif = j;
}
}
max_freq[1]=(flux_samplingFrequency/flux_FFT_samples)*(maxif);
max_mag[1]=(2.0/512.0)*maxi;

Serial.print("Individual flux: ");Serial.print("max_freq_value");Serial.print("\t");Serial.print(max_freq[0],4);Serial.print("\t");Serial.print("max_mag_value"); Serial.print("\t");Serial.println(max_mag[0],4);

Serial.print("Summation flux: ");Serial.print("max_freq_value");Serial.print("\t");Serial.print(max_freq[1],4);Serial.print("\t");Serial.print("max_mag_value"); Serial.print("\t");Serial.println(max_mag[1],4);
////*********************************************************************************************************************************************************************//

}`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions