Reading an S2P File - Issues

40 visualizaciones (últimos 30 días)
Kevin Gaukel
Kevin Gaukel el 11 de Dic. de 2013
Respondida: Mark el 29 de Mayo de 2024
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 comentario
John BG
John BG el 1 de Mzo. de 2016
Editada: John BG el 1 de Mzo. de 2016
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?

Iniciar sesión para comentar.

Respuestas (2)

Walter Roberson
Walter Roberson el 2 de Mzo. de 2016
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 el 29 de Mayo de 2024
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

Categorías

Más información sobre Data Import and Network Parameters en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by