%粒子群优化法辨识
clear all;close all;
global Ts m u y n
%读取系统时间及输入输出数据
load data_step_io u y;
% global Ts m u1 u2 u3 y n1 n2 n3
% %读取系统时间及输入输出数据
% load data_step_io u1 u2 u3 y;
data_sum=size(y);%读取数据个数
m=data_sum(2);
Ts=6;%设置采样周期
for i=1:m
t(i)=(i-1)*Ts;
end
plot(t,y,':')
hold on;
type = 1; %%设置辨识模型
%% type = 1 K/(Ts+1)^n 一型 psoi_obj_1(V(:,i));
%% type = 2 K/(T1s+1)(T2s+1)(T3s+1) 二型 psoi_obj_2(V(:,i)) ;
%% type = 3 K*e^(-tao*s)/(Ts+1) 三型 psoi_obj_3(V(:,i));
%% type = 4 K/s(Ts+1)^n 三型 psoi_obj_4(V:i);
%% type = 5 ;
if type == 1
N=2;%优化参数个数
%置传递函数系数的下限
V_l(1:N)=[-20 10];%G(s)=V1/(V2s+1)^V3
%置传递函数系数的上限
V_h(1:N)=[1 500];%G(s)=V1/(V2s+1)^V3
n=3;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%自设定阶次n
end
if type == 2
N=5;%优化参数个数
%置传递函数系数的下限
V_l(1:N)=[-20 5 5 5 0];%G(s)=V1/(V2s+1)^V3
%置传递函数系数的上限
V_h(1:N)=[0 300 300 300 0];%G(s)=V1/(V2s+1)^V3
n(1)=1;
n(2)=1;
n(3)=1;
n(4)=1;
end
if type == 3
N=3;%优化参数个数
%置传递函数系数的下限
V_l(1:N)=[-30 5 5];%G(s)=V1/(V2s+1)^V3
%置传递函数系数的上限
V_h(1:N)=[-15 100 50];%G(s)=V1/(V2s+1)^V3
n=3;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%自设定阶次n
end
if type == 4
N=3;%优化参数个数
%置传递函数系数的下限
V_l(1:N)=[-30 5 5];%G(s)=V1/(V2s+1)^V3
%置传递函数系数的上限
V_h(1:N)=[-15 100 50];%G(s)=V1/(V2s+1)^V3
n=3;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%自设定阶次n
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if type == 5
if type1 == 1
N1=2;%优化参数个数
%置传递函数系数的下限
V_l1(1:N1)=[-20 10];%G(s)=V1/(V2s+1)^V3
%置传递函数系数的上限
V_h1(1:N1)=[1 500];%G(s)=V1/(V2s+1)^V3
n1=3;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%自设定阶次n
end
if type1 == 2
N1=5;%优化参数个数
%置传递函数系数的下限
V_l1(1:N1)=[-20 5 5 5 0];%G(s)=V1/(V2s+1)^V3
%置传递函数系数的上限
V_h1(1:N1)=[0 300 300 300 0];%G(s)=V1/(V2s+1)^V3
n1(1)=1;
n1(2)=1;
n1(3)=1;
n1(4)=1;
end
if type1 == 3
N1=3;%优化参数个数
%置传递函数系数的下限
V_l1(1:N1)=[-30 5 5];%G(s)=V1/(V2s+1)^V3
%置传递函数系数的上限
V_h1(1:N1)=[-15 100 50];%G(s)=V1/(V2s+1)^V3
n1=3;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%自设定阶次n
end
if type1 == 4
N1=3;%优化参数个数
%置传递函数系数的下限
V_l1(1:N1)=[-30 5 5];%G(s)=V1/(V2s+1)^V3
%置传递函数系数的上限
V_h1(1:N1)=[-15 100 50];%G(s)=V1/(V2s+1)^V3
n1=3;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%自设定阶次n
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if type2 == 1
N2=2;%优化参数个数
%置传递函数系数的下限
V_l2(1:N2)=[-20 10];%G(s)=V1/(V2s+1)^V3
%置传递函数系数的上限
V_h2(1:N2)=[1 500];%G(s)=V1/(V2s+1)^V3
n2=3;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%自设定阶次n
end
if type2 == 2
N2=5;%优化参数个数
%置传递函数系数的下限
V_l2(1:N2)=[-20 5 5 5 0];%G(s)=V1/(V2s+1)^V3
%置传递函数系数的上限
V_h2(1:N2)=[0 300 300 300 0];%G(s)=V1/(V2s+1)^V3
n2(1)=1;
n2(2)=1;
n2(3)=1;
n2(4)=1;
end
if type2 == 3
N2=3;%优化参数个数
%置传递函数系数的下限
V_l2(1:N2)=[-30 5 5];%G(s)=V1/(V2s+1)^V3
%置传递函数系数的上限
V_h2(1:N2)=[-15 100 50];%G(s)=V1/(V2s+1)^V3
n2=3;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%自设定阶次n
end
if type2 == 4
N2=3;%优化参数个数
%置传递函数系数的下限
V_l2(1:N2)=[-30 5 5];%G(s)=V1/(V2s+1)^V3
%置传递函数系数的上限
V_h2(1:N2)=[-15 100 50];%G(s)=V1/(V2s+1)^V3
n2=3;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%自设定阶次n
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if type3 == 1
N3=3;%优化参数个数
%置传递函数系数的下限
V_l3(1:N3)=[-20 10];%G(s)=V1/(V2s+1)^V3
%置传递函数系数的上限
V_h3(1:N3)=[1 500];%G(s)=V1/(V2s+1)^V3
n3=3;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%自设定阶次n
end
if type3 == 2
N3=5;%优化参数个数
%置传递函数系数的下限
V_l3(1:N3)=[-20 5 5 5 0];%G(s)=V1/(V2s+1)^V3
%置传递函数系数的上限
V_h3(1:N3)=[0 300 300 300 0];%G(s)=V1/(V2s+1)^V3
n3(1)=1;
n3(2)=1;
n3(3)=1;
n3(4)=1;
end
if type3 == 3
N3=3;%优化参数个数
%置传递函数系数的下限
V_l3(1:N3)=[-30 5 5];%G(s)=V1/(V2s+1)^V3
%置传递函数系数的上限
V_h3(1:N3)=[-15 100 50];%G(s)=V1/(V2s+1)^V3
n3=3;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%自设定阶次n
end
if type3 == 4
N3=3;%优化参数个数
%置传递函数系数的下限
V_l3(1:N3)=[-30 5 5];%G(s)=V1/(V2s+1)^V3
%置传递函数系数的上限
V_h3(1:N3)=[-15 100 50];%G(s)=V1/(V2s+1)^V3
n3=3;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%自设定阶次n
end
N=N1+N2+N3;
V_l(1:N)=[V_l1 V_l2 V_l3];
V_h(1:N)=[V_h1 V_h2 V_h3];
end
M=50;%粒子个数
S=50;%进化代数
w=0.6;%遗忘因子
c=[0.6 0.6];%学习因子
%置寻优变量初值
V=rand(N,M);
DV=zeros(N,M);
%%%%%%%%%%%%%%
V1=rand(N1,M);
DV1=zeros(N1,M);
V2=rand(N2,M);
DV2=zeros(N2,M);
V3=rand(N3,M);
DV3=zeros(N3,M);
%%%%%%%%%%%%%%
for i=1:M
for j=1:N
V(j,i)=V_l(j)+(V_h(j)-V_l(j))*V(j,i);%%V为N行M列的随机矩阵,每列代表一个粒子,行代表粒子的每个维度
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for j=1:N1
V1(j,i)=V_l1(j)+(V_h1(j)-V_l1(j))*V1(j,i);%%V为N行M列的随机矩阵,每列代表一个粒子,行代表粒子的每个维度
end
for j=1:N2
V2(j,i)=V_l2(j)+(V_h2(j)-V_l2(j))*V2(j,i);%%V为N行M列的随机矩阵,每列代表一个粒子,行代表粒子的每个维度
end
for j=1:N3
V3(j,i)=V_l3(j)+(V_h3(j)-V_l3(j))*V3(j,i);%%V为N行M列的随机矩阵,每列代表一个粒子,行代表粒子的每个维度
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if type == 1
[Q(i),y1]=psoi_obj_1(V(:,i));
end
if type == 2
[Q(i),y1]=psoi_obj_2(V(:,i));
end
if type == 3
[Q(i),y1]=psoi_obj_3(V(:,i));
end
if type == 4
[Q(i),y1]=psoi_obj_4(V(:,i));
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if type == 5
if type1 == 1
[Q1(i),y1]=psoi_obj_1(V1(:,i));
end
if type1 == 2
[Q1(i),y1]=psoi_obj_2(V1(:,i));
end
if type1 == 3
[Q1(i),y1]=psoi_obj_3(V1(:,i));
end
if type1 == 4
[Q1(i),y1]=psoi_obj_4(V1(:,i));
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if type2 == 1
[Q2(i),y1]=psoi_obj_1(V2(:,i));
end
if type2 == 2
[Q2(i),y1]=psoi_obj_2(V2(:,i));
end
if type2 == 3
[Q2(i),y1]=psoi_obj_3(V2(:,i));
end
if type2 == 4
[Q2(i),y1]=psoi_obj_4(V2(:,i));
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if type3 == 1
[Q3(i),y1]=psoi_obj_1(V3(:,i));
end
if type3 == 2
[Q3(i),y1]=psoi_obj_2(V3(:,i));
end
if type3 == 3
[Q3(i),y1]=psoi_obj_3(V3(:,i));
end
if type3 == 4
[Q3(i),y1]=psoi_obj_4(V3(:,i));
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Q(i)=Q1(i)+Q2(i)+Q3(i);
V=[V1 V2 V3];
end
end
Qbi=Q;Vbi=V;
Qbg=
- 1
- 2
前往页