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

140 ビュー (過去 30 日間)
Alexandria Will-Cole
Alexandria Will-Cole 2018 年 11 月 27 日
回答済み: Mark 2022 年 6 月 7 日
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
Alexandria Will-Cole 2018 年 11 月 27 日
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
Alexandria Will-Cole 2018 年 11 月 27 日
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 Center および File ExchangeVisualization and Data Export についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by