Please let me ask your help on my problem. MATLAB code (at https://metrw-pitch.blogspot.com/ you can see code in .mlx (for run it you want delete comments) and .m format) executing in MATLAB online R2020b, outputs good accuracy even for low fundamental frequencies (fundFreq) but code (originally in my answer to a question of mine) of similar algorithm in C++ (acctually I have translated this code into Matlab's language), executing in Visual Studio 2019, outputs bad accuracy in low (lower than 150 Hz) frequencies.
Question is whether MATLAB's code executing in dsp kit retains its accuracy. I'm homeless (in France) and get internet access in Social Services and Post Offices like this I'm just now. So it's impossible for me to run code in dsp kit. You are kindly requested test MATLAB's code in your dsp kits and say me its output for fundFreq 50, 60, 70 Hz. Be aware when change FundFreq, change, if necessary, FFTfundFreq and/or GridDemiSpan so that grid's span covers FundFreq.
I have asked similar question on 8 Feb 2021 at 13:25, at MATLAB but nobody answered yet.
Copy of Matlab's code without comments is following.
format long; SampFreq = 16000; Segm = 1:1600; FundFreq = 50; FFTfundFreq = 41; GridDemiSpan = 10; FirstHarmAngles = FundFreq*2*pi/SampFreq*Segm+1.9*pi; SinFirstHarmAngles = sin(FirstHarmAngles); SecondHarmAngles = FundFreq*2*2*pi/SampFreq*Segm+0.9*pi; SinSecondHarmAngles = sin(SecondHarmAngles); ThirdHarmAngles = FundFreq*3*2*pi/SampFreq*Segm+0.3*pi; SinThirdHarmAngles = sin(ThirdHarmAngles); Xn = 170000*SinFirstHarmAngles+220000*SinSecondHarmAngles+... 150000*SinThirdHarmAngles; Freqs = FFTfundFreq-GridDemiSpan:0.1:FFTfundFreq+GridDemiSpan; MagnSqrd = ones(1,201); for f = 1:201 Angles = Freqs(f)*2*pi/SampFreq*Segm; XnCos = sum(Xn.*cos(Angles)); XnSin = sum(Xn.*-sin(Angles)); MagnSqrd(f) = XnCos.^2+XnSin.^2; end [maxMagnSqrd, maxMagnSqrdIndex] = max(MagnSqrd); GRIDfundFreq = Freqs(maxMagnSqrdIndex); disp(GRIDfundFreq);
With regards and friendship, Georges Theodosiou