rf-touchstone 0.0.0 → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,26 @@
1
+ import { abs } from 'mathjs';
2
+ import { add } from 'mathjs';
3
+ import { arg } from 'mathjs';
1
4
  import { Complex } from 'mathjs';
5
+ import { complex } from 'mathjs';
6
+ import { index } from 'mathjs';
7
+ import { log10 } from 'mathjs';
8
+ import { multiply } from 'mathjs';
9
+ import { pi } from 'mathjs';
10
+ import { pow } from 'mathjs';
11
+ import { range } from 'mathjs';
12
+ import { round } from 'mathjs';
13
+ import { subset } from 'mathjs';
14
+
15
+ export { abs }
16
+
17
+ export { add }
18
+
19
+ export { arg }
20
+
21
+ export { Complex }
22
+
23
+ export { complex }
2
24
 
3
25
  /**
4
26
  * Class representing frequency data in RF and microwave engineering
@@ -16,7 +38,7 @@ import { Complex } from 'mathjs';
16
38
  * freq.f_scale = [1.0, 2.0, 3.0];
17
39
  * ```
18
40
  */
19
- declare class Frequency {
41
+ export declare class Frequency {
20
42
  /**
21
43
  * Internal storage for frequency unit
22
44
  * Defaults to 'Hz' as the base SI unit for frequency
@@ -377,40 +399,62 @@ declare class Frequency {
377
399
  * - GHz: Gigahertz (10⁹ Hz)
378
400
  * Touchstone standard doesn't support THz as the frequency unit in Touchstone file
379
401
  */
380
- declare type FrequencyUnit = (typeof FrequencyUnits)[number];
402
+ export declare type FrequencyUnit = (typeof FrequencyUnits)[number];
381
403
 
382
404
  /**
383
405
  * Frequency units: 'Hz', 'kHz', 'MHz', 'GHz'
384
406
  * Touchstone standard doesn't support THz as the frequency unit in Touchstone file
385
407
  */
386
- declare const FrequencyUnits: readonly ["Hz", "kHz", "MHz", "GHz"];
408
+ export declare const FrequencyUnits: readonly ["Hz", "kHz", "MHz", "GHz"];
409
+
410
+ export { index }
411
+
412
+ export { log10 }
413
+
414
+ export { multiply }
415
+
416
+ export { pi }
417
+
418
+ export { pow }
419
+
420
+ export { range }
421
+
422
+ export { round }
423
+
424
+ /**
425
+ * Speed of light in m/s
426
+ */
427
+ export declare const SPEED_OF_LIGHT = 299792458;
428
+
429
+ export { subset }
387
430
 
388
431
  /**
389
432
  * Touchstone class for reading and writing network parameter data in Touchstone format.
390
433
  * Supports both version 1.0 and 1.1 of the Touchstone specification.
391
434
  *
392
- * ## Overview
435
+ * @remarks
436
+ * #### Overview
393
437
  *
394
438
  * The **Touchstone file format** (also known as `.snp` files) is an industry-standard ASCII text format used to represent the n-port network parameters of electrical circuits. These files are commonly used in RF and microwave engineering to describe the behavior of devices such as filters, amplifiers, and interconnects.
395
439
  *
396
440
  * A Touchstone file contains data about network parameters (e.g., S-parameters, Y-parameters, Z-parameters) at specific frequencies.
397
441
  *
398
- * ### Key Features:
442
+ * ##### Key Features:
399
443
  * - **File Extensions**: Traditionally, Touchstone files use extensions like `.s1p`, `.s2p`, `.s3p`, etc., where the number indicates the number of ports. For example, `.s2p` represents a 2-port network.
400
444
  * - **Case Insensitivity**: Touchstone files are case-insensitive, meaning keywords and values can be written in uppercase or lowercase.
401
445
  * - **Versioning**: **Only version 1.0 and 1.1 are supported in this class**
402
446
  *
403
447
  * ---
404
448
  *
405
- * ## File Structure
449
+ * #### File Structure
406
450
  *
407
451
  * A Touchstone file consists of several sections, each serving a specific purpose. Below is a breakdown of the structure:
408
452
  *
409
- * ### 1. Header Section
453
+ * ##### 1. Header Section
410
454
  *
411
455
  * - **Comment Lines**: Lines starting with `!` are treated as comments and ignored during parsing.
412
456
  * - **Option Line**: Line starting with `#` defines global settings for the file, such as frequency units, parameter type, and data format. Example:
413
- * ```
457
+ * ```plaintext
414
458
  * # GHz S MA R 50
415
459
  * ```
416
460
  * - `GHz`: Frequency unit (can be `Hz`, `kHz`, `MHz`, or `GHz`).
@@ -418,20 +462,26 @@ declare const FrequencyUnits: readonly ["Hz", "kHz", "MHz", "GHz"];
418
462
  * - `MA`: Data format (`MA` for magnitude-angle, `DB` for decibel-angle, or `RI` for real-imaginary).
419
463
  * - `R 50`: Reference resistance in ohms (default is 50 ohms if omitted).
420
464
  *
421
- * ### 2. Network Data
465
+ * ##### 2. Network Data
422
466
  *
423
467
  * The core of the file contains the network parameter data, organized by frequency. Each frequency point is followed by its corresponding parameter values.
424
468
  *
425
469
  * - **Single-Ended Networks**: Data is arranged in a matrix format. For example, a 2-port network might look like this:
426
- * ```
470
+ * ```plaintext
427
471
  * <frequency> <N11> <N21> <N12> <N22>
428
472
  * ```
429
473
  *
430
474
  * ---
431
475
  *
432
- * ## Examples
476
+ * #### References:
477
+ * - {@link https://ibis.org/touchstone_ver2.1/touchstone_ver2_1.pdf Touchstone(R) File Format Specification (Version 2.1)}
478
+ * - {@link https://books.google.com/books/about/S_Parameters_for_Signal_Integrity.html?id=_dLKDwAAQBAJ S-Parameters for Signal Integrity}
479
+ * - {@link https://github.com/scikit-rf/scikit-rf/blob/master/skrf/io/touchstone.py scikit-rf: Open Source RF Engineering}
480
+ * - {@link https://github.com/Nubis-Communications/SignalIntegrity/blob/master/SignalIntegrity/Lib/SParameters/SParameters.py SignalIntegrity: Signal and Power Integrity Tools}
433
481
  *
434
- * ### Example 1: Simple 1-Port S-Parameter File
482
+ * @example
483
+ *
484
+ * #### Example 1: Simple 1-Port S-Parameter File
435
485
  * ```plaintext
436
486
  * ! 1-port S-parameter file
437
487
  * # MHz S MA R 50
@@ -440,13 +490,14 @@ declare const FrequencyUnits: readonly ["Hz", "kHz", "MHz", "GHz"];
440
490
  * 300 0.707 -45
441
491
  * ```
442
492
  *
443
- * ---
444
- *
445
- * ## References:
446
- * - {@link https://ibis.org/touchstone_ver2.1/touchstone_ver2_1.pdf Touchstone(R) File Format Specification (Version 2.1)}
447
- * - {@link https://books.google.com/books/about/S_Parameters_for_Signal_Integrity.html?id=_dLKDwAAQBAJ S-Parameters for Signal Integrity}
448
- * - {@link https://github.com/scikit-rf/scikit-rf/blob/master/skrf/io/touchstone.py scikit-rf: Open Source RF Engineering}
449
- * - {@link https://github.com/Nubis-Communications/SignalIntegrity/blob/master/SignalIntegrity/Lib/SParameters/SParameters.py SignalIntegrity: Signal and Power Integrity Tools}
493
+ * #### Example 2: Simple 2-Port S-Parameter File
494
+ * ```plaintext
495
+ * ! Sample S2P File
496
+ * # HZ S RI R 50
497
+ * ! Freq S11(real) S11(imag) S21(real) S21(imag) S12(real) S12(imag) S22(real) S22(imag)
498
+ * 1000000000 0.9 -0.1 0.01 0.02 0.01 0.02 0.8 -0.15
499
+ * 2000000000 0.8 -0.2 0.02 0.03 0.02 0.03 0.7 -0.25
500
+ * ```
450
501
  */
451
502
  export declare class Touchstone {
452
503
  /**
@@ -585,6 +636,30 @@ export declare class Touchstone {
585
636
  * 2. Extracts frequency points
586
637
  * 3. Converts raw data into complex numbers based on format
587
638
  * 4. Stores the results in the matrix property
639
+ *
640
+ * @example
641
+ * ```typescript
642
+ * import { Touchstone, Frequency } from 'rf-touchstone';
643
+ *
644
+ * const s1pString = `
645
+ * ! This is a 1-port S-parameter file
646
+ * # MHz S MA R 50
647
+ * 100 0.99 -4
648
+ * 200 0.80 -22
649
+ * 300 0.707 -45
650
+ * `;
651
+ *
652
+ * const touchstone = new Touchstone();
653
+ * touchstone.readContent(s1pString, 1);
654
+ *
655
+ * console.log(touchstone.comments); // Outputs: [ 'This is a 1-port S-parameter file' ]
656
+ * console.log(touchstone.format); // Outputs: 'MA'
657
+ * console.log(touchstone.parameter); // Outputs: 'S'
658
+ * console.log(touchstone.impedance); // Outputs: 50
659
+ * console.log(touchstone.nports); // Outputs: 1
660
+ * console.log(touchstone.frequency?.f_scaled); // Outputs: [ 100, 200, 300 ]
661
+ * console.log(touchstone.matrix); // Outputs: the parsed matrix data
662
+ * ```
588
663
  */
589
664
  readContent(string: string, nports: number): void;
590
665
  /**
@@ -625,6 +700,37 @@ export declare class Touchstone {
625
700
  * 1. Comments (if any)
626
701
  * 2. Option line with format, parameter type, and impedance
627
702
  * 3. Network parameter data in the specified format
703
+ *
704
+ * @example
705
+ * ```typescript
706
+ * import { Touchstone, Frequency } from 'rf-touchstone';
707
+ * import { complex } from 'mathjs';
708
+ *
709
+ * const touchstone = new Touchstone();
710
+ *
711
+ * // Set properties and matrix data (using simplified complex number representation for example)
712
+ * touchstone.comments = ['Generated by rf-touchstone'];
713
+ * touchstone.nports = 1;
714
+ * touchstone.frequency = new Frequency();
715
+ * touchstone.frequency.unit = 'GHz';
716
+ * touchstone.frequency.f_scaled = [1.0, 2.0];
717
+ * touchstone.parameter = 'S';
718
+ * touchstone.format = 'MA';
719
+ * touchstone.impedance = 50;
720
+ * touchstone.matrix = [
721
+ * [ // Output port 1
722
+ * [complex(0.5, 0.1), complex(0.4, 0.2)] // S11 at each frequency
723
+ * ]
724
+ * ];
725
+ *
726
+ * const s1pString = touchstone.writeContent();
727
+ * console.log(s1pString);
728
+ * // Expected output (approximately, due to floating point precision):
729
+ * // ! Generated by rf-touchstone
730
+ * // # GHz S MA R 50
731
+ * // 1 0.5099 11.3099
732
+ * // 2 0.4472 26.5651
733
+ * ```
628
734
  */
629
735
  writeContent(): string;
630
736
  }
package/package.json CHANGED
@@ -1,18 +1,17 @@
1
1
  {
2
2
  "name": "rf-touchstone",
3
- "private": false,
4
3
  "type": "module",
5
- "version": "0.0.0",
4
+ "version": "0.0.1",
6
5
  "description": "A Javascript/TypeScript library for reading, manipulating, and writing Touchstone files (.snp files) used in radio frequency (RF) and microwave engineering.",
7
6
  "main": "dist/Touchstone.cjs.js",
8
7
  "module": "dist/Touchstone.es.js",
9
8
  "types": "dist/touchstone.d.ts",
10
9
  "files": [
11
- "dist",
12
- "readme.md",
13
- "development.md",
14
- "LICENSE",
15
- "coverage/coverage-badge.svg"
10
+ "./dist",
11
+ "./readme.md",
12
+ "./development.md",
13
+ "./LICENSE",
14
+ "./coverage/coverage-badge.svg"
16
15
  ],
17
16
  "license": "MIT",
18
17
  "author": "https://github.com/panz2018",
@@ -29,12 +28,15 @@
29
28
  "s6p",
30
29
  "frequency",
31
30
  "scattering",
32
- "matrix"
31
+ "matrix",
32
+ "impedance"
33
33
  ],
34
+ "packageManager": "yarn@4.9.2",
34
35
  "scripts": {
35
36
  "test": "run-p --print-label lint format test:unit test:coverage build docs:md && run-s docs:build",
36
37
  "lint": "eslint . --fix",
37
- "format": "prettier --write src/",
38
+ "format": "prettier --write .",
39
+ "test:watch": "vitest",
38
40
  "test:unit": "vitest run",
39
41
  "test:coverage": "vitest run --coverage && coverage-badges --source coverage/coverage-summary.json --output coverage/coverage-badge.svg",
40
42
  "build": "tsc && vite build && yarn pack",
@@ -44,30 +46,30 @@
44
46
  "docs:preview": "vitepress preview docs"
45
47
  },
46
48
  "dependencies": {
47
- "mathjs": "^14.5.0"
49
+ "mathjs": "^14.5.2"
48
50
  },
49
51
  "devDependencies": {
50
- "@eslint/js": "^9.27.0",
52
+ "@eslint/js": "^9.28.0",
51
53
  "@types/eslint-config-prettier": "^6.11.3",
52
- "@types/node": "^22.15.21",
53
- "@vitest/coverage-v8": "^3.1.4",
54
+ "@types/node": "^22.15.30",
55
+ "@vitest/coverage-v8": "^3.2.2",
54
56
  "coverage-badges-cli": "^2.1.0",
55
- "eslint": "^9.27.0",
57
+ "eslint": "^9.28.0",
56
58
  "eslint-config-prettier": "^10.1.5",
57
- "eslint-plugin-prettier": "^5.4.0",
59
+ "eslint-plugin-prettier": "^5.4.1",
58
60
  "globals": "^16.2.0",
59
- "happy-dom": "^17.4.7",
61
+ "happy-dom": "^17.6.3",
60
62
  "markdown-it-mathjax3": "^4.3.2",
61
63
  "npm-run-all": "^4.1.5",
62
64
  "prettier": "^3.5.3",
63
- "rollup-plugin-visualizer": "^5.14.0",
64
- "typedoc": "^0.28.4",
65
- "typedoc-plugin-markdown": "^4.6.3",
65
+ "rollup-plugin-visualizer": "^6.0.1",
66
+ "typedoc": "^0.28.5",
67
+ "typedoc-plugin-markdown": "^4.6.4",
66
68
  "typescript": "^5.8.3",
67
- "typescript-eslint": "^8.32.1",
69
+ "typescript-eslint": "^8.33.1",
68
70
  "vite": "^6.3.5",
69
71
  "vite-plugin-dts": "^4.5.4",
70
72
  "vitepress": "^1.6.3",
71
- "vitest": "^3.1.4"
73
+ "vitest": "^3.2.2"
72
74
  }
73
75
  }
package/readme.md CHANGED
@@ -2,9 +2,13 @@
2
2
 
3
3
  A Javascript/TypeScript library for reading, manipulating, and writing Touchstone files (.snp files) used in radio frequency (RF) and microwave engineering.
4
4
 
5
- [![Tests](https://github.com/panz2018/RF-Touchstone/actions/workflows/Tests.yml/badge.svg)](https://github.com/panz2018/RF-Touchstone/actions/workflows/Tests.yml)
5
+ [![Tests](https://github.com/panz2018/RF-Touchstone/actions/workflows/test.yml/badge.svg)](https://github.com/panz2018/RF-Touchstone/actions/workflows/test.yml)
6
6
  [![Coverage](coverage/coverage-badge.svg)](coverage/coverage-badge.svg)
7
7
 
8
+ <!--
9
+ [![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)
10
+ -->
11
+
8
12
  ## Overview
9
13
 
10
14
  RF-Touchstone provides a complete solution for working with S-parameters and other network parameters in JavaScript/TypeScript environments. This library allows you to:
@@ -47,16 +51,24 @@ import { Touchstone } from 'rf-touchstone'
47
51
 
48
52
  // Read a Touchstone file
49
53
  const touchstone = new Touchstone()
50
- touchstone.readContent(fileContent, 2) // 2-port network
54
+ touchstone.readContent(fileContent, 2) // assuming a 2-port network
51
55
 
52
56
  // Access data
53
- const frequencies = touchstone.getFrequencies()
54
- const sParameters = touchstone.getParameterMatrix()
57
+ const frequencies = touchstone.frequency.f_scaled
58
+ const sParameters = touchstone.matrix
55
59
 
56
60
  // Write back to Touchstone format
57
61
  const newContent = touchstone.writeContent()
58
62
  ```
59
63
 
64
+ <!--
65
+ ## Examples
66
+
67
+ This repository includes examples to demonstrate the usage of `rf-touchstone` in different contexts.
68
+
69
+ - **[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.
70
+ -->
71
+
60
72
  ## Documentation
61
73
 
62
74
  For detailed documentation, please visit: