How do I export data from an .s2p file in MATLAB?

139 次查看(过去 30 天)
Hi,
I have a sequence of .s2p touchstone files that I need to analyze data from. I am currently using the RF toolbox and have used these commands to export the data:
%load in touchstone s2p data file
data = read(rfdata.data,myfilename);
%sort by data
freq = data.Freq;
s_params = extract(data,'S_PARAMETERS',50);
% data
s11 = s_params(1,1,:);
s22 = s_params(2,2,:);
s21 = s_params(2,1,:);
s12 = s_params(1,2,:);
However, I'd prefer to export the data in a more manual way and not use the toolbox command, because I'm not sure if it is identifying the correct columns of data... it doesn't make 100% sense when I do this. Is there a way I can open the file and import the file as a matrix then seperate out the data? I'm thinking of using something like this:
f = myfilename(:,1); ReS11 = myfilename(:,2); ImS11 = myfilename(:,3); ReS21 = myfilename(:,4); ImS21 = myfilename(:,5); ReS12 = myfilename(:,6); ImS12 = myfilename(:,7); ReS22 = myfilename(:,8); ImS22 = myfilename(:,9);
%Creating the S Parameter Matrix
s11=ReS11+1i*(ImS11);
s12=ReS12+1i*(ImS12);
s21=ReS21+1i*(ImS21);
s22=ReS22+1i*(ImS22);
I just am not sure how to actually get the data imported into my MATLAB script in an automated way. Please help!
Thanks,
  2 个评论
Alexandria Will-Cole
I understand the file format of touchstone files, but my coding in MATLAB is still novice. I just want to know how to import the .s2p file into MATLAB without using the RF Toolbox in MATLAB, because it is not importing correctly. How can I do this manually in MATLAB?I also want my code to be fairly generic in case I want to change languages from MATLAB to something like python.

请先登录,再进行评论。

采纳的回答

Mark
Mark 2022-6-7
The RF Toolbox offers an sparameters object that can read in and manipulate data from Touchstone files
>> obj = sparameters('passive.s2p')
obj =
sparameters: S-parameters object
NumPorts: 2
Frequencies: [202×1 double]
Parameters: [2×2×202 double]
Impedance: 50
rfparam(obj,i,j) returns S-parameter Sij
The RF Toolbox also offers many functions for manipulating and plotting S-parameter data.

更多回答(1 个)

Alexandria Will-Cole
Okay, I just noticed the first link. The only problem I have with that is that they are reading in a text file. Do you know how I can change the file extension on my .s2p files within my script? There are too many to do prior to the code.

类别

Help CenterFile Exchange 中查找有关 Visualization and Data Export 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by