Invalid syntax at'='. Possibly, a ')' is missing.error in this sentence .a red line under the "=" sign.

조회 수: 1 (최근 30일)
Va_5_hf=(Va_5_har_mag)*(100/Va_5_har_mag(2)) ;
There's a Invalid syntax at'='. Possibly, a ')' is missing.error in this sentence .a red line under the "=" sign.
Thanx in advance
file='C:\Users\macbook\Desktop\Powerquality\Assignment1.xls';
data=xlsread('file','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', 10,' XTick', [1 1*step+13*step+15*step+17*step+19*step+1
+11*step+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(1i)).^2;
END
Va_3_IHD=Va_3_har_mag(1i)*100/Va_3_har_mag(2)*100;
FOR i=3:20
Va_3_IHD=Va_3_har_mag(1i)*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(1i)).^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 (1i)*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 (1i)*Ia_3_har_mag(1i)*cos(A_3_phase(1i) *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(1i)).^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(1i)*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 (1i)).^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(1i)*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);
  댓글 수: 1
dashi daqianbao
dashi daqianbao 2019년 12월 11일
file='C:\Users\macbook\Desktop\Powerquality\Assignment1.xls';
data=xlsread('Assignment1.xls','Sheet2','B4:G1155');
nn.JPG
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);

댓글을 달려면 로그인하십시오.

답변 (2개)

Image Analyst
Image Analyst 2019년 12월 11일
편집: Image Analyst 2019년 12월 11일
FOR and END need to be lower case.
You forgot to attach C:\Users\macbook\Desktop\Powerquality\Assignment1.xls so we can't run your code.
It looks like in this line(s):
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'}
you're missing a comma and ... after the third line. And a closing parenthesis. Should be
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'} )
You know, there are functions xticks() and xticklabels() that you should use instead of set().

Image Analyst
Image Analyst 2019년 12월 11일
Assignments are made with a single equals sign, not a double equals sign. I fixed a ton of those and then it bombed when you get to referencing data1, which I and the program don't know what it is. But here's what I have so far.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
file='Assignment1.xls';
data=xlsread(file,'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]),
XTickLabels = {'0','1','3','5','7','9','11','13','15','17','19'};
xticklabels(XTickLabels);
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;
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];
xticks(XTick);
ax = gca
ax.FontSize = 12;
XTickLabels ={'0','1','3','5','7','9', '11', '13', '15', '17', '19'};
xticklabels(XTickLabels);
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);
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]
ax = gca;
ax.FontSize = 12;
xticks(XTick);
XTickLabels = {'0', '1', '3','5','7'...
,'9',' 11','13', '15', '17', '19'};
xticklabels(XTickLabels);
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);
  댓글 수: 2
dashi daqianbao
dashi daqianbao 2019년 12월 12일
your help is greatly appreciated , im also having a trouble on that part .Error using " bar"
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
file='Assignment1.xls';
data=xlsread(file,'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=data(:,2);
Ib=data(:,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=data(:, 3);
Ic=data(:,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);
Ia_3_fft_result=fft(Va_3)/(len/2);
Ia_phase=atan ((Ia_3_fft_result)./real(Ia_3_fft_result))*180/pi;
Ia_3_har_mag = abs(Ia_3_fft_result);
figure(3);
bar(Ia_3_har_mag(1:20),0.4)
xlabel('Harmonic Order','fontsize',10);
ylabel('Voltage (V)','fontsize',10)
step = 1;
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]
ax = gca;
ax.FontSize = 12;
xticks(XTick);
XTickLabels = {'0', '1', '3','5','7'...
,'9',' 11','13', '15', '17', '19'};
xticklabels(XTickLabels);
figure(6);
freq=50;
bar(freq,(Ia_3_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_3_har_mag(2);
xlabel(' Frequency (Hz)','fontsize',20);
ylabel('% of fundamental (%)' ,'fontsize', 20);
%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;
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];
xticks(XTick);
ax = gca
ax.FontSize = 12;
XTickLabels ={'0','1','3','5','7','9', '11', '13', '15', '17', '19'};
xticklabels(XTickLabels);
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(A)','fontsize',10);
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]
ax = gca;
ax.FontSize = 12;
xticks(XTick);
XTickLabels = {'0', '1', '3','5','7'...
,'9',' 11','13', '15', '17', '19'};
xticklabels(XTickLabels);
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);
Walter Roberson
Walter Roberson 2019년 12월 12일
See the first example in the fft documentation for how to calculate the frequencies associated with each bin.
Note that you are plotting for all bins, including both positive and negative time. The example in the documentation plots for positive time only, so you will want to make appropriate adjustments. You might want to use fftshift()

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Axis Labels에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by