i have written the following code for pso based mppt but the simulink model gets stuck at one value and the duty does not change.... kindly suggest me the error
2 views (last 30 days)
Show older comments
function D = PSO(Param, V, I)
% MPPT controller based on the Perturb & Observe algorithm.
% D output = Duty cycle of the boost converter (value between 0 and 1)
%
% V input = PV array terminal voltage (V)
% I input = PV array current (A)
%
% Param input:
%Dinit = Param(1); %Initial value for D output
Dmax = Param(2); %Maximum value for D
Dmin = Param(3); %Minimum value for D
deltaD = Param(4); %Increment value used to increase/decrease the duty cycle D
persistent D_mat_cur Power_old vel max_power_new max_power_old Power_new global_best_duty self_best_duty D_mat_new
pop_size=10;
vmin=-1*deltaD;
vmax=deltaD;
%%wmax=0.9;
%%wmin=0.4;
c1=2;
C=1;
c2=2;
if isempty(Power_old)
%%intiallize all matrices
Power_old=zeros(1,pop_size);
Power_new=zeros(1,pop_size);
vel=zeros(1,pop_size);
D_mat_new=zeros(1,pop_size);
D_mat_cur=rand(1,pop_size);
vel=rand(1,pop_size).*(vmax-vmin)+vmin;
for i=1 : pop_size
if (D_mat_cur(i)>Dmax)
D_mat_cur(i)=Dmax;
end
end
for i=1 : pop_size
if (D_mat_cur(i)<Dmin)
D_mat_cur(i)=Dmin;
end
end
for iter =1:pop_size
D=D_mat_cur(iter);
pause(0.0001)
Power_old(iter)=V*I;
end
[max_power_old,global_index]=max(Power_old);
self_best_duty=D_mat_cur;
global_best_duty=D_mat_cur(1,global_index);
end
iter=0;
max_iter=100;
while iter<max_iter
iter=iter+1;
%calculate power
for iter =1:pop_size
D=D_mat_cur(iter);
pause(0.0001)
Power_new(iter)=V*I;
end
%%update self best duty
for i=1:pop_size
if (Power_new(1,i)>Power_old(1,i))
Power_old(1,i)=Power_new(1,i);
self_best_duty(1,i)=D_mat_cur(1,i);
end
end
%%update global best duty
[max_power_new,index]=max(Power_old);
if (max_power_new>max_power_old)
max_power_old=max_power_new;
global_best_duty=D_mat_cur(1,index);
end
w=.001;
%%calculation of new velocity matrix
for i=1 :pop_size
vel(1,i)= C*(w.*vel(1,i) +c1*rand*(self_best_duty(1,i) - D_mat_cur(1,i)) +c2*rand*(global_best_duty-D_mat_cur(1,i)));
end
%%update positions
D_mat_new=D_mat_cur+ vel;
%%bring back the param that go out of the bounds
%%upper limit
for i=1 : pop_size
if (D_mat_new(1,i)>Dmax)
D_mat_new(1,i)=Dmax;
end
end
%%lower limit
for i=1 : pop_size
if (D_mat_new(1,i)<Dmin)
D_mat_new(1,i)=Dmin;
end
end
D_mat_cur=D_mat_new;
end
[~,global_ind]=max(Power_new);
D=D_mat_cur(1,global_ind);
14 Comments
Chabane Bouali
on 5 Apr 2019
I have the same problem can you send me the correct code of PSO algorithm .
thank you very much
halli aiissa
on 5 Mar 2020
can you send me the ...correct version ...of PSO algorithm.thi is my e-mail: haliaissa11@gmail.com
thank you very much
Answers (3)
Communities
More Answers in the Power Electronics Control
See Also
Categories
Find more on Solar Power in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!