I managed to edit the matlab code, now it's working as expected,
clear
clc
%ADC sin wave, it represent the data that I have captured with the ADC
%and want to estimate the frequency
ADCsin = dsp.SineWave(1,50.124);
ADCsin.ComplexOutput = false;
ADCsin.SampleRate = 12800;
ADCsin.SamplesPerFrame = 768;
ADC = ADCsin();
plot(ADC);
grid on
hold on
%ref sin wave with 50Hz complex value
Refsin = dsp.SineWave(1,50);
Refsin.ComplexOutput = true;
Refsin.SampleRate = 12800;
Refsin.SamplesPerFrame = 768;
ref = Refsin();
plot(imag(ref))
%calculating xs
xs = ref .* ADC;
%calculate the CAF
M = 256;
h = ones(1,M)./M;
y1 = filter(h,1,xs);
y2 = filter(h,1,y1);
y3 = filter(h,1,y2);
%calculating the final result
Fest = 50 - (angle(y3(end)) - angle(y3(end-1))) * 12800/(2*pi)
Now I want to know if it's possible to make the algorithm simpler, is there a way to combine all the 3 filters to a pre-calculated fixed stream to only do the convolution one time,
I mean is there a way to combine all these 3 lines of code to a one time filter?
%calculate the CAF
M = 256;
h = ones(1,M)./M;
y1 = filter(h,1,xs);
y2 = filter(h,1,y1);
y3 = filter(h,1,y2);
So that we do the convolution only one time?