rf-touchstone 0.0.0 → 0.0.2
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.
- package/coverage/coverage-badge.svg +4 -4
- package/dist/Touchstone.cjs.js +7 -13
- package/dist/Touchstone.es.js +3561 -3429
- package/dist/Touchstone.umd.js +7 -13
- package/dist/frequency.d.ts +394 -0
- package/dist/index.d.ts +24 -0
- package/dist/touchstone.d.ts +367 -697
- package/package.json +40 -35
- package/readme.md +19 -5
- package/src/frequency.ts +693 -0
- package/src/index.ts +33 -0
- package/src/touchstone.ts +774 -0
- package/development.md +0 -181
- /package/{LICENSE → LICENSE.md} +0 -0
package/dist/touchstone.d.ts
CHANGED
|
@@ -1,697 +1,367 @@
|
|
|
1
|
-
import { Complex } from 'mathjs';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
*
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
*
|
|
154
|
-
* @
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
*
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
* @
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
*
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
*
|
|
204
|
-
* @
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
*
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
*
|
|
213
|
-
*/
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
*
|
|
217
|
-
*
|
|
218
|
-
*
|
|
219
|
-
*
|
|
220
|
-
*
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
*
|
|
225
|
-
*
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
*
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
*
|
|
236
|
-
* @
|
|
237
|
-
*
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
*
|
|
242
|
-
*
|
|
243
|
-
*
|
|
244
|
-
*
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
*
|
|
248
|
-
*
|
|
249
|
-
*
|
|
250
|
-
*
|
|
251
|
-
*/
|
|
252
|
-
get
|
|
253
|
-
/**
|
|
254
|
-
*
|
|
255
|
-
*
|
|
256
|
-
*
|
|
257
|
-
* @
|
|
258
|
-
*
|
|
259
|
-
*
|
|
260
|
-
*
|
|
261
|
-
*
|
|
262
|
-
*
|
|
263
|
-
*
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
*
|
|
268
|
-
*
|
|
269
|
-
*
|
|
270
|
-
*
|
|
271
|
-
*
|
|
272
|
-
*
|
|
273
|
-
*
|
|
274
|
-
*
|
|
275
|
-
*
|
|
276
|
-
*
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
*
|
|
281
|
-
*
|
|
282
|
-
*
|
|
283
|
-
*
|
|
284
|
-
*
|
|
285
|
-
*
|
|
286
|
-
*
|
|
287
|
-
*
|
|
288
|
-
* console.log(
|
|
289
|
-
*
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
*
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
*
|
|
298
|
-
*
|
|
299
|
-
*
|
|
300
|
-
*
|
|
301
|
-
*
|
|
302
|
-
*
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
*
|
|
307
|
-
*
|
|
308
|
-
*
|
|
309
|
-
* @
|
|
310
|
-
*
|
|
311
|
-
*
|
|
312
|
-
*
|
|
313
|
-
*
|
|
314
|
-
*
|
|
315
|
-
*
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
*
|
|
323
|
-
*
|
|
324
|
-
*
|
|
325
|
-
*
|
|
326
|
-
*
|
|
327
|
-
*
|
|
328
|
-
*
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
*
|
|
333
|
-
*
|
|
334
|
-
*
|
|
335
|
-
* @example
|
|
336
|
-
* ```typescript
|
|
337
|
-
*
|
|
338
|
-
*
|
|
339
|
-
*
|
|
340
|
-
*
|
|
341
|
-
*
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
*
|
|
346
|
-
*
|
|
347
|
-
*
|
|
348
|
-
*
|
|
349
|
-
*
|
|
350
|
-
*
|
|
351
|
-
*
|
|
352
|
-
*
|
|
353
|
-
*
|
|
354
|
-
*
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
*
|
|
359
|
-
*
|
|
360
|
-
*
|
|
361
|
-
*
|
|
362
|
-
*
|
|
363
|
-
*
|
|
364
|
-
*
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
*/
|
|
369
|
-
set wavelength_nm(values: number[]);
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
/**
|
|
373
|
-
* Type definition for frequency units
|
|
374
|
-
* - Hz: Hertz (cycles per second)
|
|
375
|
-
* - kHz: Kilohertz (10³ Hz)
|
|
376
|
-
* - MHz: Megahertz (10⁶ Hz)
|
|
377
|
-
* - GHz: Gigahertz (10⁹ Hz)
|
|
378
|
-
* Touchstone standard doesn't support THz as the frequency unit in Touchstone file
|
|
379
|
-
*/
|
|
380
|
-
declare type FrequencyUnit = (typeof FrequencyUnits)[number];
|
|
381
|
-
|
|
382
|
-
/**
|
|
383
|
-
* Frequency units: 'Hz', 'kHz', 'MHz', 'GHz'
|
|
384
|
-
* Touchstone standard doesn't support THz as the frequency unit in Touchstone file
|
|
385
|
-
*/
|
|
386
|
-
declare const FrequencyUnits: readonly ["Hz", "kHz", "MHz", "GHz"];
|
|
387
|
-
|
|
388
|
-
/**
|
|
389
|
-
* Touchstone class for reading and writing network parameter data in Touchstone format.
|
|
390
|
-
* Supports both version 1.0 and 1.1 of the Touchstone specification.
|
|
391
|
-
*
|
|
392
|
-
* ## Overview
|
|
393
|
-
*
|
|
394
|
-
* 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
|
-
*
|
|
396
|
-
* A Touchstone file contains data about network parameters (e.g., S-parameters, Y-parameters, Z-parameters) at specific frequencies.
|
|
397
|
-
*
|
|
398
|
-
* ### Key Features:
|
|
399
|
-
* - **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
|
-
* - **Case Insensitivity**: Touchstone files are case-insensitive, meaning keywords and values can be written in uppercase or lowercase.
|
|
401
|
-
* - **Versioning**: **Only version 1.0 and 1.1 are supported in this class**
|
|
402
|
-
*
|
|
403
|
-
* ---
|
|
404
|
-
*
|
|
405
|
-
* ## File Structure
|
|
406
|
-
*
|
|
407
|
-
* A Touchstone file consists of several sections, each serving a specific purpose. Below is a breakdown of the structure:
|
|
408
|
-
*
|
|
409
|
-
* ### 1. Header Section
|
|
410
|
-
*
|
|
411
|
-
* - **Comment Lines**: Lines starting with `!` are treated as comments and ignored during parsing.
|
|
412
|
-
* - **Option Line**: Line starting with `#` defines global settings for the file, such as frequency units, parameter type, and data format. Example:
|
|
413
|
-
* ```
|
|
414
|
-
* # GHz S MA R 50
|
|
415
|
-
* ```
|
|
416
|
-
* - `GHz`: Frequency unit (can be `Hz`, `kHz`, `MHz`, or `GHz`).
|
|
417
|
-
* - `S`: Parameter type (`S`, `Y`, `Z`, `H`, or `G`).
|
|
418
|
-
* - `MA`: Data format (`MA` for magnitude-angle, `DB` for decibel-angle, or `RI` for real-imaginary).
|
|
419
|
-
* - `R 50`: Reference resistance in ohms (default is 50 ohms if omitted).
|
|
420
|
-
*
|
|
421
|
-
* ### 2. Network Data
|
|
422
|
-
*
|
|
423
|
-
* The core of the file contains the network parameter data, organized by frequency. Each frequency point is followed by its corresponding parameter values.
|
|
424
|
-
*
|
|
425
|
-
* - **Single-Ended Networks**: Data is arranged in a matrix format. For example, a 2-port network might look like this:
|
|
426
|
-
* ```
|
|
427
|
-
* <frequency> <N11> <N21> <N12> <N22>
|
|
428
|
-
* ```
|
|
429
|
-
*
|
|
430
|
-
* ---
|
|
431
|
-
*
|
|
432
|
-
* ## Examples
|
|
433
|
-
*
|
|
434
|
-
* ### Example 1: Simple 1-Port S-Parameter File
|
|
435
|
-
* ```plaintext
|
|
436
|
-
* ! 1-port S-parameter file
|
|
437
|
-
* # MHz S MA R 50
|
|
438
|
-
* 100 0.99 -4
|
|
439
|
-
* 200 0.80 -22
|
|
440
|
-
* 300 0.707 -45
|
|
441
|
-
* ```
|
|
442
|
-
*
|
|
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}
|
|
450
|
-
*/
|
|
451
|
-
export declare class Touchstone {
|
|
452
|
-
/**
|
|
453
|
-
* Comments in the file header with "!" symbol at the beginning of each row
|
|
454
|
-
*/
|
|
455
|
-
comments: string[];
|
|
456
|
-
/**
|
|
457
|
-
* Touchstone format: MA, DB, and RI
|
|
458
|
-
*/
|
|
459
|
-
private _format;
|
|
460
|
-
/**
|
|
461
|
-
* Set the Touchstone format: MA, DB, RI, or undefined
|
|
462
|
-
* - RI: real and imaginary, i.e. $A + j \cdot B$
|
|
463
|
-
* - MA: magnitude and angle (in degrees), i.e. $A \cdot e^{j \cdot {\pi \over 180} \cdot B }$
|
|
464
|
-
* - DB: decibels and angle (in degrees), i.e. $10^{A \over 20} \cdot e^{j \cdot {\pi \over 180} \cdot B}$
|
|
465
|
-
* @param format
|
|
466
|
-
* @returns
|
|
467
|
-
* @throws Will throw an error if the format is not valid
|
|
468
|
-
*/
|
|
469
|
-
set format(format: TouchstoneFormat | undefined | null);
|
|
470
|
-
/**
|
|
471
|
-
* Get the Touchstone format
|
|
472
|
-
* @returns
|
|
473
|
-
*/
|
|
474
|
-
get format(): TouchstoneFormat | undefined;
|
|
475
|
-
/**
|
|
476
|
-
* Type of network parameter: 'S' | 'Y' | 'Z' | 'G' | 'H'
|
|
477
|
-
*/
|
|
478
|
-
private _parameter;
|
|
479
|
-
/**
|
|
480
|
-
* Set the type of network parameter
|
|
481
|
-
* - S: Scattering parameters
|
|
482
|
-
* - Y: Admittance parameters
|
|
483
|
-
* - Z: Impedance parameters
|
|
484
|
-
* - H: Hybrid-h parameters
|
|
485
|
-
* - G: Hybrid-g parameters
|
|
486
|
-
* @param parameter
|
|
487
|
-
* @returns
|
|
488
|
-
* @throws Will throw an error if the parameter is not valid
|
|
489
|
-
*/
|
|
490
|
-
set parameter(parameter: TouchstoneParameter | undefined | null);
|
|
491
|
-
/**
|
|
492
|
-
* Get the type of network parameter
|
|
493
|
-
*/
|
|
494
|
-
get parameter(): TouchstoneParameter | undefined | null;
|
|
495
|
-
/**
|
|
496
|
-
* Reference impedance(s) for the network parameters
|
|
497
|
-
* Default: 50Ω
|
|
498
|
-
*/
|
|
499
|
-
private _impedance;
|
|
500
|
-
/**
|
|
501
|
-
* Set the Touchstone impedance.
|
|
502
|
-
* Default: 50Ω
|
|
503
|
-
* @param impedance
|
|
504
|
-
* @returns
|
|
505
|
-
* @throws Will throw an error if the impedance is not valid
|
|
506
|
-
*/
|
|
507
|
-
set impedance(impedance: TouchstoneImpedance);
|
|
508
|
-
/**
|
|
509
|
-
* Get the Touchstone impedance.
|
|
510
|
-
* Default: 50Ω
|
|
511
|
-
* @returns
|
|
512
|
-
*/
|
|
513
|
-
get impedance(): TouchstoneImpedance;
|
|
514
|
-
/**
|
|
515
|
-
* The number of ports in the network
|
|
516
|
-
*/
|
|
517
|
-
private _nports;
|
|
518
|
-
/**
|
|
519
|
-
* Set the ports number
|
|
520
|
-
* @param nports
|
|
521
|
-
* @returns
|
|
522
|
-
* @throws Will throw an error if the number of ports is not valid
|
|
523
|
-
*/
|
|
524
|
-
set nports(nports: number | undefined | null);
|
|
525
|
-
/**
|
|
526
|
-
* Get the ports number
|
|
527
|
-
*/
|
|
528
|
-
get nports(): number | undefined | null;
|
|
529
|
-
/**
|
|
530
|
-
* Frequency points
|
|
531
|
-
*/
|
|
532
|
-
frequency: Frequency | undefined;
|
|
533
|
-
/**
|
|
534
|
-
* 3D array to store the network parameter data
|
|
535
|
-
* - The first dimension is the exits (output) port number
|
|
536
|
-
* - The second dimension is the enters (input) port number
|
|
537
|
-
* - The third dimension is the frequency index
|
|
538
|
-
* For example, data[i][j][k] would be the parameter from j+1 port to i+1 port at frequency index k
|
|
539
|
-
*/
|
|
540
|
-
private _matrix;
|
|
541
|
-
/**
|
|
542
|
-
* Sets the network parameter matrix.
|
|
543
|
-
*
|
|
544
|
-
* @param matrix - The 3D complex matrix to store, or undefined/null to clear
|
|
545
|
-
* @remarks
|
|
546
|
-
* This setter provides a way to directly assign the network parameter matrix.
|
|
547
|
-
* Setting to undefined or null will clear the existing matrix data.
|
|
548
|
-
*/
|
|
549
|
-
set matrix(matrix: TouchstoneMatrix | undefined | null);
|
|
550
|
-
/**
|
|
551
|
-
* Gets the current network parameter matrix (3D array).
|
|
552
|
-
* Represents the S/Y/Z/G/H-parameters of the network.
|
|
553
|
-
*
|
|
554
|
-
* @remarks
|
|
555
|
-
* Matrix Structure:
|
|
556
|
-
* - First dimension [i]: Output (exit) port number (0 to nports-1)
|
|
557
|
-
* - Second dimension [j]: Input (enter) port number (0 to nports-1)
|
|
558
|
-
* - Third dimension [k]: Frequency point index
|
|
559
|
-
*
|
|
560
|
-
* Example:
|
|
561
|
-
* - matrix[i][j][k] represents the parameter from port j+1 to port i+1 at frequency k
|
|
562
|
-
* - For S-parameters: matrix[1][0][5] is S₂₁ at the 6th frequency point
|
|
563
|
-
*
|
|
564
|
-
* Special case for 2-port networks:
|
|
565
|
-
* - Indices are swapped to match traditional Touchstone format
|
|
566
|
-
* - matrix[0][1][k] represents S₁₂ (not S₂₁)
|
|
567
|
-
*
|
|
568
|
-
* @returns The current network parameter matrix, or undefined if not set
|
|
569
|
-
*/
|
|
570
|
-
get matrix(): TouchstoneMatrix | undefined | null;
|
|
571
|
-
/**
|
|
572
|
-
* Reads and parses a Touchstone format string into the internal data structure.
|
|
573
|
-
*
|
|
574
|
-
* @param string - The Touchstone format string to parse
|
|
575
|
-
* @param nports - Number of ports in the network
|
|
576
|
-
*
|
|
577
|
-
* @throws {Error} If the option line is missing or invalid
|
|
578
|
-
* @throws {Error} If multiple option lines are found
|
|
579
|
-
* @throws {Error} If the impedance specification is invalid
|
|
580
|
-
* @throws {Error} If the data format is invalid or incomplete
|
|
581
|
-
*
|
|
582
|
-
* @remarks
|
|
583
|
-
* The method performs the following steps:
|
|
584
|
-
* 1. Parses comments and option line
|
|
585
|
-
* 2. Extracts frequency points
|
|
586
|
-
* 3. Converts raw data into complex numbers based on format
|
|
587
|
-
* 4. Stores the results in the matrix property
|
|
588
|
-
*/
|
|
589
|
-
readContent(string: string, nports: number): void;
|
|
590
|
-
/**
|
|
591
|
-
* Validates the internal state of the Touchstone instance.
|
|
592
|
-
* Performs comprehensive checks on all required data and matrix dimensions.
|
|
593
|
-
*
|
|
594
|
-
* @throws {Error} If any of the following conditions are met:
|
|
595
|
-
* - Number of ports is undefined
|
|
596
|
-
* - Frequency object is not initialized
|
|
597
|
-
* - Frequency points array is empty
|
|
598
|
-
* - Network parameter type is undefined
|
|
599
|
-
* - Data format is undefined
|
|
600
|
-
* - Network parameter matrix is undefined
|
|
601
|
-
* - Matrix dimensions don't match with nports or frequency points
|
|
602
|
-
*
|
|
603
|
-
* @remarks
|
|
604
|
-
* This method performs two main validation steps:
|
|
605
|
-
* 1. Essential Data Validation:
|
|
606
|
-
* - Checks existence of all required properties
|
|
607
|
-
* - Ensures frequency points are available
|
|
608
|
-
*
|
|
609
|
-
* 2. Matrix Dimension Validation:
|
|
610
|
-
* - Verifies matrix row count matches port number
|
|
611
|
-
* - Ensures each row has correct number of columns
|
|
612
|
-
* - Validates frequency points count in each matrix element
|
|
613
|
-
*/
|
|
614
|
-
validate(): void;
|
|
615
|
-
/**
|
|
616
|
-
* Generates a Touchstone format string from the internal data structure.
|
|
617
|
-
*
|
|
618
|
-
* @returns The generated Touchstone format string
|
|
619
|
-
*
|
|
620
|
-
* @throws {Error} If any required data is missing
|
|
621
|
-
* @throws {Error} If the matrix dimensions are invalid
|
|
622
|
-
*
|
|
623
|
-
* @remarks
|
|
624
|
-
* The generated string includes:
|
|
625
|
-
* 1. Comments (if any)
|
|
626
|
-
* 2. Option line with format, parameter type, and impedance
|
|
627
|
-
* 3. Network parameter data in the specified format
|
|
628
|
-
*/
|
|
629
|
-
writeContent(): string;
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
/**
|
|
633
|
-
* S-parameter format: MA, DB, and RI
|
|
634
|
-
* - RI: real and imaginary, i.e. $A + j \cdot B$
|
|
635
|
-
* - MA: magnitude and angle (in degrees), i.e. $A \cdot e^{j \cdot {\pi \over 180} \cdot B }$
|
|
636
|
-
* - DB: decibels and angle (in degrees), i.e. $10^{A \over 20} \cdot e^{j \cdot {\pi \over 180} \cdot B}$
|
|
637
|
-
*/
|
|
638
|
-
export declare type TouchstoneFormat = (typeof TouchstoneFormats)[number];
|
|
639
|
-
|
|
640
|
-
/**
|
|
641
|
-
* S-parameter format: MA, DB, and RI
|
|
642
|
-
* - RI: real and imaginary, i.e. $A + j \cdot B$
|
|
643
|
-
* - MA: magnitude and angle (in degrees), i.e. $A \cdot e^{j \cdot {\pi \over 180} \cdot B }$
|
|
644
|
-
* - DB: decibels and angle (in degrees), i.e. $10^{A \over 20} \cdot e^{j \cdot {\pi \over 180} \cdot B}$
|
|
645
|
-
*/
|
|
646
|
-
export declare const TouchstoneFormats: readonly ["RI", "MA", "DB"];
|
|
647
|
-
|
|
648
|
-
/**
|
|
649
|
-
* The reference resistance(s) for the network parameters.
|
|
650
|
-
* The token "R" (case-insensitive) followed by one or more reference resistance values.
|
|
651
|
-
* Default: 50Ω
|
|
652
|
-
*
|
|
653
|
-
* For Touchstone 1.0, this is a single value for all ports.
|
|
654
|
-
* For Touchstone 1.1, this can be an array of values (one per port)
|
|
655
|
-
*/
|
|
656
|
-
export declare type TouchstoneImpedance = number | number[];
|
|
657
|
-
|
|
658
|
-
/**
|
|
659
|
-
* Network parameter matrix stored as complex numbers.
|
|
660
|
-
*
|
|
661
|
-
* @remarks
|
|
662
|
-
* The matrix is a 3D array with the following dimensions:
|
|
663
|
-
* - First dimension: output port index (0 to nports-1)
|
|
664
|
-
* - Second dimension: input port index (0 to nports-1)
|
|
665
|
-
* - Third dimension: frequency point index
|
|
666
|
-
*
|
|
667
|
-
* For example:
|
|
668
|
-
* - matrix[i][j][k] represents the parameter from port j+1 to port i+1 at frequency k
|
|
669
|
-
* - For S-parameters: matrix[1][0][5] is S₂₁ at the 6th frequency point
|
|
670
|
-
*
|
|
671
|
-
* Special case for 2-port networks:
|
|
672
|
-
* - Indices are swapped to match traditional Touchstone format
|
|
673
|
-
* - matrix[0][1][k] represents S₁₂ (not S₂₁)
|
|
674
|
-
*/
|
|
675
|
-
export declare type TouchstoneMatrix = Complex[][][];
|
|
676
|
-
|
|
677
|
-
/**
|
|
678
|
-
* Type of network parameters: 'S' | 'Y' | 'Z' | 'G' | 'H'
|
|
679
|
-
* - S: Scattering parameters
|
|
680
|
-
* - Y: Admittance parameters
|
|
681
|
-
* - Z: Impedance parameters
|
|
682
|
-
* - H: Hybrid-h parameters
|
|
683
|
-
* - G: Hybrid-g parameters
|
|
684
|
-
*/
|
|
685
|
-
export declare type TouchstoneParameter = (typeof TouchstoneParameters)[number];
|
|
686
|
-
|
|
687
|
-
/**
|
|
688
|
-
* Type of network parameters
|
|
689
|
-
* - S: Scattering parameters
|
|
690
|
-
* - Y: Admittance parameters
|
|
691
|
-
* - Z: Impedance parameters
|
|
692
|
-
* - H: Hybrid-h parameters
|
|
693
|
-
* - G: Hybrid-g parameters
|
|
694
|
-
*/
|
|
695
|
-
export declare const TouchstoneParameters: string[];
|
|
696
|
-
|
|
697
|
-
export { }
|
|
1
|
+
import { Complex } from 'mathjs';
|
|
2
|
+
import { Frequency } from './frequency';
|
|
3
|
+
/**
|
|
4
|
+
* S-parameter format: MA, DB, and RI
|
|
5
|
+
* - RI: real and imaginary, i.e. $A + j \cdot B$
|
|
6
|
+
* - MA: magnitude and angle (in degrees), i.e. $A \cdot e^{j \cdot {\pi \over 180} \cdot B }$
|
|
7
|
+
* - DB: decibels and angle (in degrees), i.e. $10^{A \over 20} \cdot e^{j \cdot {\pi \over 180} \cdot B}$
|
|
8
|
+
*/
|
|
9
|
+
export declare const TouchstoneFormats: readonly ["RI", "MA", "DB"];
|
|
10
|
+
/**
|
|
11
|
+
* S-parameter format: MA, DB, and RI
|
|
12
|
+
* - RI: real and imaginary, i.e. $A + j \cdot B$
|
|
13
|
+
* - MA: magnitude and angle (in degrees), i.e. $A \cdot e^{j \cdot {\pi \over 180} \cdot B }$
|
|
14
|
+
* - DB: decibels and angle (in degrees), i.e. $10^{A \over 20} \cdot e^{j \cdot {\pi \over 180} \cdot B}$
|
|
15
|
+
*/
|
|
16
|
+
export type TouchstoneFormat = (typeof TouchstoneFormats)[number];
|
|
17
|
+
/**
|
|
18
|
+
* Type of network parameters
|
|
19
|
+
* - S: Scattering parameters
|
|
20
|
+
* - Y: Admittance parameters
|
|
21
|
+
* - Z: Impedance parameters
|
|
22
|
+
* - H: Hybrid-h parameters
|
|
23
|
+
* - G: Hybrid-g parameters
|
|
24
|
+
*/
|
|
25
|
+
export declare const TouchstoneParameters: string[];
|
|
26
|
+
/**
|
|
27
|
+
* Type of network parameters: 'S' | 'Y' | 'Z' | 'G' | 'H'
|
|
28
|
+
* - S: Scattering parameters
|
|
29
|
+
* - Y: Admittance parameters
|
|
30
|
+
* - Z: Impedance parameters
|
|
31
|
+
* - H: Hybrid-h parameters
|
|
32
|
+
* - G: Hybrid-g parameters
|
|
33
|
+
*/
|
|
34
|
+
export type TouchstoneParameter = (typeof TouchstoneParameters)[number];
|
|
35
|
+
/**
|
|
36
|
+
* The reference resistance(s) for the network parameters.
|
|
37
|
+
* The token "R" (case-insensitive) followed by one or more reference resistance values.
|
|
38
|
+
* Default: 50Ω
|
|
39
|
+
*
|
|
40
|
+
* For Touchstone 1.0, this is a single value for all ports.
|
|
41
|
+
* For Touchstone 1.1, this can be an array of values (one per port)
|
|
42
|
+
*/
|
|
43
|
+
export type TouchstoneImpedance = number | number[];
|
|
44
|
+
/**
|
|
45
|
+
* Network parameter matrix stored as complex numbers.
|
|
46
|
+
*
|
|
47
|
+
* @remarks
|
|
48
|
+
* The matrix is a 3D array with the following dimensions:
|
|
49
|
+
* - First dimension: output port index (0 to nports-1)
|
|
50
|
+
* - Second dimension: input port index (0 to nports-1)
|
|
51
|
+
* - Third dimension: frequency point index
|
|
52
|
+
*
|
|
53
|
+
* For example:
|
|
54
|
+
* - matrix[i][j][k] represents the parameter from port j+1 to port i+1 at frequency k
|
|
55
|
+
* - For S-parameters: matrix[1][0][5] is S₂₁ at the 6th frequency point
|
|
56
|
+
*
|
|
57
|
+
* Special case for 2-port networks:
|
|
58
|
+
* - Indices are swapped to match traditional Touchstone format
|
|
59
|
+
* - matrix[0][1][k] represents S₁₂ (not S₂₁)
|
|
60
|
+
*/
|
|
61
|
+
export type TouchstoneMatrix = Complex[][][];
|
|
62
|
+
/**
|
|
63
|
+
* Touchstone class for reading and writing network parameter data in Touchstone format.
|
|
64
|
+
* Supports both version 1.0 and 1.1 of the Touchstone specification.
|
|
65
|
+
*
|
|
66
|
+
* @remarks
|
|
67
|
+
* #### Overview
|
|
68
|
+
*
|
|
69
|
+
* 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.
|
|
70
|
+
*
|
|
71
|
+
* A Touchstone file contains data about network parameters (e.g., S-parameters, Y-parameters, Z-parameters) at specific frequencies.
|
|
72
|
+
*
|
|
73
|
+
* ##### Key Features:
|
|
74
|
+
* - **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.
|
|
75
|
+
* - **Case Insensitivity**: Touchstone files are case-insensitive, meaning keywords and values can be written in uppercase or lowercase.
|
|
76
|
+
* - **Versioning**: **Only version 1.0 and 1.1 are supported in this class**
|
|
77
|
+
*
|
|
78
|
+
* ---
|
|
79
|
+
*
|
|
80
|
+
* #### File Structure
|
|
81
|
+
*
|
|
82
|
+
* A Touchstone file consists of several sections, each serving a specific purpose. Below is a breakdown of the structure:
|
|
83
|
+
*
|
|
84
|
+
* ##### 1. Header Section
|
|
85
|
+
*
|
|
86
|
+
* - **Comment Lines**: Lines starting with `!` are treated as comments and ignored during parsing.
|
|
87
|
+
* - **Option Line**: Line starting with `#` defines global settings for the file, such as frequency units, parameter type, and data format. Example:
|
|
88
|
+
* ```plaintext
|
|
89
|
+
* # GHz S MA R 50
|
|
90
|
+
* ```
|
|
91
|
+
* - `GHz`: Frequency unit (can be `Hz`, `kHz`, `MHz`, or `GHz`).
|
|
92
|
+
* - `S`: Parameter type (`S`, `Y`, `Z`, `H`, or `G`).
|
|
93
|
+
* - `MA`: Data format (`MA` for magnitude-angle, `DB` for decibel-angle, or `RI` for real-imaginary).
|
|
94
|
+
* - `R 50`: Reference resistance in ohms (default is 50 ohms if omitted).
|
|
95
|
+
*
|
|
96
|
+
* ##### 2. Network Data
|
|
97
|
+
*
|
|
98
|
+
* The core of the file contains the network parameter data, organized by frequency. Each frequency point is followed by its corresponding parameter values.
|
|
99
|
+
*
|
|
100
|
+
* - **Single-Ended Networks**: Data is arranged in a matrix format. For example, a 2-port network might look like this:
|
|
101
|
+
* ```plaintext
|
|
102
|
+
* <frequency> <N11> <N21> <N12> <N22>
|
|
103
|
+
* ```
|
|
104
|
+
*
|
|
105
|
+
* ---
|
|
106
|
+
*
|
|
107
|
+
* #### References:
|
|
108
|
+
* - {@link https://ibis.org/touchstone_ver2.1/touchstone_ver2_1.pdf Touchstone(R) File Format Specification (Version 2.1)}
|
|
109
|
+
* - {@link https://books.google.com/books/about/S_Parameters_for_Signal_Integrity.html?id=_dLKDwAAQBAJ S-Parameters for Signal Integrity}
|
|
110
|
+
* - {@link https://github.com/scikit-rf/scikit-rf/blob/master/skrf/io/touchstone.py scikit-rf: Open Source RF Engineering}
|
|
111
|
+
* - {@link https://github.com/Nubis-Communications/SignalIntegrity/blob/master/SignalIntegrity/Lib/SParameters/SParameters.py SignalIntegrity: Signal and Power Integrity Tools}
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
*
|
|
115
|
+
* #### Example 1: Simple 1-Port S-Parameter File
|
|
116
|
+
* ```plaintext
|
|
117
|
+
* ! 1-port S-parameter file
|
|
118
|
+
* # MHz S MA R 50
|
|
119
|
+
* 100 0.99 -4
|
|
120
|
+
* 200 0.80 -22
|
|
121
|
+
* 300 0.707 -45
|
|
122
|
+
* ```
|
|
123
|
+
*
|
|
124
|
+
* #### Example 2: Simple 2-Port S-Parameter File
|
|
125
|
+
* ```plaintext
|
|
126
|
+
* ! Sample S2P File
|
|
127
|
+
* # HZ S RI R 50
|
|
128
|
+
* ! Freq S11(real) S11(imag) S21(real) S21(imag) S12(real) S12(imag) S22(real) S22(imag)
|
|
129
|
+
* 1000000000 0.9 -0.1 0.01 0.02 0.01 0.02 0.8 -0.15
|
|
130
|
+
* 2000000000 0.8 -0.2 0.02 0.03 0.02 0.03 0.7 -0.25
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
export declare class Touchstone {
|
|
134
|
+
/**
|
|
135
|
+
* Comments in the file header with `!` symbol at the beginning of each row
|
|
136
|
+
*/
|
|
137
|
+
comments: string[];
|
|
138
|
+
/**
|
|
139
|
+
* Touchstone format: MA, DB, and RI
|
|
140
|
+
*/
|
|
141
|
+
private _format;
|
|
142
|
+
/**
|
|
143
|
+
* Set the Touchstone format: MA, DB, RI, or undefined
|
|
144
|
+
* - RI: real and imaginary, i.e. $A + j \cdot B$
|
|
145
|
+
* - MA: magnitude and angle (in degrees), i.e. $A \cdot e^{j \cdot {\pi \over 180} \cdot B }$
|
|
146
|
+
* - DB: decibels and angle (in degrees), i.e. $10^{A \over 20} \cdot e^{j \cdot {\pi \over 180} \cdot B}$
|
|
147
|
+
* @param format
|
|
148
|
+
* @returns
|
|
149
|
+
* @throws Will throw an error if the format is not valid
|
|
150
|
+
*/
|
|
151
|
+
set format(format: TouchstoneFormat | undefined | null);
|
|
152
|
+
/**
|
|
153
|
+
* Get the Touchstone format
|
|
154
|
+
* @returns
|
|
155
|
+
*/
|
|
156
|
+
get format(): TouchstoneFormat | undefined;
|
|
157
|
+
/**
|
|
158
|
+
* Type of network parameter: 'S' | 'Y' | 'Z' | 'G' | 'H'
|
|
159
|
+
*/
|
|
160
|
+
private _parameter;
|
|
161
|
+
/**
|
|
162
|
+
* Set the type of network parameter
|
|
163
|
+
* - S: Scattering parameters
|
|
164
|
+
* - Y: Admittance parameters
|
|
165
|
+
* - Z: Impedance parameters
|
|
166
|
+
* - H: Hybrid-h parameters
|
|
167
|
+
* - G: Hybrid-g parameters
|
|
168
|
+
* @param parameter
|
|
169
|
+
* @returns
|
|
170
|
+
* @throws Will throw an error if the parameter is not valid
|
|
171
|
+
*/
|
|
172
|
+
set parameter(parameter: TouchstoneParameter | undefined | null);
|
|
173
|
+
/**
|
|
174
|
+
* Get the type of network parameter
|
|
175
|
+
*/
|
|
176
|
+
get parameter(): TouchstoneParameter | undefined | null;
|
|
177
|
+
/**
|
|
178
|
+
* Reference impedance(s) for the network parameters
|
|
179
|
+
* Default: 50Ω
|
|
180
|
+
*/
|
|
181
|
+
private _impedance;
|
|
182
|
+
/**
|
|
183
|
+
* Set the Touchstone impedance.
|
|
184
|
+
* Default: 50Ω
|
|
185
|
+
* @param impedance
|
|
186
|
+
* @returns
|
|
187
|
+
* @throws Will throw an error if the impedance is not valid
|
|
188
|
+
*/
|
|
189
|
+
set impedance(impedance: TouchstoneImpedance);
|
|
190
|
+
/**
|
|
191
|
+
* Get the Touchstone impedance.
|
|
192
|
+
* Default: 50Ω
|
|
193
|
+
* @returns
|
|
194
|
+
*/
|
|
195
|
+
get impedance(): TouchstoneImpedance;
|
|
196
|
+
/**
|
|
197
|
+
* The number of ports in the network
|
|
198
|
+
*/
|
|
199
|
+
private _nports;
|
|
200
|
+
/**
|
|
201
|
+
* Set the ports number
|
|
202
|
+
* @param nports
|
|
203
|
+
* @returns
|
|
204
|
+
* @throws Will throw an error if the number of ports is not valid
|
|
205
|
+
*/
|
|
206
|
+
set nports(nports: number | undefined | null);
|
|
207
|
+
/**
|
|
208
|
+
* Get the ports number
|
|
209
|
+
*/
|
|
210
|
+
get nports(): number | undefined | null;
|
|
211
|
+
/**
|
|
212
|
+
* Frequency points
|
|
213
|
+
*/
|
|
214
|
+
frequency: Frequency | undefined;
|
|
215
|
+
/**
|
|
216
|
+
* 3D array to store the network parameter data
|
|
217
|
+
* - The first dimension is the exits (output) port number
|
|
218
|
+
* - The second dimension is the enters (input) port number
|
|
219
|
+
* - The third dimension is the frequency index
|
|
220
|
+
* For example, data[i][j][k] would be the parameter from j+1 port to i+1 port at frequency index k
|
|
221
|
+
*/
|
|
222
|
+
private _matrix;
|
|
223
|
+
/**
|
|
224
|
+
* Sets the network parameter matrix.
|
|
225
|
+
*
|
|
226
|
+
* @param matrix - The 3D complex matrix to store, or undefined/null to clear
|
|
227
|
+
* @remarks
|
|
228
|
+
* This setter provides a way to directly assign the network parameter matrix.
|
|
229
|
+
* Setting to undefined or null will clear the existing matrix data.
|
|
230
|
+
*/
|
|
231
|
+
set matrix(matrix: TouchstoneMatrix | undefined | null);
|
|
232
|
+
/**
|
|
233
|
+
* Gets the current network parameter matrix (3D array).
|
|
234
|
+
* Represents the S/Y/Z/G/H-parameters of the network.
|
|
235
|
+
*
|
|
236
|
+
* @remarks
|
|
237
|
+
* Matrix Structure:
|
|
238
|
+
* - First dimension [i]: Output (exit) port number (0 to nports-1)
|
|
239
|
+
* - Second dimension [j]: Input (enter) port number (0 to nports-1)
|
|
240
|
+
* - Third dimension [k]: Frequency point index
|
|
241
|
+
*
|
|
242
|
+
* Example:
|
|
243
|
+
* - matrix[i][j][k] represents the parameter from port j+1 to port i+1 at frequency k
|
|
244
|
+
* - For S-parameters: matrix[1][0][5] is S₂₁ at the 6th frequency point
|
|
245
|
+
*
|
|
246
|
+
* Special case for 2-port networks:
|
|
247
|
+
* - Indices are swapped to match traditional Touchstone format
|
|
248
|
+
* - matrix[0][1][k] represents S₁₂ (not S₂₁)
|
|
249
|
+
*
|
|
250
|
+
* @returns The current network parameter matrix, or undefined if not set
|
|
251
|
+
*/
|
|
252
|
+
get matrix(): TouchstoneMatrix | undefined | null;
|
|
253
|
+
/**
|
|
254
|
+
* Reads and parses a Touchstone format string into the internal data structure.
|
|
255
|
+
*
|
|
256
|
+
* @param string - The Touchstone format string to parse
|
|
257
|
+
* @param nports - Number of ports in the network
|
|
258
|
+
*
|
|
259
|
+
* @throws {Error} If the option line is missing or invalid
|
|
260
|
+
* @throws {Error} If multiple option lines are found
|
|
261
|
+
* @throws {Error} If the impedance specification is invalid
|
|
262
|
+
* @throws {Error} If the data format is invalid or incomplete
|
|
263
|
+
*
|
|
264
|
+
* @remarks
|
|
265
|
+
* The method performs the following steps:
|
|
266
|
+
* 1. Parses comments and option line
|
|
267
|
+
* 2. Extracts frequency points
|
|
268
|
+
* 3. Converts raw data into complex numbers based on format
|
|
269
|
+
* 4. Stores the results in the matrix property
|
|
270
|
+
*
|
|
271
|
+
* @example
|
|
272
|
+
* ```typescript
|
|
273
|
+
* import { Touchstone, Frequency } from 'rf-touchstone';
|
|
274
|
+
*
|
|
275
|
+
* const s1pString = `
|
|
276
|
+
* ! This is a 1-port S-parameter file
|
|
277
|
+
* # MHz S MA R 50
|
|
278
|
+
* 100 0.99 -4
|
|
279
|
+
* 200 0.80 -22
|
|
280
|
+
* 300 0.707 -45
|
|
281
|
+
* `;
|
|
282
|
+
*
|
|
283
|
+
* const touchstone = new Touchstone();
|
|
284
|
+
* touchstone.readContent(s1pString, 1);
|
|
285
|
+
*
|
|
286
|
+
* console.log(touchstone.comments); // Outputs: [ 'This is a 1-port S-parameter file' ]
|
|
287
|
+
* console.log(touchstone.format); // Outputs: 'MA'
|
|
288
|
+
* console.log(touchstone.parameter); // Outputs: 'S'
|
|
289
|
+
* console.log(touchstone.impedance); // Outputs: 50
|
|
290
|
+
* console.log(touchstone.nports); // Outputs: 1
|
|
291
|
+
* console.log(touchstone.frequency?.f_scaled); // Outputs: [ 100, 200, 300 ]
|
|
292
|
+
* console.log(touchstone.matrix); // Outputs: the parsed matrix data
|
|
293
|
+
* ```
|
|
294
|
+
*/
|
|
295
|
+
readContent(string: string, nports: number): void;
|
|
296
|
+
/**
|
|
297
|
+
* Validates the internal state of the Touchstone instance.
|
|
298
|
+
* Performs comprehensive checks on all required data and matrix dimensions.
|
|
299
|
+
*
|
|
300
|
+
* @throws {Error} If any of the following conditions are met:
|
|
301
|
+
* - Number of ports is undefined
|
|
302
|
+
* - Frequency object is not initialized
|
|
303
|
+
* - Frequency points array is empty
|
|
304
|
+
* - Network parameter type is undefined
|
|
305
|
+
* - Data format is undefined
|
|
306
|
+
* - Network parameter matrix is undefined
|
|
307
|
+
* - Matrix dimensions don't match with nports or frequency points
|
|
308
|
+
*
|
|
309
|
+
* @remarks
|
|
310
|
+
* This method performs two main validation steps:
|
|
311
|
+
* 1. Essential Data Validation:
|
|
312
|
+
* - Checks existence of all required properties
|
|
313
|
+
* - Ensures frequency points are available
|
|
314
|
+
*
|
|
315
|
+
* 2. Matrix Dimension Validation:
|
|
316
|
+
* - Verifies matrix row count matches port number
|
|
317
|
+
* - Ensures each row has correct number of columns
|
|
318
|
+
* - Validates frequency points count in each matrix element
|
|
319
|
+
*/
|
|
320
|
+
validate(): void;
|
|
321
|
+
/**
|
|
322
|
+
* Generates a Touchstone format string from the internal data structure.
|
|
323
|
+
*
|
|
324
|
+
* @returns The generated Touchstone format string
|
|
325
|
+
*
|
|
326
|
+
* @throws {Error} If any required data is missing
|
|
327
|
+
* @throws {Error} If the matrix dimensions are invalid
|
|
328
|
+
*
|
|
329
|
+
* @remarks
|
|
330
|
+
* The generated string includes:
|
|
331
|
+
* 1. Comments (if any)
|
|
332
|
+
* 2. Option line with format, parameter type, and impedance
|
|
333
|
+
* 3. Network parameter data in the specified format
|
|
334
|
+
*
|
|
335
|
+
* @example
|
|
336
|
+
* ```typescript
|
|
337
|
+
* import { Touchstone, Frequency } from 'rf-touchstone';
|
|
338
|
+
* import { complex } from 'mathjs';
|
|
339
|
+
*
|
|
340
|
+
* const touchstone = new Touchstone();
|
|
341
|
+
*
|
|
342
|
+
* // Set properties and matrix data (using simplified complex number representation for example)
|
|
343
|
+
* touchstone.comments = ['Generated by rf-touchstone'];
|
|
344
|
+
* touchstone.nports = 1;
|
|
345
|
+
* touchstone.frequency = new Frequency();
|
|
346
|
+
* touchstone.frequency.unit = 'GHz';
|
|
347
|
+
* touchstone.frequency.f_scaled = [1.0, 2.0];
|
|
348
|
+
* touchstone.parameter = 'S';
|
|
349
|
+
* touchstone.format = 'MA';
|
|
350
|
+
* touchstone.impedance = 50;
|
|
351
|
+
* touchstone.matrix = [
|
|
352
|
+
* [ // Output port 1
|
|
353
|
+
* [complex(0.5, 0.1), complex(0.4, 0.2)] // S11 at each frequency
|
|
354
|
+
* ]
|
|
355
|
+
* ];
|
|
356
|
+
*
|
|
357
|
+
* const s1pString = touchstone.writeContent();
|
|
358
|
+
* console.log(s1pString);
|
|
359
|
+
* // Expected output (approximately, due to floating point precision):
|
|
360
|
+
* // ! Generated by rf-touchstone
|
|
361
|
+
* // # GHz S MA R 50
|
|
362
|
+
* // 1 0.5099 11.3099
|
|
363
|
+
* // 2 0.4472 26.5651
|
|
364
|
+
* ```
|
|
365
|
+
*/
|
|
366
|
+
writeContent(): string;
|
|
367
|
+
}
|