apf,stattcom,inverter

by

 

power electronic simulation

[fftv,vao]=modulation(N,M,V)
%main menu to select the number of levels of the inverter
%the number of solution sets required,the maximum
%the number of iterations,the minimum error tolerable,and
%up to what number of harmonics will be minimized.
function[p]=mainmenu(px)
clc
disp(sprint('1-change the number of levels :%g',px(1)));
disp(sprint('2-change number_of_points :%g',px(2)));
disp(sprint('3-change the maximum number of iterations :%g',px(3)));
disp(sprint('4-change the minimum error (percent) :%g',px(4)));
disp(sprint('5-eliminate (6n+1)harmonics.n :%g',px(5)));
p=input('Make a selection(1-4)or press enter to run : ',1);
if(isempty(p)==1),p=0;end
%Finds the optimum angles to minimize up to the 6n+-1th harmonics using GA
%uses functions
%   "fitness.m" to evaluvate the fitness of the population
%   "mainmenu.m"to display an options menu
%
%if the percentage of the sum of the selected harmonics is less than
% "minh",the solution is accepted,if not it is not accepted
%
%if some solutions are not accepted,then "number of points"will be
%different then the "number of iterations",otherwise they will be the
%same
%
% For n cascaded converters,the number of levels is 2n+1
clear
global harm_n
p=100;
k=7;nop=2000;mnoi=20000;minh=2;harm_n=8;
px=[7 2000 20000 2 8];
while p~=0
    p=mainmenu(px);
    switch p
        case 0
        case 1
            k=(input('number of levels(default 7)=  ')-1)/2;
            if isempty(k),k=3;end
            px(1)=2*k+1;
        case 2
            nop=input('number_of_points(default 2000): ');
            if isempty(nop),nop=2000;end
            px(2)=nop;
        case 3
             mnoi=input('maximum number of iterations(default 20000): ');
             if isempty(mnoi),mnoi=20000;end
             px(3)=mnoi;
        case 4
            minh=input('minimum error(default 2):  ');
            if isempty(minh),minh=2;end
            px(4)=minh;
        case 5
            harm_n=input('eliminate(6n+1)harmonics.n(default 8):  ');
            if isempty(harm_n),harm_n=2;end
            px(5)=harm_n;
        otherwise
            disp('Error 01:Enter a value between 0 and 4')
            disp('Press enter to continue')
            pause
    end
end
k=(px(1)-1)/2;
nop=px(2);
mnoi=px(3);
minh=px(4);
for i=1:k
    pool(i,:)=[.01 .99];
end
file='fitness';
n=100;
out=zeros(1,k+3);
it=1;
it_all=0;
flag1=0;
VV=125*ones(1,k);
while(it<nop)
    it_all=it_all+1;
    if it_all==mnoi,return,end
    if flag1==1
        it=size(out,1)+1;
        flag1=0;
    else
        it;
    end
    %create a random initial population of size 20
    initPop=initializega(20,pool,file);
    for i=1:20
        initPop(i,1:k)=sort(initPop(i,1:k));
    end
    [x endPop]=ga(pool,file,[],intpop,[1e-6 1 1],'maxgen term',n);
    if (-x(k+1)<minh)
        MM=x;
        N=4096;
        [fftvaoo vaoo]=modulation(N,MM,VV);
        vvv=abs(fftvaoo(2));
        sumhh=0;
        for g =1:harm_n
            h55=abs((fftvaoo(6*g+1+1)));%(6n+1)th harmonic
            h77=abs((fftvaoo(6*g-1+1)));%(6n-1)th harmonic
            sumhh=sumhh+h55+h77;
        end
        xx=sort(x(1:k))*90;
        out(it,:)=[xx(1:k)vvv/sum(VV)-x(k+1)100*(sumhh)/vvv];%The best found
        it=it+1;
        flag1=0;
    else
        flag1=1;
    end
    if flag1==0
        figure(1)
        subplot(2,1,1),plot(0:N/2-1,abs(fftvaoo(1:N/2)));
        axis([0,50,0,(abs(fftvaoo(2))*1.01)]);
        subplot(2,1,2),plot(vaoo)
        hold,plot(abs(fftvaoo(2))*sin(2*pi*(1:N)/N,'r'),hold
        figure(2)
        subplot(3,1,1)
        for i=1:k
            plot(out(:,k+1),out(:,i),'.'),
            if i==1,hold,end
            if i==k,hold off,end
        end
        subplot(3,1,2)
        plot(out(:,k+1),sum(out,2)/(k*90),'.'),hold,
        plot(out(:,k+1),4/pi-out(:,k+1),'r'),
        plot(out(:,k+1),1-out(:,k+1),'g'),hold,ylabel('overall M')
        subplot(3,1,3),
        plot(out(:,k+1),(out(:,k+2)),'.'),hold on
        plot(out(:,k+1),(out(:,k+3)),'r'),hold off,ylabel('cost function')
    end
    drawnow
end
%Evaluate the fitness of the chromosomes
function[sol,val]=fitness(sol,options)
global harm_n
M=sol;
N=4096;%N is a power of 2
kk=max(size(sol))-1;
V=125*ones(1 kk);
[fftvao v]=modulation(N,M,V);
vv=abs(fftvao(2));
sumh=0;
for g=1:harm_n
    h5=abs((fftvao(6*g+1+1))); %(6n+1)th harmonic
    h7=abs((fftvao(6*g-1+1))); %(6n-1)th harmonic
    sumh=sumh+h5+h7;
end
val=-100(sumh)/vv;
%Modulation creates the multilevel output voltage
function [fftv,vao]=modulation(N,M,V)
nn=1:N;
vc(1:N/4)=nn(1:N/4)/(N/4);
vc(N/4+1:N/2)=fliplr(vc(1:N/4));
vc(N/2+1:N)=-(vc(1:N/2));
for i=1:max(size(V))
    v(i,1:N)=M(i)<=abs(vc))*V(i);
end
vao=sum(v).*sign(vc);
fftv=2*fft(vao)/N;

            
            


Contact us