https://github.com/suryakantamangaraj/touchstone-dotnet
.NET library for Touchstone .sNp file parsing and S‑parameter handling. Offers strongly typed classes, LINQ‑friendly APIs, and seamless integration into enterprise RF/microwave analysis and simulation pipelines.
https://github.com/suryakantamangaraj/touchstone-dotnet
dotnet microwave parser rf s-parameters s2p touchstone
Last synced: 2 months ago
JSON representation
.NET library for Touchstone .sNp file parsing and S‑parameter handling. Offers strongly typed classes, LINQ‑friendly APIs, and seamless integration into enterprise RF/microwave analysis and simulation pipelines.
- Host: GitHub
- URL: https://github.com/suryakantamangaraj/touchstone-dotnet
- Owner: suryakantamangaraj
- License: mit
- Created: 2026-04-18T07:42:28.000Z (2 months ago)
- Default Branch: main
- Last Pushed: 2026-04-22T06:22:51.000Z (2 months ago)
- Last Synced: 2026-04-22T20:27:26.865Z (2 months ago)
- Topics: dotnet, microwave, parser, rf, s-parameters, s2p, touchstone
- Language: C#
- Homepage: http://suryaraj.com/touchstone-dotnet/
- Size: 454 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
# Touchstone.Parser
> **A .NET library for Touchstone `.sNp` parsing and S‑parameter analysis in RF/microwave engineering.**
[](https://www.nuget.org/packages/Touchstone.Parser)
[](https://www.nuget.org/packages/Touchstone.Parser)
[](https://github.com/suryakantamangaraj/touchstone-dotnet/actions/workflows/ci.yml)
[](https://codecov.io/gh/suryakantamangaraj/touchstone-dotnet)
[](https://suryakantamangaraj.github.io/touchstone-dotnet/)
[](LICENSE)
[](https://dotnet.microsoft.com/)
**Touchstone.Parser** is a clean, modular, enterprise-ready .NET library for parsing [Touchstone](https://ibis.org/) (`.sNp`) files — the industry-standard format for RF and microwave S‑parameter data. It provides strongly typed classes, LINQ-friendly APIs, and seamless integration into simulation and analysis workflows.
---
## ✨ Features
- **Parse `.sNp` files** into strongly typed C# classes (`TouchstoneData`, `FrequencyPoint`, `NetworkParameter`)
- **Multi-port support** — 1‑port through N‑port networks
- **All data formats** — Real/Imaginary (RI), Magnitude/Angle (MA), Decibel/Angle (DB)
- **All frequency units** — Hz, kHz, MHz, GHz with automatic normalization
- **All parameter types** — S, Y, Z, H, G
- **LINQ-friendly APIs** — query S‑parameters with `GetS11()`, `GetS21()`, `GetParameter(i, j)`
- **RF calculations** — insertion loss, return loss, VSWR out of the box
- **Export utilities** — CSV export and Touchstone writer for round-trip fidelity
- **Async support** — `ParseAsync()` with cancellation token
- **Cross-platform** — targets `net6.0` and `netstandard2.1`
- **Ecosystem breadth** — check out the [Python version](https://github.com/suryakantamangaraj/touchstone-python) for Python-based workflows
- **Zero dependencies** — pure .NET, no external packages
---
## 📦 Installation
```bash
dotnet add package Touchstone.Parser
```
Or via the NuGet Package Manager:
```
Install-Package Touchstone.Parser
```
---
## 🚀 Quick Start
```csharp
using Touchstone.Parser.Parsing;
using Touchstone.Parser.Utilities;
using Touchstone.Parser.Models;
// Parse a Touchstone file
var data = TouchstoneParser.Parse("filter.s2p");
Console.WriteLine($"Ports: {data.NumberOfPorts}");
Console.WriteLine($"Frequency points: {data.Count}");
// Query S21 insertion loss with LINQ
foreach (var (freqHz, param) in data.GetS21())
{
double freqGhz = FrequencyConverter.FromHz(freqHz, FrequencyUnit.GHz);
Console.WriteLine($"{freqGhz:F3} GHz → S21 = {param.MagnitudeDb:F2} dB");
}
// Filter to a frequency range
var passband = data.InFrequencyRange(2.0e9, 3.0e9);
// Compute VSWR
foreach (var (freqHz, vswr) in data.ToVswr())
{
Console.WriteLine($"VSWR = {vswr:F3}");
}
// Export to CSV
using var writer = new StreamWriter("output.csv");
data.ToCsv(writer, FrequencyUnit.GHz, DataFormat.DecibelAngle);
```
---
## 📖 API Overview
### Parsing
| Method | Description |
|--------|-------------|
| `TouchstoneParser.Parse(filePath)` | Parse from a file path |
| `TouchstoneParser.Parse(stream, fileName?)` | Parse from a stream |
| `TouchstoneParser.Parse(textReader, fileName?)` | Parse from a TextReader |
| `TouchstoneParser.ParseString(content, fileName?)` | Parse from a raw string |
| `TouchstoneParser.ParseAsync(filePath, ct)` | Async file parsing |
### Data Access (LINQ-friendly)
| Method | Description |
|--------|-------------|
| `data.GetParameter(row, col)` | Get any S‑parameter across all frequencies |
| `data.GetS11()` / `GetS21()` / `GetS12()` / `GetS22()` | Common 2‑port shortcuts |
| `data.Frequencies` | All frequency values in Hz |
| `data.GetFrequenciesIn(FrequencyUnit.GHz)` | Frequencies in any unit |
| `data[index]` | Access a specific frequency point |
### RF Calculations
| Method | Description |
|--------|-------------|
| `data.ToInsertionLoss()` | \|S21\| insertion loss in dB |
| `data.ToReturnLoss()` | \|S11\| return loss in dB |
| `data.ToVswr()` | VSWR from S11 |
### Filtering & Export
| Method | Description |
|--------|-------------|
| `data.InFrequencyRange(minHz, maxHz)` | Filter to frequency range |
| `data.Where(predicate)` | Custom filtering |
| `data.ToCsv(writer, unit, format)` | Export to CSV |
| `data.ToCsvString(unit, format)` | Export to CSV string |
| `TouchstoneWriter.Write(data, filePath)` | Write back to Touchstone format |
### Utilities
| Method | Description |
|--------|-------------|
| `FrequencyConverter.Convert(val, from, to)` | Convert between frequency units |
| `NetworkParameter.FromRealImaginary(re, im)` | Create from RI |
| `NetworkParameter.FromMagnitudeAngle(mag, deg)` | Create from MA |
| `NetworkParameter.FromDecibelAngle(dB, deg)` | Create from DB |
---
## 🏗️ Project Structure
```
touchstone-dotnet/
├── src/
│ └── Touchstone.Parser/ # Core library
│ ├── Models/ # Domain models (enums, data classes)
│ ├── Parsing/ # Parser engine
│ └── Utilities/ # Converters, extensions, writer
├── tests/
│ └── Touchstone.Parser.Tests/ # xUnit test suite
├── examples/
│ └── Touchstone.Parser.Examples/ # Demo console app
├── Directory.Build.props # Centralized build settings
├── Touchstone.Parser.sln # Solution file
└── global.json # .NET SDK version
```
---
## 🔧 Supported Formats
| Feature | Supported |
|---------|-----------|
| Touchstone v1.0 / v1.1 | ✅ |
| 1‑port (`.s1p`) | ✅ |
| 2‑port (`.s2p`) | ✅ |
| Multi-port (`.s3p`, `.s4p`, ...) | ✅ |
| Real-Imaginary (RI) | ✅ |
| Magnitude-Angle (MA) | ✅ |
| Decibel-Angle (DB) | ✅ |
| Hz / kHz / MHz / GHz | ✅ |
| S / Y / Z / H / G parameters | ✅ |
| Comments and metadata | ✅ |
| Touchstone v2.0 keywords | 🔜 Planned |
---
## 🧪 Running Tests
```bash
dotnet test --verbosity normal
```
---
## 🤝 Contributing
Contributions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
---
## 💬 Community
- ⭐ **Star this repo** and related RF/microwave projects to help them grow - then mention your project in context to build visibility.
- 💡 **Share feedback** via [GitHub Discussions](https://github.com/suryakantamangaraj/touchstone-dotnet/discussions) - we'd love to hear how you're using the library, what's working, and what could be better.
---
## 📄 License
This project is licensed under the [MIT License](LICENSE).
---
## 💖 Support & Funding
If this library helps you in your RF/microwave engineering work, consider supporting its maintenance and the development of new features:
- **[Sponsor on GitHub](https://github.com/sponsors/suryakantamangaraj)**
- ⭐ **Star the project** to help it gain visibility in the engineering community.
---
## 📚 Resources
- [Touchstone File Format Specification (IBIS)](https://ibis.org/)
- [S-parameter — Wikipedia](https://en.wikipedia.org/wiki/Scattering_parameters)
- [NuGet Package](https://www.nuget.org/packages/Touchstone.Parser)
---
Made by suryamangaraj · Built for the RF/microwave engineering community 📡