USE MATLAB IMPEDANCE.txt 2. (New) Create a script for the following problem An e
ID: 2249167 • Letter: U
Question
USE MATLAB
IMPEDANCE.txt
2. (New) Create a script for the following problem An engineer had measured impedances of a collection of electrical components and created a text file - impedance.txt - based on the numeric:al data. You will find that impedance.txt on Canvas. The first Row of the file is MAGNITUDE of the impedance and the second Row ithe PHSE (in radian) of the impedance. Column number indicates the number of components. Here are the needed conditions. (1) will read the impedance.txt and find the Column number (You can u 'size' function) (2) compute real part and imaginary part of impedance of individual component. (3) Save the result on a variable Impedance Catesian. (4) Save the result on a text file Impedance_Cartesian.txt (5) Also have this following message displayed on the screen (There are ### components in the file impedance.txt. The Conversion of POLAR format of complex number into CARTESIAN format is completed and the esult is saved on Impedance_Cartesian.txt") (6) Do this with FOR LOOP OR WHILE LOOP (Only a single script is needed!) Conversion Equation from Polar into Cartesian From MAGNITUDE 4 PHASE ANGLE REAL +jIMAGINARY REAL-MAG * cos(PHASE ANGLE) IMAGINARY MAGNITDE * sin(PHASE ANGLE) *is not Convolution. It is product!Explanation / Answer
clear all
fileID = fopen('Impedance.txt','r');
a=0;
m=1;
p=1;
k=1;
while a~=-1
a=fgetl(fileID);
if a==-1
break
end
temp=str2num(a);
if mod(k,2) == 1
for i=1:length(str2num(a))
mag(m,i)=temp(i);
end
m=m+1;
end
if mod(k,2) == 0
for i=1:length(str2num(a))
phase(p,i)=temp(i);
end
p=p+1;
end
k=k+1;
end
[m,p]=size(mag);
for i=1:m
for k=1:p
Impedance_Cartesian(i,k)=(mag(i,k)*cos(phase(i,k))+(mag(i,k)*sin(phase(i,k)))*1j);
end
end
[m,p]=size(Impedance_Cartesian);
z_real = real(Impedance_Cartesian);
z_imag = imag(Impedance_Cartesian);
a=num2str(Impedance_Cartesian);
formatSpec = '%6.4f %6.4f*i ';
fileID = fopen('Impedance_Cartesian.txt', 'w');
for i=1:length(m)
fprintf(fileID,formatSpec,real(Impedance_Cartesian),imag(Impedance_Cartesian));
end
fprintf(['There are ' num2str(p) ' companents in the file impedance.txt. The Conversion of POLAR format of complex number into CARTESIAN format is completed and the result is saved on Impedance_Cartesian.txt'])
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.