I have implemented Full cycle DFT algorithm in arduino 2560. It works well with fundamental(50Hz). It attenuates all even harmonics. But surprisingly lets through all odd harmonics. What am I doing wrong? Here is my code
//Full Cycle DFT Experiment- Sampling Frequency is 1KHz and Number of samples is N=20
// Sample Mode-ADC #define Sampling_Interval 1000 // unit us - 1KHz #define Samples 20 #define Scaling 3.45
const int analogInPin = A0;
long startTime;
long endTime;
uint16_t n,i;
float result;
float FCDFT(int16_t arry[]);
int16_t values[Samples];
char real_coeff[Samples];
char imag_coeff[Samples];
void setup()
{
Serial.begin(9600);
pinMode(4, OUTPUT);
startTime=0;
endTime=0;
n=0;
for(i=0;i<Samples;i++)
{
real_coeff_= cos(23.14159i/20);//LUT_ imag_coeff_= sin(23.14159i/20); * }* } void loop() { * while(1)* * {* * startTime=micros();* * if((startTime-endTime)>=Sampling_Interval)
_ {* * endTime = micros();* * if (n<Samples)* * {* * values[n] = analogRead(analogInPin);* * n++; * * }* * else if(n==Samples)* * {* * result= FCDFT(values);* * n=0;* _ Serial.println(result*Scaling);_
You have lost me with " It works well with fundamental(50Hz). It attenuates all even harmonics. But surprisingly lets through all odd harmonics" . With your code how do you get values for anything but the 50Hz value? Using a sample rate of 1KHz and taking 20 samples means you are only obtaining the 50 Hz component of the input and not the harmonics of 50 Hz. What am I missing?
Also, I'm uncomfortable with the indexing used in equations 2.1 and 2.2 in your reference. The indexing is normally k within 0 to (N-1) and not within 1 to N , Since I have not read the whole reference I can't be sure it is wrong but should be worth checking.