# RF-Touchstone

A Javascript/TypeScript library for reading, manipulating, and writing Touchstone files (.snp files) used in radio frequency (RF) and microwave engineering.

[![Tests](https://github.com/panz2018/RF-Touchstone/actions/workflows/test.yml/badge.svg)](https://github.com/panz2018/RF-Touchstone/actions/workflows/test.yml)
[![Coverage](coverage/coverage-badge.svg)](coverage/coverage-badge.svg)

<!--
[![React Example Tests](https://github.com/mjcaprani/rf-touchstone/actions/workflows/test-react-example.yml/badge.svg)](https://github.com/mjcaprani/rf-touchstone/actions/workflows/test-react-example.yml)
-->

## Overview

RF-Touchstone provides a complete solution for working with S-parameters and other network parameters in JavaScript/TypeScript environments. This library allows you to:

- Read and parse Touchstone files (.s1p, .s2p, .s3p, etc.)
- Manipulate network parameter data
- Write data back to Touchstone format
- Convert between different parameter representations (RI, MA, DB)

## What is a Touchstone File?

Touchstone files are an industry-standard ASCII text format for representing network parameters of electrical circuits. Each file contains:

- Comments (lines starting with !)
- Option line (starts with #) specifying frequency units, parameter type, and data format
- Network parameter data organized by frequency points

RF-Touchstone currently supports versions 1.0 and 1.1 of the Touchstone specification.

## Key Features

- Full support for Touchstone file format (v1.0 and v1.1)
- Parameter type support: S, Y, Z, G, H
- Format conversions: RI (Real/Imaginary), MA (Magnitude/Angle), DB (Decibel/Angle)
- TypeScript implementation with strong typing
- Comprehensive test suite

## Installation

```bash
npm install rf-touchstone
# or
yarn add rf-touchstone
```

## Quick Start

```typescript
import { Touchstone } from 'rf-touchstone'

// Read a Touchstone file
const touchstone = new Touchstone()
touchstone.readContent(fileContent, 2) // assuming a 2-port network

// Access data
const frequencies = touchstone.frequency.f_scaled
const sParameters = touchstone.matrix

// Write back to Touchstone format
const newContent = touchstone.writeContent()
```

<!--
## Examples

This repository includes examples to demonstrate the usage of `rf-touchstone` in different contexts.

- **[React Example](https://github.com/panz2018/RF-Touchstone/tree/main/examples/react)**: A simple standalone React application (using Vite and TypeScript) that showcases how to import and use `rf-touchstone` from npm to parse and display Touchstone file data. Includes comprehensive tests and a GitHub Action for CI.
-->

## Documentation

For detailed documentation, please visit:

- [Project Website](https://panz2018.github.io/RF-Touchstone/)
- [DeepWiki Documentation](https://deepwiki.com/panz2018/RF-Touchstone) - Interactive AI documentation that allows you to converse and ask questions about this repository

## Development

For information on setting up a development environment and contributing to the project, see [development.md](development.md).

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
