Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

fft,frequency spectrum

Status
Not open for further replies.
hi guys,
does any body have a code that can perform fft using pic 18f4550. i have tried many but i cant scale the frequencies so that i can get frequencies starting from 50hz .any body please help me
 
I don't have complete code to post, but I could try to help you. Could you post the code that receives the data.
This free book might also help you: https://www.dspguide.com/pdfbook.htm
 
Last edited:
this code produces frequency buckets starting from 312hz i just want to scale the frequency so that i can get buckets from 50hz onwards. please help me
 

Attachments

  • fft.c
    3.9 KB · Views: 304
  • fft.h
    7.4 KB · Views: 187
  • main.c
    7.1 KB · Views: 145
this code here performs fft and produce frequency buckets from around 312hz. ijust want to scale it so that i can get buckets starting from 50hz. upper limit is not at all important . please help me
 

Attachments

  • fft.h
    7.4 KB · Views: 151
  • main.c
    7.1 KB · Views: 164
  • fft.c
    3.9 KB · Views: 153
Not sure what exactly you mean.
If the algorithm you posted works, then the resulting arrays are the cofficients (real and imaginary) corresponding certain frequencies (starting from 0 frequency).

To find out what the actual frequency is for each coefficient (m), you also need to know number of samples you collected (N) and the sampling interval (T)..
then you can calculated the correspondin frequencies for each "bin".
f(m) = m / ((N/2)*T)

(At least this applies to the fft algorithm you posted, I think)
You can see that the units are 1/s.. that is Hz.

So, you need to choose you samplerate and number of samples you collect appropriately. This is the way you scale the resulting frequency analysis. No need to modify the algorithm itself.
Also note that your number of samples N, needs to be a power of two.. 128, 512, 1024, etc.
What is the frequency range you are interested to "analyse"?

EDIT:
Also notice what the author says about "bucket 0" in his example code: "The first bucket cannot be used so in reality our result is 31 buckets."
I believe that the "bucket 0" is there and it is a bucket for frequencies 0 - 312.5Hz
The reason that he is not using that bucket is that this example program is for audio frequencies.. so he leaves out the "dc" bucket.
C:
        // Perform the (forward) FFT calculation

        // Note: the FFT result length is half of the input data length
        // so if we put 64 samples in we get 32 buckets out.  The first bucket
        // cannot be used so in reality our result is 31 buckets.
        //
        // The maximum frequency we can measure is half of the sampling rate
        // so if we sample at 20Khz our maximum is 10Khz (this is called the
        // Nyquist frequency).  So if we have 32 buckets divided over 10Khz,
        // each bucket represents 312.5Khz of range, so our lowest bucket is
        // (bucket 1) 312.5Hz - 625Hz and so on up to our 32nd bucket which
        // is 9687.5Hz - 10,000Hz
 
        //  1 : 312.5 - 625
        //  2 : 625 - 937.5
//..
        // 30 : 9375 - 9687.5
        // 31 : 9687.5 - 10000
 
Last edited:
Your english is good. I just wasn't sure if I answered the problem you were having. Glad if you got the code working like you want.
 
hi
i simulated it on proteus. but te o/p looks like this when a 100hz signal is applied. the next pic is when i apply a 1khz signal . all the freq are having a particular amplitude. is this right . also look into the first bucket its always high
100hz.JPG
1khz.JPG
 
this is the full code i have written

i have not posted ds1307.h and i2c.h as they are not used in the code
 

Attachments

  • fft.c
    2.8 KB · Views: 299
  • fft.h
    5.8 KB · Views: 160
  • glcd.c
    5.2 KB · Views: 169
  • glcd.h
    2.3 KB · Views: 165
  • glcd_header_00.hex
    13.7 KB · Views: 138
  • includes.h
    200 bytes · Views: 148
  • main.c
    5.1 KB · Views: 258
What is your sampling frequency? How many samples?
and.. do not trust the simulator if you are combining analog and digital (firmware).
 
sampling freq is 20khz as per the codes documentation. as the simulation is not real time , i cant get the sampling freq. I have ordered for a glcd module . all my firm ware is ready except for the display . as iam in bed rest due to sprain in my leg , i dont have access to a cro
 
Status
Not open for further replies.

Latest threads

Back
Top