topic Accurate Frequency Determination FFT Analysis in PTC Mathcad
https://community.ptc.com/t5/PTC-Mathcad/Accurate-Frequency-Determination-FFT-Analysis/m-p/448381#M176673
<HTML><HEAD></HEAD><BODY><P><STRONG style="font-size: 9pt;">Accurate Fast Fourier Transform Analysis</STRONG></P><P><STRONG style="font-size: 9pt;">Sampling Frequency Paradox and 100 Single Musical Note Frequencies C0 to D8#</STRONG></P><P><STRONG style="font-size: 9pt;"> </STRONG></P><P style="margin-bottom: 6pt;"><STRONG style="font-size: 9pt;">Summary</STRONG></P><P style="margin-bottom: 3pt;"><SPAN style="font-size: 9pt;">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.</SPAN></P><P style="margin-bottom: 3pt;"><SPAN style="font-size: 9pt;">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.</SPAN></P><P style="margin-bottom: 3pt;"><SPAN style="font-size: 9pt;"><SPAN>Algorithm is copyright so licensing questions to </SPAN><A class="jive-link-email-small" href="mailto:terryhendicott@ymail.com" target="_blank">terryhendicott@ymail.com</A><SPAN> because it is far more accurate and potentially very useful. Have found no references to a similar algorithm that does what this does.</SPAN></SPAN></P><P style="margin-bottom: 6pt;"><STRONG style="font-size: 9pt;">Performance Claims</STRONG></P><P style="margin-bottom: 3pt;"><SPAN style="font-size: 9pt;">The lower a point is on the% Error Graph the lower the error in calculating frequency.</SPAN></P><P style="margin-bottom: 3pt;"><SPAN style="font-size: 9pt;">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.</SPAN></P><P style="margin-bottom: 3pt;"><SPAN style="font-size: 9pt;">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 <SPAN style="font-family: arial,helvetica,sans-serif;">seconds or 5011 data samples.</SPAN></SPAN></P><P><SPAN style="font-size: 9pt; font-family: arial,helvetica,sans-serif;">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.</SPAN></P><P></P><P><SPAN style="font-size: 9pt; font-family: arial,helvetica,sans-serif;">Figure 1 - % Error Graph</SPAN></P><P><SPAN style="font-size: 9pt; font-family: arial,helvetica,sans-serif;">Figure 2 - Enhanced Spectral Shape</SPAN></P><P><SPAN style="font-size: 9pt; font-family: arial,helvetica,sans-serif;">Figure 3 - Close Up Of Resampled Peak</SPAN></P><P></P><P style="margin-bottom: 3pt;"><SPAN style="font-size: 9pt;">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.</SPAN></P><P style="margin-bottom: 6pt;"><STRONG style="font-size: 9pt;">Problem Definition</STRONG></P><P style="margin-bottom: 3pt;"><SPAN style="font-size: 9pt;">FFT analysis is able to determine frequencies from sound data supplied. FFT analysis however has a paradox.</SPAN></P><P style="margin-bottom: 3pt;"><SPAN style="font-size: 9pt;">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. </SPAN></P><P style="margin-bottom: 3pt;"><SPAN style="font-size: 9pt;">The sampling frequency is not the same as the sound frequency in the sound. Data sampling frequency is higher.</SPAN></P><P style="margin-bottom: 6pt;"><STRONG style="font-size: 9pt;">Problem Details</STRONG></P><P style="margin-bottom: 3pt;"><SPAN style="font-size: 9pt;">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?</SPAN></P><P style="margin-bottom: 3pt;"><SPAN style="font-size: 9pt;">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.</SPAN></P><P style="margin-bottom: 3pt;"><SPAN style="font-size: 9pt;">Most software makes do with sampling at 44100 Hz typical of data in WAV files.</SPAN></P><P style="margin-bottom: 3pt;"><SPAN style="font-size: 9pt;">The "spreading" (not having an integer ratio of sampling to sound) causes errors in FFT determined frequencies.</SPAN></P><P style="margin-bottom: 3pt;"><SPAN style="font-size: 9pt;">Just how erroneous is FFT using sampling rates at 44100 Hz for everything?</SPAN></P><P style="margin-bottom: 3pt;"><SPAN style="font-size: 9pt;">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?</SPAN></P><P style="margin-bottom: 3pt;"><SPAN style="font-size: 9pt;">If you use an optimum sampling frequency is the frequency in the sound more accurately determined?</SPAN></P><P style="margin-bottom: 6pt;"><STRONG style="font-size: 9pt;">Solution Study</STRONG></P><P style="margin-bottom: 6pt;"><SPAN style="font-size: 9pt;">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.</SPAN></P><P style="margin-bottom: 6pt;"><SPAN style="font-size: 9pt;">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?</SPAN></P><P style="margin-bottom: 6pt;"><SPAN style="font-size: 9pt;">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.</SPAN></P><P style="margin-bottom: 6pt;"><STRONG style="font-size: 9pt;">The Files : Part a</STRONG></P><P style="margin-bottom: 6pt;"><SPAN style="font-size: 9pt;">44100 Hz Errors:</SPAN></P><P style="margin-bottom: 6pt;"><SPAN style="font-size: 9pt;">FFT_All_Single_Musical_Notes.xmcd generates and analyses sounds C0, C0#, D0 .. D8# by FFT at 44100 Hz and looks at errors.</SPAN></P><P style="margin-bottom: 6pt;"><SPAN style="font-size: 9pt;">File is run four times at the four sound data lengths of 32678, 16384, 8192, 4096, 2048.</SPAN></P><P style="margin-bottom: 6pt;"><SPAN style="font-size: 9pt;">ErrorReport_FFT_44100_Hz_All_Notes.xlsb summarises the errors. It is also pasted into FFT_All_Single_Musical_Notes.xmcd</SPAN></P><P style="margin-bottom: 6pt;"><SPAN style="font-size: 9pt;">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</SPAN></P><P style="margin-bottom: 6pt;"><STRONG style="font-size: 9pt;">The Files : Part b</STRONG></P><P style="margin-bottom: 6pt;"><SPAN style="font-size: 9pt;">Solving the Paradox: Finding the Optimum Sampling Hz without knowing sound frequency.</SPAN></P><P style="margin-bottom: 6pt;"><SPAN style="font-size: 9pt;">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.</SPAN></P><P style="margin-bottom: 6pt;"><SPAN style="font-size: 9pt;">FFT_Paradox.xmcd also contains a pasted copy of ErrorReport_FFT_44100_Hz_All_Notes.xlsb</SPAN></P><P style="margin-bottom: 6pt;"><SPAN style="font-size: 9pt;">FFT_Paradox.xmcd also contains imported section of ErrorReport_FFT_Optimum_Hz_All_Notes.prn</SPAN></P><P style="margin-bottom: 6pt;"><STRONG style="font-size: 9pt;">The Files : Part c</STRONG></P><P style="margin-bottom: 6pt;"><SPAN style="font-size: 9pt;">Optimum Hz Errors:</SPAN></P><OL start="1" style="list-style-type: upper-alpha;"><LI><SPAN style="font-size: 9pt;">AutomatingFile.xmcd uses another MathCad file over and over again. This way many sounds can be analysed.</SPAN></LI></OL><P style="margin-bottom: 6pt;"><SPAN style="font-size: 9pt;">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.</SPAN></P><P style="margin-bottom: 6pt;"><SPAN style="font-size: 9pt;">Automate_FFT_Paradox.xmcd is a version of earlier FFT_Paradox.xmcd file but is referenced in AutomatingFile.xmcd</SPAN></P><P style="margin-bottom: 6pt;"><SPAN style="font-size: 9pt;">Automate_FFT_Paradox.xmcd as a referenced file takes input from AutomatingFile.xmcd.</SPAN></P><OL start="1" style="list-style-type: upper-alpha;"><LI><SPAN style="font-size: 9pt;">AutomatingFile.xmcd is changed by hand to report errors over the musical frequency range.</SPAN></LI></OL><P style="margin-bottom: 6pt;"><SPAN style="font-size: 9pt;">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.</SPAN></P><P style="margin-bottom: 6pt;"><STRONG style="font-size: 9pt;">Conclusion</STRONG></P><P style="margin-bottom: 6pt;"><SPAN style="font-size: 9pt;">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.</SPAN></P></BODY></HTML>Thu, 03 May 2018 17:20:10 GMTTezza20102018-05-03T17:20:10ZAccurate Frequency Determination FFT Analysis
https://community.ptc.com/t5/PTC-Mathcad/Accurate-Frequency-Determination-FFT-Analysis/m-p/448381#M176673
Accurate Fast Fourier Transform AnalysisSampling Frequency Paradox and 100 Single Musical Note Frequencies C0 to D8# SummaryWant 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'sThu, 03 May 2018 17:20:10 GMThttps://community.ptc.com/t5/PTC-Mathcad/Accurate-Frequency-Determination-FFT-Analysis/m-p/448381#M176673Tezza20102018-05-03T17:20:10ZRe: Accurate Frequency Determination FFT Analysis
https://community.ptc.com/t5/PTC-Mathcad/Accurate-Frequency-Determination-FFT-Analysis/m-p/448382#M176674
<HTML><HEAD></HEAD><BODY><P>Interesting idea!</P><P></P><P>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?</P><P></P><P>If you changed the starting sample rate, does the accuracy vary? </P><P></P><P>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.</P><P></P><P>If you vary phase, does it track?</P></BODY></HTML>Thu, 25 Apr 2013 12:36:26 GMThttps://community.ptc.com/t5/PTC-Mathcad/Accurate-Frequency-Determination-FFT-Analysis/m-p/448382#M176674FredKohlhepp2013-04-25T12:36:26ZRe: Accurate Frequency Determination FFT Analysis
https://community.ptc.com/t5/PTC-Mathcad/Accurate-Frequency-Determination-FFT-Analysis/m-p/448383#M176675
<HTML><HEAD></HEAD><BODY><P>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. </P><P></P><P>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: <A _jive_internal="true" href="https://community.ptc.com/message/134317#134317">http://communities.ptc.com/message/134317#134317</A></P><P></P><P>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).</P></BODY></HTML>Sat, 27 Apr 2013 22:32:07 GMThttps://community.ptc.com/t5/PTC-Mathcad/Accurate-Frequency-Determination-FFT-Analysis/m-p/448383#M176675RichardJ2013-04-27T22:32:07Z