Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Help!!! Wrong results while using FFT in MikroC Pro for dsPIC

Status
Not open for further replies.

karanbanthia

Junior Member level 1
Joined
Jan 7, 2010
Messages
16
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Location
pune
Activity points
1,412
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 :

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??
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top