Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TouchstoneParser fails to load files with \r\n line endings on Windows #528

Closed
TerryHoCQ opened this issue Dec 25, 2021 · 12 comments
Closed
Assignees
Labels
bug Something isn't working portability Things that break on some OS
Milestone

Comments

@TerryHoCQ
Copy link

Merry Christmas! I'm trying to generate TDR waveform from a S2p file (On offline mode), and I found 2 issues on importing touchstone file, thank you!

1: Fail to import touchstone from File menu
2: Can import touchstone file from Add/import menu, but no waveform generated.

@TerryHoCQ TerryHoCQ changed the title Dec 25, 2021
@TerryHoCQ TerryHoCQ changed the title Dec 25, 2021
@azonenberg
Copy link
Collaborator

Please paste output of running glscopeclient with "--debug --trace TouchstoneParser" and trying to load your test file.

Also, are you able to share the .s2p file so I can try reproducing on my end?

@TerryHoCQ
Copy link
Author

Thank you! And please download the .s2p file from below link:
http://www.sisolver.com/temp/SxP.zip

@azonenberg
Copy link
Collaborator

Testing on my end, all three files appear to load correctly.

There's an issue from the refactoring of the channel emulation / de-embed filter that makes it not work with touchstone files opened via file|import, you have to do add|import for it to recognize the file. This will be fixed at some point soon.

When you do add|import, do you not see a mag/angle waveform? Can you generate other test waveforms, say add|generate|sine, and see correct waveforms there? Are you testing on Linux or Windows?

398-2
398-1

@TerryHoCQ
Copy link
Author

Hello! I tested on Windows. Yes, add|import function works on test.s2p file, and failed on 12.s2p file. Here are the snapshots for your reference, thank you!
Test1
Test2

@azonenberg
Copy link
Collaborator

All of your files load fine for me on Linux... but interestingly, 12.s2p has Windows-style \r\n line terminations while test.s2p has Unix-style \n line terminators. Can you try using dos2unix or similar to change the line endings and confirm that \r\n line endings trigger the bug while \n do not? If so, we're looking at a platform specific line ending handling problem.

Unrelated: you'll probably want to have the TDR filter have step start = -1V and end=0V (i.e. still a 1V step, but ending at zero) if your S-parameters don't contain a DC component, since the resting (zero reflection) state of the channel emulation filter is going to be 0V not 1V in this case.

@azonenberg azonenberg changed the title Dec 26, 2021
@azonenberg
Copy link
Collaborator

Also, migrating this ticket to the scopehal repo since it appears to be a bug in the TouchstoneParser class in libscopehal, rather than in the glscopeclient UI.

@azonenberg azonenberg transferred this issue from ngscopeclient/scopehal-apps Dec 26, 2021
@azonenberg azonenberg self-assigned this Dec 26, 2021
@azonenberg azonenberg added bug Something isn't working portability Things that break on some OS labels Dec 26, 2021
@azonenberg azonenberg added this to the v0.1 milestone Dec 26, 2021
@TerryHoCQ
Copy link
Author

TerryHoCQ commented Dec 26, 2021

Confirmed the problem: "12.s2p has Windows-style \r\n line terminations while test.s2p has Unix-style \n line terminators."

And I reset the TDR filter step start = -1V and end=0V, but waveform is not correct. please help to advise, thank you !

test2-1
test2-2

@azonenberg
Copy link
Collaborator

azonenberg commented Dec 26, 2021

You seem to be zoomed really far out on the TDR plot.

For 50 GHz S-parameters you're going to want your stimulus waveform to be a minimum of 100 Gsps (minimum Nyquist rate), and the curves will look more smooth if you go even higher. I'd suggest 500 Gsps.

Here's what I get when zooming in on test.s2p S11 applied to a 500 Gsps step. This looks plausible for a transmission line with a nominal impedance of about 52 ohms plus a bit of loss causing an upward slope to the curve. The overall reflection curve is about 900ps long, so your line is about 450ps propagation delay one way (which lines up nicely with the S21 group delay of your .s2p). Assuming around 6ps / mm propagation velocity your line is probably about 75mm in physical length.

tdr-curve

@azonenberg
Copy link
Collaborator

Also, try changing the fopen() call in TouchstoneParser::Load() (line 60 of lib/scopehal/TouchstoneParser.cpp) to open the file in binary mode ("rb" instead of "r"). Does that fix the import issue? Opening in text mode should work fine on Windows, but who knows...

@TerryHoCQ
Copy link
Author

Also, try changing the fopen() call in TouchstoneParser::Load() (line 60 of lib/scopehal/TouchstoneParser.cpp) to open the file in binary mode ("rb" instead of "r"). Does that fix the import issue? Opening in text mode should work fine on Windows, but who knows...

I have rebuilt the code, and confirmed it works fine by changingTouchstoneParser::Load() ("rb" instead of "r") on Windows.

@TerryHoCQ
Copy link
Author

TerryHoCQ commented Dec 26, 2021

And I tried to set the step rate with 500 Gsps, it seems the Channel emulation waveform is not correct. Thank you!
test3

@azonenberg
Copy link
Collaborator

I'm not sure it's actually wrong. You're zoomed waaaaaay out and seem to be seeing low frequency / interpolation artifacts caused by the limited low frequency content of your .s2p. Try zooming in the channel emulation view to +/- 2ns of the step or so.

I'm closing this issue as the original line ending issue is now fixed and I don't want to mix different problems in one ticket. Feel free to file a second one if you're having further trouble.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working portability Things that break on some OS
Projects
None yet
Development

No branches or pull requests

2 participants