file='C:\Users\macbook\Desktop\Powerquality\Assignment1.xls';
data=xlsread('Assignment1.xls','Sheet2','B4:G1155');
data=round(data);
t=1/7680:1/7680:3/20;
%Voltage and current curve for all phases abc
Va=data(:,1)
Ia=data(:,4);
figure(1);
a=plotyy(t,Va,t,Ia)
set(get(a(1),'Ylabel'),'String','Voltage(V)')
set(get(a(2),'Ylabel'),'String','Current(A)')
Vb = data1(:,2);
Ib=data1(:,5);
figure(2);
a=plotyy(t,Vb,t,Ib)
set(get(a(1),'Ylabel'),'String','Voltage(v)')
set(get(a(2), 'Ylabel'), 'String', 'Current(A)')
Vc=datal(:, 3);
Ic=datal(:,6)
figure(3)
a=plotyy(t, Vc, t, Ic)
set(get(a(1), 'Ylabel'),'String','Voltage(V)')
set(get(a(2),' Ylabel'),' String', 'Current(A)')
%finding frequency spectrum and harmonic frequency content
t=1/20:1/(60*128):1/15;
Va_3=data(256:1:384,1);
len=length(t);
Va_3_fft_result=fft(Va_3)/(len/2);
Va_phase=atan ((Va_3_fft_result)./real(Va_3_fft_result))*180/pi;
Va_3_har_mag = abs(Va_3_fft_result);
figure(3);
bar(Va_3_har_mag(1:20),0.4)
xlabel('Harmonic Order','fontsize',10);
ylabel('Voltage (V)','fontsize',10)
step = 1;
set(gca,'fontsize', 10, 'XTick', [11*step+13*step+15*step+17*step+19*step
11*step+1 13*step+1 ...
15*step+17*step+19*step+1]),
'XTickLabel', {'0','1','3','5','7'... ,'9','11','13','15','17','19'});
figure(6);
bar(freq,(Ia_har_mag)*100/(Ia_3_har_mag(2)))
Ia_3_hf==(Ia_3_har_mag)*100/(Ia_3_har_mag(2));
Ia_3_f==Ia__har_mag(2);
xlabel(' Frequency (Hz)','fontsize',10);
ylabel('% of fundamental (%)' ,'fontsize', 10);
%next period of the disturbance is the fifth period
t==1/12:1/6400:1/10;
Va_5==data(640:1:768,1)
len==length(t);
Va_5_fft_result==fft(Va_5)/(len/2);
Va_5_phase==atan((Va_5_fft_result)./real(Va_5_fft_result))*180/pi;
Va_5_har_mag==(Va_5_fft_result);
figure(7);
bar(Va_5_har_mag(1:20),0.4)
xlabel(' Harmonic Order', fontsize', 10);
ylabel(' Voltage (v)','fontsize', 10);
step==1;
set(gca,'fontsize', 12,' XTick', [1 1*step+1 3*step+1 5*step+1 7*step+9*step+1
11*step+1 13*step+1....
...15*step+1 17*step+1 19*step+1],
'XTickLabel',{'0','1','3','5','7'...
,'9', '11', '13', '15', '17', '19'};
figure(8)
bar(freq,(Va_5_har_mag)*100/(Va_5_har_mag(2)));
Va_5_hf==(Va_5_har_mag)*100/(Va_5_har_mag(2));
Va_5_f==Va_5__mag(2);
xlabel(' Frequency (Hz)','fontsize', 10);
ylabel('% of fundamental (%)' ,'fontsize',10);
Ia_5==data(640:1:768,4)
len==length(t);
Ia_5_fft_result==fft(Ia_5)/(len/2);
Ia_5_phase==atan ((Ia_5_fft_result)./real(Ia_5_fft_result))*180/pi;
Ia_5_har_mag==abs(Ia_5_fft_result);
bar(Ia_5_har_mag(1:20),0.4)
xlabel('Harmonic Order','fontsize',10);
ylabel('Current()','fontsize',10);
set(gca, 'fontsize', 12,'XTick', ({1 1*step+1 3*step+1 5*step+1 7*step+1 9*step+1
11*step+1 13*step+1....
15*step+1 17*step+1 19*step+1})),...
'XTickLabel', {'0', '1', '3','5','7'...
,'9',' 11','13', '15', '17', '19'}
figure(10);
bar(freq,(Ia_5_har_mag)*100/(Ia_5_har_mag(2)))
Ia_5_hf==(Ia_5_har_mag)*100/(Ia_5_har_mag(2));
Ia_5_f==Ia_5_har_mag(2);
xlabel(' Frequency (Hz)', fontsize', 10);
ylabel('% of fundamental (%)','fontsize', 10);
%code for the calculation of IHD, THD, P, S
%period before the disturbance is the third period
Va_3_sum==0;
for i=3:20
Va_3_sum=Va_3_sum+(Va_3_har_mag(i)).^2;
end
Va_3_IHD=Va_3_har_mag(i)*100/Va_3_har_mag(2)*100
for i=3:20
Va_3_IHD=Va_3_har_mag(i)*100/Va_3_har_mag(2);
end
Ia_3_sum=0;
for i=3:20
Ia_3_sum=Ia_3_sum+(Ia_3_har_mag(i)).^2;
end
Ia_3_THD=(sqrt(Ia_3_sum)/a_3_har_mag(2))*100;
for i=1:20
Ia_3_IHD=Ia_3_har_mag (i)*100/Ia_3_har_mag(2)*100;
end
A_3_phase=Va_3_phase-Ia_3_phase;
for i=1:20
P_3=P_3+0.5*Va_3_har_mag (i) *Ia_3_har_mag(i)*cos(A_3_phase(i) *pi/180);
end
Va_3_sum=Va_3_sun+(Va_3_har_mag(1)).^2+(Va_3_har_mag(2)).^2;
Ia_3_sum=Ia_3_sum+(Ia_3_har_mag(1)).^2+(Ia_3_har_mag(2)).^2;
s_3=sqrt(Va_3_sum*Ia_3_sum);
%The period after the disturbance is the fifth period
Va_5_sum=0
for i=3:20
Va_5_=Va_5_sum+(Va_5_har_mag(i)).^2;
end
Va_5_THD=(sqrt(Va_5_sum) /Va_5_har_mag (2)*100);
for i=1:20
Va_5_IHD=Va_5_har_mag(i)*100/Va_5_har_mag(2);
end
Ia_5_sum=0
for i=3:20
Ia_5_sum=Ia_5_sum+(Ia_5_har_mag (i)).^2;
end
Ia_5_THD=(sqrt(Ia_5_sum)/Ia_5_har_mag(2))*100;
for i=1:20
Ia_5_IHD=Ia_5_har_mag(i)*100/Ia_5_har_mag(2);
end
A_5_phase=Va_5_phase-Ia_5_phase;
P_5=0;
for i=1:20
P_5=P_5+0.5*Va_5_har_(i) *Ia_5_har_mag(i) *cos(A_5_phase(i) *pi/180);
end
Va_5_sum=Va_5_sum+(Va_5_har_mag(1)).^2+(Va_5_har_mag (2)).^2;
Ia_5_sum=Ia_5_sum+(Ia_5_har_mag(1)).^2+(Ia_5_har_mag(2)).^2;
S_5=sqrt(Va_5_*Ia_5_sum);