您好,欢迎来到华佗养生网。
搜索
您的当前位置:首页matlab谐波分析程序

matlab谐波分析程序

来源:华佗养生网


clc

clear all;

format long;

Ns=1000;

order=13;

%**********************read the position density************************

fid=fopen('B.dat','r'); %open the original file

fidnew = fopen('b1.dat','w'); %write the new file

while feof(fid)==0

tline = fgetl(fid); %tline?

if ~ischar(tline), break, end

temp=abs(tline);

Nlength=length(tline);

and flux

isemptyline=0; %

if Nlength==0

isemptyline=1;

end

allspace=0; %

isspace=0;

for i=1:Nlength

T=temp(i);

if T==32

isspace=isspace+1;

end

if isspace==Nlength

allspace=1;

break

end

end

findalpha=0; %

for j=1:Nlength

T=temp(j);

if ((T>=65)&(T>=90))|((T>=97)&(T>=122))

findalpha=1;

break;

end

end

if (~findalpha)&(~allspace)&(isemptyline==0) %

fprintf(fidnew,tline);

fprintf(fidnew,'\\n');

end

end

fclose(fid);

fclose(fidnew);

fid1=fopen('b1.dat','r');

flux_position =fscanf(fid1,'%f',[2,Ns]);

fclose(fid1);

%********************************read finish*****************************************flux_position=flux_position';

pos1=flux_position(:,1);

pos_delta=pos1(2);

pos_length=length(pos1);

file

pos_last=pos1(pos_length);

for i=1:1:pos_length %copy and get another part of position

pos2(i)=pos_last+i*pos_delta;

end

pos1=pos1';

flux1=flux_position(:,2);

flux2=-flux_position(:,2);

pos=[pos1,pos2];%combine and get all part of position

flux1=flux1';

flux2=flux2';

flux=[flux1,flux2];%combine and get all part of flux density value

figure;

plot(pos1,flux1,'r');%plot origional waveform

hold on;

grid on;

fft1=fft(flux,Ns);

j=0;

amp_har=zeros(1,(order+1)/2);

for m=1:2:order

j=j+1;

fft1=fft(flux,Ns);

fund_ele_front=fft1(m+1);

fund_ele_back=fft1(Ns+1-m);

amp_har(j)=(abs(fund_ele_front))/Ns*2;

fft1=0*fft1;

fft1(m+1)=fund_ele_front;

fft1(Ns+1-m)=fund_ele_back;

fft1=ifft(fft1,Ns);

fft1=real(fft1);

plot(pos1,fft1);

hold on;

end

k=(1:2:order);

figure;

bar(k,amp_har);

grid on;

peak_b=max(fft1)

rms_b=0.707*peak_b

clc

clear all;

format long;

Ns=1000;

order=7;

%**********************read the position density************************

fid=fopen('B.dat','r'); %open the original file

fidnew = fopen('b1.dat','w'); %write the new file

while feof(fid)==0

tline = fgetl(fid); %tline?

if ~ischar(tline), break, end

temp=abs(tline);

Nlength=length(tline);

isemptyline=0; %

and flux

if Nlength==0

isemptyline=1;

end

allspace=0; %

isspace=0;

for i=1:Nlength

T=temp(i);

if T==32

isspace=isspace+1;

end

if isspace==Nlength

allspace=1;

break

end

end

findalpha=0; %

for j=1:Nlength

T=temp(j);

if ((T>=65)&(T>=90))|((T>=97)&(T>=122))

findalpha=1;

break;

end

end

if (~findalpha)&(~allspace)&(isemptyline==0) %

fprintf(fidnew,tline);

fprintf(fidnew,'\\n');

end

end

fclose(fid);

fclose(fidnew);

fid1=fopen('b1.dat','r');

flux_position =fscanf(fid1,'%f',[2,Ns]);

fclose(fid1);

%********************************read finish*****************************************flux_position=flux_position';

pos1=flux_position(:,1);

pos_delta=pos1(2);

pos_length=length(pos1);

pos_last=pos1(pos_length);

file

for i=1:1:pos_length %copy and get another part of position

pos2(i)=pos_last+i*pos_delta;

end

pos1=pos1';

flux1=flux_position(:,2);

flux2=-flux_position(:,2);

pos=[pos1,pos2];%combine and get all part of position

flux1=flux1';

flux2=flux2';

flux=[flux1,flux2];%combine and get all part of flux density value

figure;

plot(pos1,flux1,'r');%plot origional waveform

hold on;

grid on;

fft1=fft(flux,Ns);

j=0;

amp_har=zeros(1,(order+1)/2);

for m=1:2:order

j=j+1;

fft1=fft(flux,Ns);

fund_ele_front=fft1(m+1);

fund_ele_back=fft1(Ns+1-m);

amp_har(j)=(abs(fund_ele_front))/Ns*2;

fft1=0*fft1;

fft1(m+1)=fund_ele_front;

fft1(Ns+1-m)=fund_ele_back;

fft1=ifft(fft1,Ns);

fft1=real(fft1);

plot(pos1,fft1);

hold on;

end

k=(1:2:order);

figure;

bar(k,amp_har);

grid on;

%peak_b=max(fft1)

%rms_b=0.707*peak_b

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- huatuo7.cn 版权所有 湘ICP备2022005869号-9

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务