Jump to content
43oh

Recommended Posts

Isn't the fundamental frequency also the peak frequency?

 

In the lowest frequency doesnt match, but i think it is more a problem of amplification in the microphone, it amplifies the fundamental and its first harmonic, but the program detect only the harmonic instead the fundamental, however, the harmonic should be attenuate. In this way, i dont understand why the fft gives more importance to the harmonic when the fundamental is more powerfull.

 

Tomorrow i'll use the debug print, I delete it before haved tested the program with the microphone, that's my fault.

 

 

Can you filter out the harmonic in software?

 

I suppose and hope i can, i'll try to implement a low pass filter by software only for this case

Link to post
Share on other sites
  • 3 weeks later...

well the project is in the same point.

 

I've check some LP filters but it doesnt work right. It stil detecting double low frequencies. Any good LP filter there?

  [...]

for( i=0; i<nPts; i++) imag[i] = 0;        // clear imaginary array
  
  for (i = 1; i < nPts; i++) 
    {
      int gain = 0.01;
//Filer A
      //real_LP[i] = (gain * real[i] + real[i-1])/(1+gain); //-----> gain=3;

//Filter B
      real_LP[i] = gain * real[i] + (1-gain)*real[i-1]; //-----> 0<gain<1;
    } 
    
  fix_fft(real_LP, imag, LOG2N, 0);             // perform fft on sampled points in real[i]

[...]
Link to post
Share on other sites

In the first post of this thread I copied the debug output into a spreadsheet and plotted it. Can you do that and post the graph? Include all the parameters you are using so the results can be duplicated. At the end of the day though I am not how sure how accurate this is going to be.

Link to post
Share on other sites

I am guessing that you have set the parameters wrong for the fft and it is outside it's range.  In the original code I had a table in fix_fft.h that showed the highest frequency that could be measured with different values of LOG2N and FREQ_RESOLUTION for the MSP432.  Perhaps you have modified the values outside the range of the table and it is isn't covering your range?

 

I ran a couple of cases real quick to see how it performed at lower frequencies since I haven't done that before.  I was using a Tiva TM4C123 LaunchPad and Energia v17 at 80 MHz.  First, set the parameters:

#define LOG2N              7     //log base 2 of the number of points, e.g. LOG2N = 8 is 256 points
#define FREQ_RESOLUTION    2     //Frequency resolution of output in Hz
#define ANALOG_IN          6     //analog input pin
#define ANALOG_RESOLUTION 12     //CPU specific

With these parameters the highest frequency that can be measured is 126 Hz.  Note that this information is given in the debug print with the original code.  I generated a square wave and varied the frequency with the following results....

 

Generated Frequency           FFT

20                                          19

40                                          39

80                                          81

100                                       101

Since the resolution is only 2 Hz this is OK.  Now, as stated above, the maximum frequency these settings can go to is 126 Hz.  So if we modify as follows then we can measure up to 252 Hz.

#define LOG2N              7     //log base 2 of the number of points, e.g. LOG2N = 8 is 256 points
#define FREQ_RESOLUTION    4     //Frequency resolution of output in Hz
#define ANALOG_IN          6     //analog input pin
#define ANALOG_RESOLUTION 12     //CPU specific

And some more measurements...

 

Generated Frequency           FFT

100                                        98

160                                        162

200                                        202

Note that 100 Hz was run again and there is a different answer due to the changes in the settings and the coarser resolution.  To go higher, change the settings again.

#define LOG2N              8     //log base 2 of the number of points, e.g. LOG2N = 8 is 256 points
#define FREQ_RESOLUTION    5     //Frequency resolution of output in Hz
#define ANALOG_IN          6     //analog input pin
#define ANALOG_RESOLUTION 12     //CPU specific

and measuring at 400 Hz

 

Generated Frequency           FFT

400                                        403

Link to post
Share on other sites

Yes, i modified the parameters to get a 1Hz resolution, giviing a 511Hz max frequency, it is true this values arent in the table. 

#define LOG2N              10     //log base 2 of the number of points, e.g. LOG2N = 8 is 256 points
#define FREQ_RESOLUTION   1     //Frequency resolution of output in Hz
#define ANALOG_IN          27     //analog input pin
#define ANALOG_RESOLUTION 12     //CPU specific

The problem is that sometimes it works right and suddenly it works wrong, detecting the main frequency or double frec (the second harmonic). I think it is an aliasing problem. 

 

Trying to solve this problem i implemented a little LP filter before calling FFT function, it reduces this blinking misfunction, but not solved it completely, but it appears less times and it detects the whole working range (70 - 350 Hz)

  for (i = 1; i < nPts; i++) 
    {
      int gain = 50;
     
      real[i] = (gain * real[i] + real[i-1])/(1+gain); //-----> gain= 10 o 50;
    }

This is the amplifier i use to set the guitar signal before the ADC

 

 

post-48544-0-90955700-1462616822_thumb.jpg

post-48544-0-65355700-1462616835_thumb.jpg

Link to post
Share on other sites

Wow. You have stretched it well past what I originally did.

 

The intermittent nature of the error is interesting. Is there a primary and secondary blip in the data? The plots you post above show a single strong spike.

 

Can you generate a known clean signal instead of the amplifier from the guitar and see what happens?

 

Nice project by the way.

Link to post
Share on other sites

@@Ymir

 

I ran another series of cases using the parameters that you specified above, i.e.

#define LOG2N             10     //log base 2 of the number of points, e.g. LOG2N = 8 is 256 points
#define FREQ_RESOLUTION    1     //Frequency resolution of output in Hz
#define ANALOG_IN          6     //analog input pin
#define ANALOG_RESOLUTION 12     //CPU specific

The input to the FFT was a clean square wave from an AD9850 as described in this thread:  http://forum.43oh.com/topic/9402-ad9850-frequency-generator-boosterpack/

 

I am still using my original code with Energia v17 and a TM4C123.  Cases at 20 Hz, 40 Hz, 80 Hz, etc. were run as shown below, and some were repeated to see if an intermittent error would pop up.  Here are the results...

 

Case         Result 1    Result 2    Result 3

 20 Hz          20             20             20

 40 Hz          40             40             40

 80 Hz          80             80             80

100 Hz       100

120 Hz       120           120           120

160 Hz       160

200 Hz       200

 

 

To be honest, I was surprised and pleased at the outcome.  Everything was spot on.  Admittedly I only did 15 trials but there were no intermittent errors and 100% accuracy.

 

Check the incoming signal.

 

EDIT:  I just ran this ten times with a sin wave at 100 Hz and got perfect results with that as well

Link to post
Share on other sites
  • 1 month later...

 

 

First, sorry for not answer before, but i was incredibly bussy and couldnt test neither circuits nor the code deep.

 

Anyway, I've used a function generator to test the accuracy and range of the code and it runs perfect from 30 Hz to 330Hz, i only tested my working range.

 

Moreover i've tested the circuits linearity, and they are incredibly linear.

 

So, with this results, i tested the input....when the input is direct from the guitar, the code runs, but when i use a microphone, suddenly appears a problem, the lowest string frequency, at 82Hz, it isnt detected but the code detect it second harmonic, more or less, and calculate 166Hz. So the problem is something with the microphone. Im using an electret microphone.

 

I tested the input from the microphone with an oscilloscope and seems not to recognize that lower frequency.

 

I'll do more experiments and coment the results.

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