Plotting Phase angle in Matlab

12 Ansichten (letzte 30 Tage)
Matthew Portnoy
Matthew Portnoy am 25 Okt. 2020
Kommentiert: Sindar am 25 Okt. 2020
I am trying to plot 2 phase angle graphs based on two impedance calculations. The problem is when i try to calculate the angle with unwrap(angle(Zc)), the plot looks nothing like it should. I am using 5 different text files as data, those are attached. And below is my code and my graphs, then graphs of what I am supposed to be getting.
clear all;
clc;
load freq1.txt;
load Rzero1.txt;
load Lzero1.txt;
load Rpos1.txt;
load Lpos1.txt;
Czero = 7.524/1e3;
Cpos = 1.2027/1e3;
Gzero = 2/1e8;
Gpos = 2/1e8;
w(1)=0;
Zc(1)=0;
Zcpos(1)=0;
Zcmag(1)=0;
Zcposmag(1)=0;
i=1;
k=1;
n=10;
for i=1:size(Rzero1,1)
w(i) = 2*pi*freq1(i);
Zcmag(i) = abs(((Rzero1(i)+1j*w(i)*Lzero1(i))./(Gzero+1j*w(i)*Czero))); %magnitude of Zc
Zc(i) = sqrt(((Rzero1(i)+1j*w(i)*Lzero1(i))./(Gzero+1j*w(i)*Czero)));
end
for k=1:size(Rpos1,1)
w(k) = 2*pi*freq1(k);
Zcposmag(k) = abs(((Rpos1(k)+1j*w(k)*Lpos1(k))./(Gpos+1j*w(k)*Cpos))); %magnitude of Zc
Zcpos(k) = sqrt(((Rpos1(k)+1j*w(k)*Lpos1(k))./(Gpos+1j*w(k)*Cpos)));
end
figure(1)
semilogx(freq1,Zcmag);
figure(2)
semilogx(freq1,Zcposmag)
Zcphase = unwrap(angle(Zc));
Zcposphase = unwrap(angle(Zcpos));
figure(3);
semilogx(freq1,Zcphase);
figure(4);
semilogx(freq1,Zcposphase);
Zc phase for zero sequence
Zc phase for positive sequence

Antworten (1)

Sindar
Sindar am 25 Okt. 2020
First off, "load" is for Matlab files, not raw text. Check out textscan. If your code isn't error-ing, you probably have old versions of the variables sitting around somehow
Next, there are several code issues to clean up:
This loop can be done with elementwise vector operations. Change it from
for i=1:size(Rzero1,1)
w(i) = 2*pi*freq1(i);
Zcmag(i) = abs(((Rzero1(i)+1j*w(i)*Lzero1(i))./(Gzero+1j*w(i)*Czero))); %magnitude of Zc
Zc(i) = sqrt(((Rzero1(i)+1j*w(i)*Lzero1(i))./(Gzero+1j*w(i)*Czero)));
end
to
w = 2*pi*freq1;
Zc(i) = sqrt((Rzero1+1j*w.*Lzero1)./(Gzero+1j*w*Czero));
Zcmag = abs(Zc.^2);
Also, these lines are completely unnecessary:
w(1)=0;
Zc(1)=0;
Zcpos(1)=0;
Zcmag(1)=0;
Zcposmag(1)=0;
i=1;
k=1;
  1 Kommentar
Sindar
Sindar am 25 Okt. 2020
Huh, reading the load documentation, it actually does support text files. Still not a good choice, but perhaps not the source of your problem

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by