Cut *.sdatb files at a certain frequency

91 views
Skip to first unread message

wickli...@gmail.com

unread,
Oct 7, 2025, 11:11:58 AM10/7/25
to VNA Tools
Hey guys

We sometimes face the situation, where we have to measure two more or less identical elements where the only notable difference is the frequency range.

It is way more efficient to just make one Cal and measure both elements in one go with an extended frequency range covering both elements.

However, this leaves us with two *.sdat files, both of which do have frequency points we don't actually need in our output file.

Is there a way to shorten these files so only the relevant frequency range is in the final output file?

Thanks
Patric

wickli...@gmail.com

unread,
Oct 8, 2025, 4:23:34 AM10/8/25
to VNA Tools
Just fyi, I made a script doing what I need.
It may need some polishing and I may add a "min_frequency" as well, but that's the basic script:

import clr
clr.AddReference('Metas.UncLib.Core')
clr.AddReference('Metas.UncLib.linProp')
clr.AddReference('Metas.Vna.Tools')
from Metas.Vna.Tools import Script

input_file  = r"example_9GHz.sdatb"
output_file = r"example_3GHz.sdatb"
max_freq_Hz = 3e9

s = Script(RootPath)
m = s.LoadSParamData(input_file)

# Determine cutoff index
limit_index = -1
for i in range(m.NFreq):
    if m.Frequency[i] <= max_freq_Hz:
        limit_index = i
    else:
        break

if limit_index < 0:
    raise Exception("No frequencies below 3 GHz found.")

print("Cutoff index =", limit_index, "frequency =", m.Frequency[limit_index], "Hz")

# Clone the original dataset by loading a second reference
trunc = s.LoadSParamData(input_file)

# Overwrite S-parameter data for frequencies up to the cutoff
for i in range(limit_index + 1):
    for r in range(m.NPorts):
        for c in range(m.NPorts):
            trunc[i, r, c] = m[i, r, c]

# Truncate the frequency vector
trunc.Frequency = m.Frequency[0:limit_index + 1]

# Save truncated dataset
s.SaveSParamData(output_file, trunc)
print("Saved truncated dataset up to 3 GHz:", output_file)

wickli...@gmail.com

unread,
Oct 8, 2025, 11:08:06 AM10/8/25
to VNA Tools
I did some polishing and made it so one can truncate a whole folder instead of just one file. I'll leave it at that.


import clr
clr.AddReference('Metas.UncLib.Core')
clr.AddReference('Metas.UncLib.linProp')
clr.AddReference('Metas.Vna.Tools')
from System.IO import DirectoryInfo, Directory, Path, FileInfo, SearchOption
from Metas.Vna.Tools import Script

# ================= CONFIGURATION =================
input_folder  = r"C:\path\to\input_folder"     # folder containing .sdatb files
output_folder = r"C:\path\to\output_folder"  # folder to save truncated files
min_freq_Hz   = 1e9                 # Min Frequency
max_freq_Hz   = 3e9                 # Max Frequency

# ================= INITIALIZATION =================
s = Script(RootPath)
di = DirectoryInfo(input_folder)
fis = di.GetFiles('*.sdatb', SearchOption.AllDirectories)

for fi in fis:
    print("Processing:", fi.FullName)

    # --- Load original dataset ---
    d = s.LoadSParamData(fi.FullName)

    # --- Determine frequency range indices ---
    start_index = None
    end_index = None
    for i in range(d.NFreq):
        f = d.Frequency[i]
        if start_index is None and f >= min_freq_Hz:
            start_index = i
        if f <= max_freq_Hz:
            end_index = i

    if start_index is None or end_index is None or start_index > end_index:
        print("  Skipped (no data in selected range)")
        continue

    print("  Truncating from %.3f GHz to %.3f GHz" %
          (d.Frequency[start_index]/1e9, d.Frequency[end_index]/1e9))

    # --- Clone dataset and overwrite truncated values ---
    trunc = s.LoadSParamData(fi.FullName)
    for i_new, i_orig in enumerate(range(start_index, end_index + 1)):
        for r in range(d.NPorts):
            for c in range(d.NPorts):
                trunc[i_new, r, c] = d[i_orig, r, c]

    # --- Truncate frequency vector ---
    trunc.Frequency = d.Frequency[start_index:end_index + 1]

    # --- Compute relative path for output ---
    rel_path = fi.FullName[len(input_folder):].lstrip('\\')
    output_path = Path.Combine(output_folder, rel_path)
    output_dir  = Path.GetDirectoryName(output_path)
    if not Directory.Exists(output_dir):
        Directory.CreateDirectory(output_dir)

    # --- Save truncated dataset ---
    output_file = Path.Combine(output_dir, Path.GetFileNameWithoutExtension(fi.Name) + '_trunc.sdatb')
    s.SaveSParamData(output_file, trunc)
    print("  Saved truncated file:", output_file)

print("Batch truncation completed for folder:", input_folder)

Juerg Ruefenacht

unread,
Oct 14, 2025, 4:36:18 AM10/14/25
to VNA Tools
Hello Patric,
you can select in the File Explorer a frequency list file for this purpose (see User Manual, section 3.2).

Best Regards
Juerg

wickli...@gmail.com schrieb am Dienstag, 7. Oktober 2025 um 17:11:58 UTC+2:

wickli...@gmail.com

unread,
Oct 16, 2025, 3:46:31 AM10/16/25
to VNA Tools
Hello Juerg

Oh, that would have made things quite a lot easier. Thank's for your feedback!

Greetings
Patric

Mr Skinner

unread,
Jul 20, 2026, 4:26:32 PMJul 20
to VNA Tools
Hi all,

I have a similar question. If I have an .sdatb file containing 2-port S-parameters, is it possible to save the data for just one S-parameter (e.g. s11) into a separate file?

Best regards
James

wickli...@gmail.com

unread,
Jul 23, 2026, 7:34:53 AM (12 days ago) Jul 23
to VNA Tools
Hey James

This may not be the easiest and prettiest solution, but you could yout copy a 1P file with the same frequency Points and paste the values from your 2P file in there. Hopefully Michael will have a prettierr solution tho.:

import clr
clr.AddReference('System.Windows.Forms')

clr.AddReference('Metas.UncLib.Core')
clr.AddReference('Metas.UncLib.linProp')
clr.AddReference('Metas.Vna.Tools')
from System.Threading import Thread
from Metas.UncLib.Core import Complex
from Metas.UncLib.LinProp import UncNumber
from System.Windows.Forms import MessageBox
from Metas.Vna.Tools import Script

s = Script(RootPath)

w = s.LoadSParamData(r'PathTo1PFile')
x = s.LoadSParamData(r'PathToSrcFile')
z = w


n = x.NFreq

for i in range(n):
    z[i, 0, 0] = x[i, 0, 0]
s.SaveSParamData(r'Output.sdatb', z)

Mr Skinner

unread,
Jul 23, 2026, 10:10:06 AM (12 days ago) Jul 23
to VNA Tools
Thanks Patric, I will give it a go. I also have a not-so-pretty solution which is to save the .sdatb data as a databased calibration standard. The menu allows you to select ports, so if I only want s11 I set the field to port 1. It then creates a 'calibration standard' in the database from which I can take the 1-port sdatb file. Not so efficient but it works at least.

Best regards
James

Michael Wollensack METAS

unread,
Jul 27, 2026, 5:12:11 AM (8 days ago) Jul 27
to VNA Tools
Reply all
Reply to author
Forward
0 new messages