在网上看到不错,保存下
clc;clear;
t=linspace(-600,600,600);
T=400;omega=2*pi/T;
y1=sin(omega*t-0*pi/3);
y2=sin(omega*t-2*pi/3);
y3=sin(omega*t-4*pi/3);
%
temp=y1(find(y1>=y2));
cross(1)=temp(1);
temp=y2(find(y2<=y3));
cross(2)=temp(1);%
sort(cross);%排序
figure,hold on
%%%%%%%%%%%%第一条
y11n=find(y1
temp=find(diff(y11n)>1);
plot(t(y11n(1):y11n(temp(1))),y1(y11n(1):y11n(temp(1))),'k--')
for i=1:length(temp)-1
plot(t( y11n(temp(i)+1):y11n(temp(i+1)) ),y1(y11n(temp(i)+1):y11n(temp(i+1)) ),'k--')
end
plot(t( y11n(temp(end)+1):y11n(end) ),y1(y11n(temp(end)+1):y11n(end )),'k--')
%%%%%
y11n=find(y1>cross(2) );
temp=find(diff(y11