⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fitsine.m

📁 biomedical stuffs...
💻 M
字号:
function [A,Q,yf,J]=fitsine(prd,y,tim,Arng,Qrng, dA,dQ)
%	[A,Q,yf,J]=fitsine(prd,y,tim,Arng,Qrng,dA,dQ)
%	Fits sine wave with period prd to data vector y
%		sampled at time points tim
%	Arng, Qrng: 2-element vectors with min and max of ranges of A and Q to be tested
%	dA, dQ: desired increments of A and Q
%	A = amplitude of fitted sine;  Q = phase of fitted sine
%	yf = fit curve,   J=matrix of mean square error(MSE) b/w approximated signals and actual signal
%       Optimal values returned (A,Q) minimize J.
%  
%	This program is distributed as a supplement to the book
%	"Biomedical Signal Processing and Signal Modeling" by E. N. Bruce,
%	published by Wiley, 2000.  It is provided for educational use only.
%  While every effort has been made to insure its suitability to illustrate
%  principles described in the above book, no specific feature or capability 
%  is implied or guaranteed.
na=ceil((Arng(2)-Arng(1))/dA), nq=ceil((Qrng(2)-Qrng(1))/dQ)
Arng(2)=Arng(1)+(na-1)*dA; Qrng(2)=Qrng(1)+(nq-1)*dQ;
lny=length(y);ymn=mean(y);ydt=y-ymn;
J=zeros([na,nq]);ia=0;size(J)
for a=Arng(1):dA:Arng(2)
   ia=ia+1;
   iq=0;
   for q=Qrng(1):dQ:Qrng(2)
      iq=iq+1;
      yfit=a*sin(2*pi*tim/prd+q);
      J(ia,iq)=(yfit-ydt)'*(yfit-ydt);
   end
end
Jmin=min(min(J))
[ainx,qinx]=find(J<=Jmin)
A=Arng(1)+(ainx-1)*dA; Q=Qrng(1)+(qinx-1)*dQ;
yf=A*sin(2*pi*tim/prd+Q)+ymn;
figure(1),plot(tim,y,':',tim,yf),title('Data=dotted,  Fit=solid')
figure(2),mesh([Qrng(1):dQ:Qrng(2)]',[Arng(1):dA:Arng(2)]',J)
ylabel('Amplitude'), xlabel('Phase'), zlabel('J')

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -