Convert S2P to CSV: What Changes, What Can Be Lost, and When to Keep the Original
A practical review of converting Touchstone S2P files to CSV: what the conversion changes, how units and column order can be lost, and when to keep the S2P file.
An S2P file is a Touchstone file. It stores network parameters, usually S-parameters, for a two-port device across a range of frequencies. Converting it to CSV is a delimited-text task. It is not a visual text effect. This review covers what the conversion does, what it can silently drop, and how to check that the CSV still means what the original file meant.
Scope note: no specific converter product was examined or tested for this article, and no measurements were taken. The guidance below rests on the publicly documented structure of the Touchstone format and on general behavior of CSV files. Where a claim would depend on a particular tool or destination, that is flagged as something to verify yourself.
Is converting S2P to CSV suitable for your use?
It is a good fit if you want to plot, filter or compare the data in a spreadsheet, a database or a general-purpose analysis script. It also helps when you need to hand the numbers to someone who does not use RF software. The main benefit is that CSV has one value per cell and a named header row, so the data is easy to sort, chart and import almost anywhere.
The decisive tradeoff is context. An S2P file carries more than numbers: an option line declares the frequency unit, the parameter type, the number format and the reference impedance. A plain CSV has no standard place for that information. If a conversion drops it, the numbers survive but their meaning does not.
Keep the original S2P file in these cases:
- The data will go into a circuit simulator, network analyzer software or another RF tool that already reads Touchstone files.
- You are archiving measurement or vendor data and need an authoritative copy.
- The file contains noise parameters, comments, or Touchstone 2.0 keywords that you do not intend to handle explicitly.
- The recipient is an RF engineer who expects the standard format.
In most workflows the safest approach is to treat the CSV as a working copy and keep the S2P file as the source.
What the conversion actually changes
Words like "reverse", "mirror" or "font" do not apply here. Converting S2P to CSV does not reorder characters, restyle glyphs or change how text is displayed. It changes how the stored data is structured. Specifically, it does three things:
- Delimiters: whitespace-separated values become comma-separated values.
- Structure: comment lines and the option line are removed from the data rows and are either dropped or carried into a header row.
- Optionally, numeric representation: some converters also convert between number formats, such as magnitude-angle, dB-angle and real-imaginary. That is a calculation, not a format change, and should be stated clearly by any tool that does it.
In a Touchstone 1.x file, lines starting with an exclamation mark are comments. A single line starting with a hash sign is the option line, for example "# GHz S MA R 50". Its fields mean the following:
- Frequency unit: Hz, kHz, MHz or GHz.
- Parameter type: S, Y, Z, H or G.
- Number format: DB for dB-angle, MA for magnitude-angle, RI for real-imaginary.
- Reference resistance: the value after R.
- Defaults: if the option line or any of its fields is missing, the specification defaults are GHz, S, MA and 50 ohms.
Each data line for a two-port file holds nine values: the frequency, followed by four pairs of numbers. The pairs appear in the order 11, 21, 12, 22. Putting 21 before 12 is a long-standing quirk of two-port Touchstone 1.x files and is easy to mislabel. A converter that names the columns S11, S12, S21, S22 in that order without reordering the values will swap forward and reverse transmission.
The following is a structural illustration with placeholders, not real data. The input looks like this:
! comment line
# GHz S MA R 50
f1 m11 a11 m21 a21 m12 a12 m22 a22
f2 m11 a11 m21 a21 m12 a12 m22 a22
A faithful CSV keeps the file's value order and puts the option-line context into the header:
freq_GHz,S11_mag,S11_ang_deg,S21_mag,S21_ang_deg,S12_mag,S12_ang_deg,S22_mag,S22_ang_deg
f1,m11,a11,m21,a21,m12,a12,m22,a22
f2,m11,a11,m21,a21,m12,a12,m22,a22
Edge cases that a simple converter may mishandle
- Noise parameters: two-port Touchstone 1.x files may add a noise block after the network data. Its lines have five values, and it begins where the frequency stops increasing. A converter that does not detect this may append noise rows into the S-parameter columns.
- Touchstone 2.0 files: these use bracketed keywords such as [Version], [Number of Ports] and [Two-Port Data Order]. The last keyword can declare a 12_21 or 21_12 order, so the column order cannot be assumed.
- Y and Z data: in Touchstone 1.x these values are normalized to the reference resistance. A CSV that drops the R value leaves them impossible to denormalize correctly.
- Inline comments: an exclamation mark partway through a data line starts a comment. Values after it must be ignored.
- Case: keywords in the option line are case-insensitive, so "ghz" and "GHz" mean the same thing.
A minimal conversion sketch
The Python sketch below shows one way to keep the option-line context in the CSV header and to set noise rows aside rather than mixing them in. It writes values as the original text, so no rounding is introduced. It deliberately stops on Touchstone 2.0 keywords instead of guessing the data order. It was not run against real files for this article, so test it on your own data before relying on it.
import csv
UNITS = {"HZ": "Hz", "KHZ": "kHz", "MHZ": "MHz", "GHZ": "GHz"}
PAIRS = {"MA": ("mag", "ang_deg"), "DB": ("db", "ang_deg"), "RI": ("re", "im")}
def parse_options(line):
# Touchstone 1.x defaults apply to any field the option line leaves out
opts = {"unit": "GHz", "param": "S", "fmt": "MA", "ref": "50"}
tokens = line.lstrip("#").split()
for i, tok in enumerate(tokens):
t = tok.upper()
if t in UNITS:
opts["unit"] = UNITS[t]
elif t in ("S", "Y", "Z", "H", "G"):
opts["param"] = t
elif t in PAIRS:
opts["fmt"] = t
elif t == "R" and i + 1 < len(tokens):
opts["ref"] = tokens[i + 1]
return opts
def s2p_to_csv(src_path, dst_path):
opts = parse_options("#")
network, leftover = [], []
with open(src_path, encoding="utf-8", errors="replace") as src:
for raw in src:
line = raw.split("!", 1)[0].strip()
if not line:
continue
if line.startswith("#"):
opts = parse_options(line)
continue
if line.startswith("["):
raise ValueError("Touchstone 2.0 keywords found; check [Two-Port Data Order] first")
fields = line.split()
in_network = not leftover and len(fields) == 9 and (
not network or float(fields[0]) > float(network[-1][0]))
(network if in_network else leftover).append(fields)
a, b = PAIRS[opts["fmt"]]
p = opts["param"]
header = ["freq_" + opts["unit"]]
for name in ("11", "21", "12", "22"): # file order for 2-port data
header += [f"{p}{name}_{a}", f"{p}{name}_{b}"]
with open(dst_path, "w", newline="", encoding="utf-8") as dst:
writer = csv.writer(dst)
writer.writerow(header)
writer.writerows(network)
return opts, leftover # leftover usually holds noise parameters
The reference resistance is returned but not written into the CSV, because a single impedance value does not fit naturally into a column header. Record it alongside the file, for example in the file name or a short accompanying note, especially for Y or Z data.
Will the CSV stay readable and usable after copying or sharing?
CSV is plain text. Copying and pasting it does not depend on special characters or styling, and reading order is unchanged. Every row reads left to right, frequency first. The practical risks come from how destinations interpret the file, not from the text itself:
- Spreadsheet display: a spreadsheet may show fewer digits than the file contains. If the sheet is then re-saved as CSV, the displayed or reformatted values may replace the original text. Keep an untouched copy of the converted file.
- Regional decimal settings: in locales that use a comma as the decimal separator, some applications expect a semicolon as the field delimiter. A comma-delimited file may then split or merge columns unexpectedly. Check the import settings rather than assuming a double-click will open the file correctly.
- Scientific notation: values such as 1.2E-3 are valid in both formats, but some tools may reformat them on import.
- Lost context: anyone who receives only the CSV loses the comments in the original S2P file, which often record the instrument, calibration or test conditions. Copy anything important into a separate note.
Accessibility: a CSV with a descriptive header row is generally easier to move through cell by cell in a spreadsheet than columns lined up with whitespace in a text file. Clear headers such as "S21_mag" also make values easier to identify and to search for. No screen reader or specific spreadsheet application was tested for this article, so confirm behavior in the environment your readers actually use.
Editing: CSV is easier to edit by row and column, which also makes it easier to change values accidentally. When the data needs to go back into an RF tool, convert from the preserved S2P file rather than round-tripping through an edited CSV.
How to check a converter before trusting it
- Count rows: the number of CSV data rows should equal the number of network data lines in the S2P file, excluding any noise block.
- Count columns: every row should have nine values for a two-port file.
- Check the header: confirm it records the frequency unit, the parameter type and the number format, and that the column labels follow the 11, 21, 12, 22 order of the values.
- Spot-check values: compare the first, last and a middle row against the original text, character for character.
- Check noise handling: if the source has a noise block, confirm it is excluded or written to a separate output.
- Check Touchstone 2.0 handling: if the source is a 2.0 file, confirm the tool honors [Two-Port Data Order].
- Check privacy before uploading: for an online converter, read its stated data-handling terms before uploading proprietary measurement data. Its appearance or marketing language is no evidence of how files are stored or retained, and offline conversion avoids the question.
Bottom line
Converting S2P to CSV works well for analysis and sharing, provided the frequency unit, parameter type, number format and reference impedance travel with the numbers, and the two-port column order is labeled correctly. Keep the original Touchstone file whenever the data will feed RF software or needs to remain the authoritative record.