Hi,
I have text file which has freq and s21 value(In cartesian form and polar form ).
Need a help in convertering those S-paramteres to Z- parameters
I tried to use s2z command, but i doesn't work in this.
Could any one please help me resolve the problem?

 Akzeptierte Antwort

William Rose
William Rose am 17 Jan. 2022

0 Stimmen

How do you know s2z does not work? Do you get an error message, and if so, what?
The input to s2z must be complex numbers, in the form Re + i*Im. The file you provided has a header line and three columns: frequency, real part, imaginary part. It uses two different separators: tab and comma. That is annoying because it complicates the reading in of the data.
I assume that the data is in real, imaginary format. Change it to complex:
z=Re+1i*Im
Then use s2z.

9 Kommentare

Thank you for the help, could you please help me to convert the z parameter to table form.
data = readcell('s21.txt');
[rows, columns] = size(data);
counter = 0;
for row = 1 : rows
thisCellContents = data{row, 1};
if contains(thisCellContents, 'Freq');
% Skip a text line in the middle of all the data.
continue;
end
counter = counter + 1;
column1(counter) = str2double(thisCellContents(1:21));
column2(counter) = str2double(thisCellContents(23:end-1));
column3(counter) = data{row, 2};
end
fprintf('Done parsing %d lines of data to get %d numbers per vector.\n', rows, counter);
a=column1;
b=column2.';
c=column3.';
T = complex(b,c);
Z=s2z(T,50);
%%% COnvert above Z to table form%%%%
X=struct2table(Z);
It was easier for me to import the text file you provided to Excel. Therefore I did that. Then I saved the data, without the header line, to a text file, with tab separators (not tab plus comma). That file is attached to this message. It is easy to load the data from that file and convert columns 2 and 3 from s plane to z plane:
A=load('s21.txt','-ascii');
s=A(:,2)+1i*A(:,3);
z=s2z(s);
Try it.
A plot of the real and imaginary parts versus frequency shows that the values of s(f) repeat, and the repeat period is about 1.5E8 Hz:
A=load('s21.txt','-ascii');
figure; plot(A(:,1),A(:,2),'-r',A(:,1),A(:,3),'-b');
grid on; legend('Real','Imag');
xlabel('Frequency'); ylabel('s(f)');
Therefor, let us plot s(f) for one cycle of frequencies. At higher frequencies, s(f) repeats itself.
N1=find(A(:,1)>=1.5e8,1); %index corresponding to one cycle of s(f)
figure; plot(A(1:N1,2),A(1:N1,3),'-kx'); grid on; axis equal;
xlabel('Re(s)'); ylabel('Im(s)'); title('s plane');
s2z adds an extra dimension to the array, which complicates plotting. Squeeze array z after creating it with s2z, to eliminate the extra dimension:
s=A(:,2)+1i*A(:,3);
z=s2z(s);
z=squeeze(z);
Next: plot z(f) for one cycle:
figure;
plot(real(z(1:N1)),imag(z(1:N1)),'-bx'); title('z plane');
grid on; axis equal
The default reference impedance for s2z() is 50 Ω. That is why real(s)=0 maps to real(z)=50. Good luck.
Venkatkumar M
Venkatkumar M am 19 Jan. 2022
Bearbeitet: Venkatkumar M am 19 Jan. 2022
@William Rose Simple question is it posisble to do the same process with freq and polar form data(s21_db.txt)?
@Venkatkumar M, yes you can do it.
First, you must get the data from file s21_db.txt into a numeric array or vectors. I used the Import Tool in Matlab to import the data from file s21_db.txt. In the ImportData tool, I defined delimiters tab, comma, left parenthesis, right parenthesis, and "dB". I told import Tool to treatmultiple delimiters as one. I imported the columns as three column vectors: freq, magdB, and angle.
Then you convert the data from [dB, angle in degrees] to a vector of complex numbers as follows:
s=10.^(magdB/20).*(cos(angle*pi/180)+1i*sin(angle*pi/180));
Now you convert the complex vector s to z values:
z=s2z(s);
or you can do
z=squeeze(s2z(s));
to eliminate the extra dimension that is created by s2z().
Venkatkumar M
Venkatkumar M am 20 Jan. 2022
Bearbeitet: Venkatkumar M am 20 Jan. 2022
Is there way to delimeter (tab, comma, left parenthesis, right parenthesis, and "dB") this thing using command delimeter in readtable function in editor instead importing it and naming it
@Venkatkumar M, Yes, you can use readtable to read in the file s21_dB.txt. See the following:
delims={'dB,','(',')','tab',char(176)};
T=readtable('s21_db.txt','Delimiter',delims);
whos('T');
Name Size Bytes Class Attributes T 15957x3 384383 table
The variable names are the default values: T.Var1, T.Var2, T.Vvar3. If you want to rename the variable name, do the following:
T = renamevars(T,["Var1","Var2","Var3"],["freq","magdB","phase"]);
Use the vectors in the table to compute the complex numbers for s2z.
s=10.^(T.magdB/20).*(cos(pi*T.phase/180)+1i*sin(pi*T.phase/180));
z=squeeze(s2z(s));
whos('z');
Name Size Bytes Class Attributes z 15957x1 255312 double complex
Try.
I am getting error in function renamevars
Undefined function 'renamevars' for input arguments of type 'table'.
Error in s_parm_db_to_z_param_1 (line 7)
T = renamevars(T,["Var1","Var2","Var3"],["freq","magdB","phase"]);
could you please clarify this?
William Rose
William Rose am 21 Jan. 2022
@Venkatkumar M, I don;t know why you get an error. The error message suggests Matlab is not finding the function renamevars(). renamevars is art of basic Matlab - nt some Toolbox. Therefore it should work.
Did renamevars get overwritten by accident? Try "clear renamevars" to address this possibility, then try your code again.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by