Jump to content
43oh

Recommended Posts

Hello to all!

 

Im new using Launchpad and energia, and im trying to make a Spectrum analyzer, so to make it works i need to use the fast fourier transform, to change from time domine to frecuency domine, ok so.... 

I was looking for a library with the FFT but only found one for arduino... it is the FIX_FFT.H  

here: http://arduino.cc/forum/index.php/topic,38153.0.html

 

but... this library uses another library the avr/pgmspace.h

so I can not use this...

 

anybody knows a FFT library for energia? or how to make it works without avr/pgmspace.h or with a replace....

 

or some code to work with  FFT on energia??

 

 

THANKS!! :)

 

valery

 

 

Link to post
Share on other sites

Hi,

 

On Arduino you must use PROGRAMSPACE to store the large vector constant in Flash.

MSP430 is more efficient about the constants handling.

You can leave PGMSPACE and use constants instead, it should work.

That said, although I built an audio spectrum scope on Arduino and offer it as a kit, I have not dug enough in the FFT lib to be sure you will port it to Energia easily.

The sampling must be done differently too, because on the AVR you put the ADC in "free running" mode to reduce the sampling delay. Something similar may be available on MSP430 but the command to issue to the MCU will be different for sure.

 

Yan.

Link to post
Share on other sites

hey

I finally found a Code to work with FFT on Energia, it is very simple, so I can understand it but, there is a thing that i Cant understand, and it is the frecuency because i get the amplitude but I dont know what the frecuency for every amplitude is... this is the code:

 

 

 

#include <math.h>

#define ANALOG_IN 0




void setup() {
Serial.begin(9600); 
}


void loop() {
  
  fourier();
  
}




void  fourier(){


               
      int var = 0;
    
    while(var < 1){


      
                /////------------------------------------------------------------------------getting data
              
              int h=8;    // Taza de refresco de 0.5 Hz aprox        
              float f[h];
              float F[h];
              float Y[h];
              float Real[h];
              float Imag[h];
              float Final[8];
             /////------------------------------------------------------------------------------initialiting 
               
                for (int i=0; i < h; i=i+1){ 
                  Real[i]=0; 
               }  
                for (int i=0; i < h; i=i+1){  
                  Imag[i]=0;  
               }  
              for (int i=0; i < h; i=i+1){   
                  f[i]=analogRead(ANALOG_IN);  //Obtiene un vector en el tiempo normalizado al voltaje        
               }  
               for (int i=0; i < 7; i=i+1){  
                  Final[i]=0;  
               }
               
             /////--------------------------------------------------------------------------------- Fourier
               
               for(int j=0; j<h;j=j+1){                        
                for(int u=0; u<h;u=u+1){
                  Real[j]=Real[j]+ f[u]*sin((2*3.14*u*j/h));   // Vector parte Real
                  Imag[j]=Imag[j]+ f[u]*cos(-2*3.14*u*j/h);    // Vector parte Imag  
               }
               F[j]=sqrt(pow(Real[j],2)+pow(Imag[j],2));
                  Serial.print(F[j]);
               Serial.print(" ");
              }   
              
              delay(100);
            
            /////---------------------------------------------------------------------------Llevando a fftshift
            /* I dont understand this part:


               for (int i=0; i < 31; i=i+1){  
                  Y[i]=F[32+i];  
               }
            
              for (int i=0; i < 30; i=i+1){  // Me como el F[0]...Muy distorsionado
                  Y[i+31]=F[i+1];  
               }
               */
          
                 
             } 
 }

 

 
///////////////////////////////////////////////////////////////////
 
Im plotting it on MATLAB
and what im getting whit a potentiometer is a vector of 8 points, kind of:
 
 
  |    |    |    |
 | |  | |   | |  | |
 | |  | |   | |  | |
 | |  | |   | |  | |
 | |  | |   | |  | |
____________
0  1  2  3  4  8
 
But i dont think it has 8 frecuencies from 0 to 8HZ
I think it is only one frecuency because the potentiometer is constant
 
so what can i do to place it on the right frecuency
 
Link to post
Share on other sites

For a sample rate 'S' in units of samples per second...

 

F[0]: 0 Hz (DC)

F[1]: S * 1 / 8 Hz

F[2]: S * 2 / 8 Hz

F[3]: S * 3 / 8 Hz

F[4]: S * 4 / 8 Hz

F[5]: S * -3 / 8 Hz

F[6]: S* - 2 / 8 Hz

F[7]: S * -1 / 8 Hz

 

There is also a mistake in the code

this:

Real[j]=Real[j]+ f*sin((2*3.14*u*j/h)); // Vector parte Real

Imag[j]=Imag[j]+ f*cos(-2*3.14*u*j/h); // Vector parte Imag

 

should be:

Real[j] += f * cos(2 * 3.14 * u * j / h); // Vector parte Real

Imag[j] += f * -sin(2 * 3.14 * u * j / h); // Vector parte Imag

 

Link to post
Share on other sites

For a sample rate 'S' in units of samples per second...

 

F[0]: 0 Hz (DC)

F[1]: S * 1 / 8 Hz

F[2]: S * 2 / 8 Hz

F[3]: S * 3 / 8 Hz

F[4]: S * 4 / 8 Hz

F[5]: S * -3 / 8 Hz

F[6]: S* - 2 / 8 Hz

F[7]: S * -1 / 8 Hz

 

There is also a mistake in the code

this:

Real[j]=Real[j]+ f*sin((2*3.14*u*j/h)); // Vector parte Real

Imag[j]=Imag[j]+ f*cos(-2*3.14*u*j/h); // Vector parte Imag

 

should be:

Real[j] += f * cos(2 * 3.14 * u * j / h); // Vector parte Real

Imag[j] += f * -sin(2 * 3.14 * u * j / h); // Vector parte Imag

 

THANK YOU I UNDERSTAND NOW :)

 

im going to fix it :)

Link to post
Share on other sites
  • 2 years later...

Quick note about this:

 

/////---------------------------------------------------------------------------Llevando a fftshift

            /* I dont understand this part:

 

This is doing zero-phase windowing, which is common in signal processing. It just shifts where you are in the sinusoidal signal & doesn't change the results of the DFT.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...