How to Read One Line of an S2P File (MA, DB and RI Formats)
A two-port S2P data line holds nine numbers: the frequency, then the pairs for S11, S21, S12 and S22 in that order. The option line tells you whether each pair is MA, DB or RI, and a magnitude of 0.9975 is about -0.022 dB.
For practitioners
A Touchstone S2P file looks like a wall of numbers. It is not. It has one option line that tells you how to read the data, and then one data line per frequency point. If you can read one line, you can read the whole file.
This article takes a single line apart, explains the three number formats and shows how to convert between them by hand.
The option line sets the rules
The first line that is not a comment starts with #. It is the option line. Here is a typical one:
# GHz S MA R 50
It has four parts, always in this order:
- Frequency unit.
GHzmeans the first number on every data line is in gigahertz. - Parameter type.
Smeans the file holds S-parameters. - Data format.
MA,DBorRI. This decides what the pairs of numbers mean. - Reference resistance.
R 50means the values are normalised to 50 ohm.
Read this line first. The same numbers mean something completely different in MA and in RI, and nothing in the data line itself tells you which one you have.
Anatomy of one data line
For a two-port, each data line holds nine numbers. The first is the frequency. The other eight are four pairs, one per S-parameter:
| Position | Meaning |
|---|---|
| 1 | Frequency |
| 2, 3 | S11 (first number, second number) |
| 4, 5 | S21 |
| 6, 7 | S12 |
| 8, 9 | S22 |
Each pair is a complex number. Its two values are the first and second number of the format named in the option line.
In a two-port S2P file the order is S11, S21, S12, S22. S21 and S12 are swapped compared with the matrix layout (S11, S12, S21, S22) used for files with three or more ports. Reading S21 as S12 is the most common slip.
The three formats
All three formats describe the same complex number. They differ only in how it is written.
MA gives the magnitude as a plain ratio and the angle in degrees. The magnitude is a linear number, not dB.
DB gives the magnitude in dB and the angle in degrees. The magnitude in dB is:
RI gives the real part and the imaginary part. There is no angle at all.
The angle is in degrees in both MA and DB. It only becomes radians when you feed it into cos and sin on a calculator or in code.
Worked example: one made-up line
The values below are illustrative, chosen so the arithmetic is easy to follow. They are not a measurement.
# GHz S MA R 50
2.4 0.9975 -30 0.1 45 0.1 45 0.9 -20
Reading it with the table above:
- Frequency: 2.4 GHz
- S11: magnitude 0.9975, angle -30°
- S21: magnitude 0.1, angle 45°
- S12: magnitude 0.1, angle 45°
- S22: magnitude 0.9, angle -20°
Now convert S11 to the other two formats.
MA to DB. The magnitude is 0.9975:
So S11 in DB is the pair (-0.022, -30). The angle does not change.
MA to RI. Convert -30° to radians first: -30° is -π/6, about -0.5236 rad. Then:
So S11 in RI is about (0.8639, -0.4988).
The S21 magnitude of 0.1 is exactly -20 dB, because 20*log10(0.1) = -20. That makes S21 in DB the pair (-20, 45).
Converting back
DB to MA. Invert the dB formula:
From -0.022 dB you get back about 0.9975.
RI to MA. Use the Pythagorean sum and the two-argument arctangent:
Check with the example: the square root of 0.8639² + 0.4988² is about 0.9975, and atan2(-0.4988, 0.8639) is -30°.
Use atan2, not a plain arctan of Im/Re. A plain arctan loses the quadrant. A real part of -0.5 with an imaginary part of 0.5 and a real part of 0.5 with an imaginary part of -0.5 give the same ratio but angles 180° apart.
Checks that catch mistakes
- Magnitude above 1 in a passive device. A linear magnitude above 1 for a passive part suggests you are reading DB or RI numbers as MA.
- Large negative first numbers. Values like -20 or -35 in a pair that you thought was MA are dB values. The file is DB.
- Angles that look like fractions. A pair such as (0.86, -0.50) is probably RI, not an angle.
- S21 and S12 swapped. For a passive, reciprocal part they are nearly equal, so the swap may hide. For an amplifier they differ a lot, and the swap is obvious.
An S2P viewer does these conversions for you and plots the result. Doing one line by hand is still worth it, because it tells you what the viewer is showing.
In plain words · for students and beginners
Reading one S2P line in plain words
The idea in everyday terms
Think of a spreadsheet row where every column has a heading, except the headings are all in one line at the top of the file. The option line is that heading line. Each data line is one row: a frequency, then four pairs of numbers.
Each pair describes one "answer" of the device, for example how much signal bounces back or how much gets through. The pair is like a position on a map. You can give it as "distance and compass direction" (MA or DB) or as "so far east, so far north" (RI). It is the same place either way.
Where the comparison breaks down: a map position has no unit trouble, but here the distance can be a plain ratio (MA) or a decibel value (DB). You must check which one the file uses.
The same example in simple steps
Take the line 2.4 0.9975 -30 0.1 45 0.1 45 0.9 -20 with the heading # GHz S MA R 50.
- The heading says GHz, S-parameters, MA format, 50 ohm.
- The first number, 2.4, is the frequency: 2.4 GHz.
- The next two numbers, 0.9975 and -30, are S11. Size 0.9975, angle -30 degrees.
- The next pair is S21, then S12, then S22. Yes, S21 comes first.
- To get dB, take 20 times the log of 0.9975. That is about -0.022 dB.
- To get real and imaginary, multiply 0.9975 by cos(-30°) and by sin(-30°). You get about 0.8639 and -0.4988.
The drawing shows why there are four answers: the device has two ports, and each port can send signal in and receive signal back.
Mistakes beginners make
- Ignoring the heading line. Without it you cannot tell MA from RI.
- Mixing up S21 and S12. In a two-port file S21 comes before S12.
- Treating dB as a ratio. A first number of -20 in DB format is not a size of minus twenty. It is a level in decibels (a way of writing ratios on a log scale).
- Feeding degrees to a calculator set for radians. Check the angle mode before you press cos or sin.
Remember
- The option line comes first and tells you the frequency unit, the format and the reference resistance.
- A two-port line is nine numbers: frequency, then S11, S21, S12, S22 as pairs.
- MA, DB and RI are three ways to write the same number; 0.9975 is about -0.022 dB.
Related pages on RF View
Frequently asked questions
What order are the S-parameters in an S2P file line?
After the frequency come the pairs for S11, S21, S12 and S22, in that order. Note that S21 comes before S12 in a two-port file.
How do I convert MA to DB in a Touchstone file?
Keep the angle as it is and replace the magnitude with 20*log10(magnitude). A magnitude of 0.9975 becomes about -0.022 dB.
How do I convert MA to real and imaginary (RI)?
Real = magnitude*cos(angle) and imaginary = magnitude*sin(angle), with the angle in degrees converted to radians first.
What does R 50 mean in the option line?
It is the reference resistance in ohm that the S-parameters are normalised to. In '# GHz S MA R 50' it is 50 ohm.