声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 966|回复: 1

高手帮忙看看这个程序啊!急!

[复制链接]
发表于 2006-4-18 13:09 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
<P>pll.m函数<BR><BR>function[tt,v1,fo,fs,t1,vc,th1,fn,c,vo]=pll(fii,foo,Kd,T,th0,dt);<BR>%<BR>%            [t1,vc,th1,fn,c,vo]=pll(fi,fo,Kd,T,th0,dt);<BR>%            Default:pll(800,1000,1,.1,[0 0],.00025);BBI 99<BR>global K fi fo<BR>if nargin&lt;5;th0=[0 0];end;<BR>if nargin&lt;2;foo=1000;end;<BR>if nargin&lt;1;fii=800;end;<BR>if nargin&lt;3;Kd=1;end;<BR>if nargin&lt;4;T=100/foo;end;<BR>if nargin&lt;6;dt=.25/foo;end;<BR>fo=foo;fi=fii;Kv=2*pi*fo;K=Kv*Kd;<BR>vs=version;vs=vs(1);<BR>if strcmp(vs,'4');<BR>  [t,th]=ode23('equation',0,T,th0) ;whitebg('w') ;delete(1);<BR>else;<BR>    dT=.25/fi;[t,th] =ode45('equation',0:dT:T,th0');<BR>end;<BR>t1=0;dt:T-dt;<BR>th1=spline(t,th(:,1),t1);th2=spline(t,th(:,2),t1);<BR>vo=cos(2*pi*fo*t1+th1);<BR>fn=1/T;n=length(vo);c=abs(fft(vo))/n*2;<BR>I=1:n/2;fn=fn*(I-1);c=c(I);<BR>I=1:n/2;fn=fn*(I-1);c=c(I);<BR>I=find(c&gt;.01);fn=fn(I);cn=20*log10(c(I));<BR>vc=th2/Kv;f=th2/(2*pi)+fo;<BR>%==========================================================================<BR>figure('Units','normal','Pos',[0.006 .05 .985 .88]);<BR>set(gcf,'NumberTitle','off','Name',nstr);<BR>subplot(221);plot(t1,vc,'b');title('Control Voltage');<BR>xlabel('t(ms)');v=axis;v3=v(3)*1.17;zoom xon;<BR>if abs(v3)&lt;1e-06;v3=-0.084;end;<BR>if abs(min(vc))+max(vc)&lt;1e-04;v3=-1.337;end;<BR>subplot(223);plot(t1,f,'k');<BR>title('Frequency');xlabel('t(ms)');<BR>subplot(224);plot(t1,th1,'k');<BR>title('Phase');xlabel('t(ms)');<BR>m=length(I);<BR>for i=1:m;<BR>     subplot(222);<BR>     plot (fn(i)+[0 0],[-40 cn(i)],'b');hold on;<BR>end;<BR>plot(fn(m)+2/T,0,'b',fn(1)-2/T,0,'b');<BR>title('Spectrum');hold off;xlbel('f(kHz)');pause(3);<BR>%==========================================================================<BR> m=10*4;n=length(t1);n2=n-m+1;<BR> dt=t1(2);T=m*dt;dt=.1*dt;fs=1/dt;<BR> tt=0:dt:T;tt2=t1(n2)+ tt;<BR> v1=spline(t1(1:m),vc(1:m),tt);<BR> v2=spline(t1(n2:n),vc(n2:n),tt2);<BR> y1=vco(v1,fo,fs);y2=vco(v2,fo,fs);<BR> H2=figure('Name',nstr,'Num','off','Pos',[5100 790 400]);<BR> subplot(211);plot(tt,y1,'b',tt,sin(2*pi*fi*tt),'r');<BR> set(gca,'units','pix','pos',[40 240 720 140]);xlabel('t(ms)');<BR> subplot(212);plot(tt2,sin(2*pi*fi*tt2),'r',tt2,y2,'b');<BR> set(gca,'units','pix','pos',[40 45 720 140]);<BR> axis([tt2(1) tt2(length(tt2))-1 1]);<BR> xlabel('t(ms)');v=axis;zoom xon;<BR> ...........................................<BR>下面这个是PLL.m函数在运行过程中要调用的equation.m函数,该函数用来描述微分方程。</P>
<P>function yp=equation(x,y);<BR> %<BR> %BBI 99<BR> global K fi fo<BR> RC=25/(2*pi*fo);        %滤波器的时间常数<BR> yp(1)=y(2);<BR> yp(2)=K/RC*sin(2*pi*fi*x).*cos(2*pi*fo*x+y(1))-y(2)/RC;<BR> v=version;v=v(1);<BR> if strcmp (v,'5');yp=yp';end;<BR>..............................<BR>这个程序是不是不全啊,Equation子程序能不能这样直接写在PLL函数的后面,还是要单独调用啊?<BR><BR><BR></P>
回复
分享到:

使用道具 举报

发表于 2006-4-19 20:31 | 显示全部楼层

回复:(tangww)高手帮忙看看这个程序啊!急!

按照你程序中的调用方式,Equation要单独写成m文件
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-9-21 20:27 , Processed in 0.054709 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表