cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X

Accurate Frequency Determination FFT Analysis

Tezza2010
1-Newbie

Accurate Frequency Determination FFT Analysis

Accurate Fast Fourier Transform Analysis

Sampling Frequency Paradox and 100 Single Musical Note Frequencies C0 to D8#

Summary

Want to be able to analyse accurately sounds of practical frequencies?  An algorithm has been found for a much more accurate way to do it.

On average it is 1000's of times more accurate.  Algorithm finds frequencies to very high precision on very short samples.  Better shaped spectra result.

Algorithm is copyright so licensing questions to terryhendicott@ymail.com because it is far more accurate and potentially very useful.  Have found no references to a similar algorithm that does what this does.

Performance Claims

The lower a point is on the% Error Graph the lower the error in calculating frequency.

Middle data set in the % Error Graph below is error in % in calculating musical frequencies on notes C0, C0#, D0 up to D8# using Fast Fourier Transforms (FFT) using each data sample 2^15 = 32678 long (0.743 seconds) in WAV style at 44100 Hz sampling frequency.

Top data set in the % Error Graph below is the loss of accuracy if the sample size is diminished to 2^11 or 2048 long (0.046 seconds).  At lowest musical pitches the sample needs to be 4096 notes then 8192 to include enough data for the FFT analysis.  In music at 132 beats per minute a sixteenth note (semi quaver) is 0.114 seconds or 5011 data samples.

The lowest data set of the % Error Graph is the same sized samples as the top data set of mostly 2048 data points (0.046 seconds) except for lower musical pitches that need 4096 then 8192 sample sizes.  The order of accuracy of the calculation of the frequency value of the sound to high precision is a quantum leap in performance.

Figure 1 - % Error Graph

Figure 2 - Enhanced Spectral Shape

Figure 3 - Close Up Of Resampled Peak

This increased performance in calculating the numerical value of the sound frequency is due to far better spectral shape resulting from solving the sampling frequency paradox in conducting FFT analysis of a frequency signal.

Problem Definition

FFT analysis is able to determine frequencies from sound data supplied. FFT analysis however has a paradox.

FFT to be accurate requires that the sound is sampled at a frequency that is an integer ratio of the frequency contained in the signal. 

The sampling frequency is not the same as the sound frequency in the sound.  Data sampling frequency is higher.

Problem Details

If this integer ratio is not maintained the spectrum determined by the FFT is subject to "spreading".  See the MathCad help and Quicksheets where accurate FFT analysis is conducted on a 0.50 Hz signal frequency of the sound and a sampling frequency of 4.0 Hz being a nice integer 8 times ratio. Establishing such an integer ratio for a sampling frequency is harder when frequency of sound is say musical note E3 at 164.813 Hz. What is best sampling frequency to use for this, particularly if you do not know the sound is 164.813 Hz?

Paradox is if you are trying to find practical sound frequencies you can't set data sample rates as an integer ratio of the frequency in the signal as the frequency in the signal is information you do not know and are actually seeking.

Most software makes do with sampling at 44100 Hz typical of data in WAV files.

The "spreading" (not having an integer ratio of sampling to sound) causes errors in FFT determined frequencies.

Just how erroneous is FFT using sampling rates at 44100 Hz for everything?

Can a more accurate method of determining the optimum sampling frequency for a sound signal for an FFT analysis be determined only from the data of a sound sampled at 44100 Hz?

If you use an optimum sampling frequency is the frequency in the sound more accurately determined?

Solution Study

Yes to all questions above.  44100 Hz is error prone.  An algorithm is possible. More accuracy is available.  Algorithm shows higher accuracy is available even at shorter bursts of sound.  Average is thousands of times more accurate on sound bites 16 times shorter.

Errors are studied here first using only 44100 Hz as the sampling rate, and can be significant and depend on sample size.  Shorter sound samples worse errors.  Generate whole range of musical notes of varying durations with known frequencies and recorded how FFT does at 44100 Hz sampling rate.  Turns out not so good?

An algorithm is provided that can determine a more optimum sound sampling rate than 44100 Hz for a given sound frequency sample.  Re-sampling using this optimum sampling rate for a given sound leads to more accurate determination of sound frequency (and better shaped spectra showing clearer peaks).  Optimum sampling rate is different for different sound frequencies. Algorithm needs no more information than that already available at 44100 Hz.  Algorithm does not need to know what sound frequency exists in the sound.  It finds them accurately.  Algorithm is successful at finding the optimum data sampling frequency without knowledge of what the sound frequency is.

The Files : Part a

44100 Hz Errors:

FFT_All_Single_Musical_Notes.xmcd generates and analyses sounds C0, C0#, D0 .. D8# by FFT at 44100 Hz and looks at errors.

File is run four times at the four sound data lengths of 32678, 16384, 8192, 4096, 2048.

ErrorReport_FFT_44100_Hz_All_Notes.xlsb summarises the errors.  It is also pasted into FFT_All_Single_Musical_Notes.xmcd

FFT_32678_44100.jpg, FFT_16384_44100.jpg, FFT_8192_44100.jpg, FFT_4096_44100.jpg, FFT_2048_44100.jpg show the errors become worse as sound is shortened.  Images copied out of FFT_All_Single_Musical_Notes.xmcd

The Files : Part b

Solving the Paradox:  Finding the Optimum Sampling Hz without knowing sound frequency.

FFT_Paradox.xmcd looks at the possibility of making an algorithm to better sample sound files to accurately determine sound constituent frequencies.  It finds one.  It is very accurate compared to using 44100 Hz for everything.  File uses musical note frequency E3 for short duration of 0.046 seconds.

FFT_Paradox.xmcd also contains a pasted copy of ErrorReport_FFT_44100_Hz_All_Notes.xlsb

FFT_Paradox.xmcd also contains imported section of ErrorReport_FFT_Optimum_Hz_All_Notes.prn

The Files : Part c

Optimum Hz Errors:

  1. AutomatingFile.xmcd uses another MathCad file over and over again.  This way many sounds can be analysed.

Full range from C0, C0#, D0 ... D8# used at short duration 0.046 sec.  It will also work on high pitch notes at even shorter durations of sound.

Automate_FFT_Paradox.xmcd is a version of earlier FFT_Paradox.xmcd file but is referenced in AutomatingFile.xmcd

Automate_FFT_Paradox.xmcd as a referenced file takes input from AutomatingFile.xmcd.

  1. AutomatingFile.xmcd is changed by hand to report errors over the musical frequency range.

ErrorReport_FFT_Optimum_Hz_All_Notes.xlsb includes previous errors for FFT at 44100 Hz and compares them to errors using an optimally chosen sampling rate.  A text file ErrorReport_FFT_Optimum_Hz_All_Notes.prn is an export of ErrorReport_FFT_Optimum_Hz_All_Notes.xlsb used back in FFT_Paradox.xmcd for discussion of the success of the algorithm described.

Conclusion

Better algorithm to find sound frequency that aids FFT analysis of sounds is available.  It resolves the FFT paradox.  It determines an optimum data sampling frequency allowing re-sampling of sound data and calculation of FFT at this optimum data sampling frequency.  Wrote this algorithm as no other way is available to determine sound frequencies values in WAV files to this sort of accuracy on such short samples that represent portions of a sixteenth note (semi quaver) in 132 beat per minute music.

2 REPLIES 2

Interesting idea!

How would you execute this idea for a signal that wasn't a pure tone (say a three-note chord?)  Run it three times, once for each note?

If you changed the starting sample rate, does the accuracy vary? 

How does the accuracy of the amplitude track?  Your signal has an amplitude of 1, yet you report a match to an "exact amplitude" of 22.722.

If you vary phase, does it track?

RichardJ
19-Tanzanite
(To:Tezza2010)

Part of the error comes from sampling, but a lot is from the fact that you do not have an integer number of periods. Your sinusoid is therefore not actually a single frequency.

If you want an accurate estimate of the frequency of a simple sinusoid (or even the sum of a few frequencies) you can first get estimates of the frequency, phase, and amplitude from the FT, and then do a least squares fit of a pure sinusoid to the data using the estimated values as guesses. The least squares fit is prone to errors without good guesses, but the estimates from the FT are good enough (at least they have been every time I have done this, and I have been doing it for almost 20 years). See here for an example: http://communities.ptc.com/message/134317#134317

As an aside, you can't copyright an algorithm, only the specific coding you used. If you want to protect an algorithm you need to patent it (which you now can't do, even if you were willing to spend the money, because you have disclosed it).

Top Tags