我有正弦信号和噪声,其中每个振荡的噪声点数应该在我的代码中每个振荡五个点相同),我想每次改变振荡次数:2,3,4 ... .15(在我的代码改变可变“随机”)
在每个振荡次数时,我将提取幅度作为频率的函数<不幸的是,对于很少的振荡,FFT不会起作用,信号中的点太少,所以我必须将信号(带有噪声的正弦)拟合到正弦波中。为了比较新信号的频率和正弦波的频率
看到我的代码,我该怎么做拟合,所以我可以提取信号的频率?
%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);
这是一个常见问题。请尝试下面的链接或Stackoverflow上的其他链接。在你的情况下,你有很多异常值,所以你使用像RANSAC这样的方法将它们抛弃。
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