Search code examples
matlabsignalssignal-processingfftfrequency-analysis

finding the frequency of signal without using FFT


I have sine signal with noise where the number of points of noise per oscillation should be the same in my code five points per oscillation) , I want to change each time the number of oscillation :2,3,4….15 ( in my code changing the vairable "random")

At each number of oscillation I shall extract the amplitude as a function of frequency < unfortunately for few oscillation FFT wouldn't work there are too few points in the signal , so I have to fit the signal ( sine with noise ) to sine wave in order to compare the frequency of new signal to the frequency of the sine wave

see my code,how can I do the fitting ,so I can extract the frequency of the signal?

  %my code
  random=40;
  f=5; % the frequency of the sine wave also the number of points per 
     oscillation

  %the number of oscillation is random/f

  t = (1:random)';
  X = ones(random,2);


  y_1= sin((2*pi)/f*t);
  X(:,2) = y_1;
  y=y_1+randn(random,1);
  y = y(:);
  beta = X\y;
  yhat = beta(1)+beta(2)*sin((2*pi)/f*t);
 figure
 plot(t,y,'.b','markersize',12);
 hold on
 plot(t,yhat,'r','linewidth',2);

Solution

  • This is a common problem. Please try the links below or other ones on Stackoverflow. In your case, you have quite a few outliers so you use methods like RANSAC to throw them out.

    https://www.mathworks.com/matlabcentral/answers/121579-curve-fitting-to-a-sinusoidal-function

    https://www.mathworks.com/matlabcentral/answers/195371-sine-curve-fitting-for-the-given-data