karanbanthia
Junior Member level 1
Hi,
I am trying to use the FFT library in mikroC to calculate the frequency of input signal. The code gets complied but I am getting wrong and random results. The calculated freq does not match the input simulated sine wave. Following are the details of my code -
Sampling freq = 1KHz
Signed Fractional Data Output from ADC. Sampling done using timer 3 Interrupt.
I am performing 128 point DFT.
Following is a part of my main code where calculation is done :
What is wrong with these calculations??
I am trying to use the FFT library in mikroC to calculate the frequency of input signal. The code gets complied but I am getting wrong and random results. The calculated freq does not match the input simulated sine wave. Following are the details of my code -
Sampling freq = 1KHz
Signed Fractional Data Output from ADC. Sampling done using timer 3 Interrupt.
I am performing 128 point DFT.
Following is a part of my main code where calculation is done :
Code:
if(start_calc == 1)
{
FFT(log2N, TwiddleCoeff_128, stored_reading);
BitReverseComplex(log2N, stored_reading);
if(i==0)
{
//sum[i] = 0;
i = i+1;
k = k+2;
}
else if(i<=((num_samples/2)-1))
{
test_pin = 1;
re = stored_reading[k++];
im = stored_reading[k++];
rer = Q15_Itof(re);
imr = Q15_Itof(im);
tmpr = rer * rer;
rer = tmpr;
tmpr = imr * imr;
imr = tmpr;
tmpr = sqrt(rer + imr);
//rer = tmpr * 128.;
//sum[i] = rer;
//sum[i] = tmpr;
if(tmpr> maximum)
{
maximum = tmpr;
peak_freq_bin = i;
}
else;
i = i+1;
}
else
{
test_pin = 0;
//Vector_Max(sum,(num_samples/2),&peak_freq_bin);
peak_freq = peak_freq_bin * 8;
WordToStr(peak_freq,txt);
send_string(txt);
start_calc = 0;
//test_pin = 0;
i = 0;
k = 0;
maximum = 0;
peak_freq_bin = 0;
SR = 0x0000; // Set CPU Priority to 0
}
}
else;
What is wrong with these calculations??