필터 지우기
필터 지우기

Reading an S2P File - Issues

조회 수: 32 (최근 30일)
Kevin Gaukel
Kevin Gaukel 2013년 12월 11일
답변: Mark 2024년 5월 29일
I have been trying to use dlmread to read in an S-parameter file (S2P file), but have had issues. The enclosed file (ExampleS2pFile.txt - which is actually .s2p but MATLAB CENTRAL will not allow attachment of an S2p File directly) contains a typical 2-Port Sparameter file which has been verified as working.
When I enter the following
Sparmtrx = dlmread('ExampleS2pFile.s2p','');
I get an error message corresponding to the "header file of the S-parameter matrix
Error using dlmread (line 139)
Mismatch between file and format string.
Trouble reading number from file (row 1u, field 1u) ==> # MHz S DB R 50\n
When I start on row 2 - which is where the issue starts,
Sparmtrx = dlmread('ExampleS2pFile.txt','',2,0);
I get the following message:
Error using dlmread (line 139)
Mismatch between file and format string.
Trouble reading number from file (row 2u, field 1u) ==> \n
When I go to column 1
Sparmtrx = dlmread('ExampleS2pFile.txt','',2,1);
I lose the first column of the S-parameter file - the one associated with frequency, and I get a row of zeros between each line.
-0.0060 -15.1590 -84.3870 -68.6250 -84.3870 -68.6250 -0.02000 74.26100
0 0 0 0 0 0 0 0
-0.0060 -15.166 -84.369 -68.6450 -84.3690 -68.645 -0.020 74.2370
0 0 0 0 0 0 0 0
When I manually remove the header, I get the correct format
19263 -0.0060 -15.1900 -84.3150 -68.705 -84.3150 -68.705 -0.0210 74.165
19263.25 -0.0060 -15.1980 -84.2960 -68.725 -84.296 -68.7250 -0.021 74.141
I would like to know how this error is turning up with the header and is gone without it. I am seeing a potential bug in dlmread, and removing the header of the S2P files is a NONOPTION!
Please help
Thanks
Kevin M Gaukel MSEE
  댓글 수: 1
John BG
John BG 2016년 3월 1일
편집: John BG 2016년 3월 1일
rename the file to file_name_s2p.m
attach it
interested readers will change the file extension back to .s2p and then find an answer, hopefully
What is the DUT, partly damaged/squashed coaxial?
'.. contains 2-Port Sparameter file which has been verified as working ..'
can you supply at least s21 as well?

댓글을 달려면 로그인하십시오.

답변 (2개)

Walter Roberson
Walter Roberson 2016년 3월 2일
dlmread() historically could not be used for files that contain any text (other than the delimiter itself), even if the text is in header lines or columns that the range parameter told the reading to skip. Support for skipping text headers might have been added as of R2015a (we happened to notice that the documentation of the restriction is no longer there.)
textscan() does not have the same restriction, but it does require that you provide the format instead of it figuring out the number of columns.
fmt = repmat('%f', 1, 9);
fid = fopen('ExampleS2pFile.txt', 'rt');
datacell = textscan(fid, fmt, 'HeaderLines', 2, 'CollectOutput', 1);
fclose(fid);
data = datacell{1};

Mark
Mark 2024년 5월 29일
You can use the sparameters method to read in Touchstone format files.
S = sparameters('ExampleS2pFile.txt')
% or from the original .s2p file
S = sparameters('ExampleS2pFile.s2p')
The sparameters reader uses the official Touchstone 2.0 reader supported by the IBIS committee.
>> S = sparameters('ExampleS2pFile.s2p')
S =
sparameters with properties:
Impedance: 50
NumPorts: 2
Parameters: [2×2×4001 double]
Frequencies: [4001×1 double]
>> S.Parameters(:,:,1)
ans =
0.9645 - 0.2613i 0.0000 - 0.0001i
0.0000 - 0.0001i 0.2706 + 0.9603i

카테고리

Help CenterFile Exchange에서 Large Files and Big Data에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by