Frequency Response Analyzer with Bode Plots

Post discussions on applications you are writing
Post Reply
zolkow
Advanced
Posts: 0
Joined: Sun Apr 12, 2015 9:36 am
Location: Hungary

Re: Frequency Response Analyzer with Bode Plots

Post by zolkow »

great!

I did it: the stdout file remained 0 size, the error output got 11 lines of this message:
"Can't open C:\Users\Zoltán\Documents\FRA4PicoScope\diag\step0try0.svg."


a couple of times I tried running the app in admin mode, but didn't help.
usually I try this if something should work, but does not :)
But I'm afraid I don't know how to run a program in admin mode WITH command line switches :oops:

hexamer
Advanced User
Advanced User
Posts: 5
Joined: Tue Aug 12, 2014 10:09 pm

Re: Frequency Response Analyzer with Bode Plots

Post by hexamer »

zolkow wrote:great!

I did it: the stdout file remained 0 size, the error output got 11 lines of this message:
"Can't open C:\Users\Zoltán\Documents\FRA4PicoScope\diag\step0try0.svg."


a couple of times I tried running the app in admin mode, but didn't help.
usually I try this if something should work, but does not :)
But I'm afraid I don't know how to run a program in admin mode WITH command line switches :oops:
Great! We probably won't need to run as admin and use command switches simultaneously - there are other fairly simple ways to see if this is a privilege issue. One way is to launch notepad, type some characters, then try to save the text file in that directory. If you can create the text file when you don't have elevated privileges, then that's not the issue.

Another thing that seems like a possibility is if somehow PLplot didn't get compiled with fully working Unicode support. I'm wondering if the acute a "á" in your name might be causing issues with "fopen". I could try some experiments on my side to see if this is an issue.

zolkow
Advanced
Posts: 0
Joined: Sun Apr 12, 2015 9:36 am
Location: Hungary

Re: Frequency Response Analyzer with Bode Plots

Post by zolkow »

I could create a file there without any problems, but how could I eliminate that accent from my folder name?
By creating a new user, and reinstalling the program for him?

hexamer
Advanced User
Advanced User
Posts: 5
Joined: Tue Aug 12, 2014 10:09 pm

Re: Frequency Response Analyzer with Bode Plots

Post by hexamer »

zolkow wrote:I could create a file there without any problems, but how could I eliminate that accent from my folder name?
By creating a new user, and reinstalling the program for him?
Yes, that might work - at least for a short term diagnosis/workaround.

There really should be no reason the whole program can't support Unicode, other than perhaps a simple oversight on my part. My app has Unicode support and PLplot definitely can support it as well, but I might have made a mistake while integrating PLplot.

hexamer
Advanced User
Advanced User
Posts: 5
Joined: Tue Aug 12, 2014 10:09 pm

Re: Frequency Response Analyzer with Bode Plots

Post by hexamer »

I think the issue with outputting the diagnostic plots is a due to a couple of things which I've learned with some experimentation.

PLplot's advertised Unicode support is really about the display of plot text. For output graphics file creation, it still uses functions like plsfnam and fopen which take ASCII (single byte/character) strings. I've found that fopen can actually deal with extended ASCII, such as the á in your name (encoded as 0xE1) just fine. But it seems that fopen doesn't deal with multibyte strings. So, when I convert the Unicode encoded path to a multibyte string (using WideCharToMultiByte), the 0x00E1 gets converted to 0xC3, 0xA1. Apparently fprintf handles this OK (since the stderr messages look correct), but fopen does not.

Other files the app creates in the Documents\FRA4PicoScope directory (PNG plots and CSV data) are OK, because I handle all of that and it's done with full Unicode paths.

It seems like a general problem that PLplot uses fopen in this case - there will be Unicode characters that can't be handled with extended ASCII. But what I might be able to do as a workaround is programmatically change the working directory to the diag directory, then generate the files without fully qualified paths.

zolkow
Advanced
Posts: 0
Joined: Sun Apr 12, 2015 9:36 am
Location: Hungary

Re: Frequency Response Analyzer with Bode Plots

Post by zolkow »

wooohooo! I`ve got diag files!! :D
The amplitude values look strange to me, so no surprise that the dB plot is strange too..
I think we got closer to the solution :wink:

http://basszusmuhely.hu/picoscope/FRAdebug4.zip

hexamer
Advanced User
Advanced User
Posts: 5
Joined: Tue Aug 12, 2014 10:09 pm

Re: Frequency Response Analyzer with Bode Plots

Post by hexamer »

zolkow wrote: I think we got closer to the solution :wink:
I agree! These are not at all what I imagined, so I'm glad we got them. There seems to be some kind of mismatch between timing calculations and buffer size since the data just suddenly stops at about 1/4 of the whole sweep. That's where I'll focus my debugging - I've got some ideas already.

hexamer
Advanced User
Advanced User
Posts: 5
Joined: Tue Aug 12, 2014 10:09 pm

Re: Frequency Response Analyzer with Bode Plots

Post by hexamer »

Here's what I've figured out so far and where I'm stuck:

The fact that the last ~3/4 of the time domain plots look blank is due to an unintentional vector re-size going on in PicoScope::GetData - lines 862-865 in v0.3b. This is also compounded by an incorrect buffer size calculation. It seems to think that scope has 8k samples per channel when it really has half that much. These issues should only affect the time-domain plots. The frequency response calculations are still using the right sample size numbers (e.g. 1954 at the first frequency of ~100 Hz), thus only looking at the data that appears sinusoidal in about the first 1/4 of the graph.

The other thing I notice are that the output frequency looks wrong, like it's about half what it should be - the first clue there is that we should be getting 16 cycles and we only get about 8. If it really is wrong, that would explain the very low amplitudes detected. I've traced out the use of the parameters for frequency, time interval between samples, and number of samples and it looks like they are all correct, thus the graph scale is correct. So it seems that the output frequency really is wrong. The other thing I notice is some jitter in some of the plots. This makes me wonder if somehow I have unintentionally enabled sweeping.

Looking at the documentation for ps2000_set_sig_gen_built_in, I'm honestly not sure I'm using it correctly. The unfortunate thing about that function is that it has parameters that could conceivably interact in surprising ways. E.g. it would be clearer if it had an explicit parameter to enable/disable sweeping. I assumed that by setting the start and stop frequency the same that sweeping would be disabled and thus the increment and dwellTime parameters don't matter, but maybe that's not true.

Edit: The code in the PS2000 console examples sets increment and dwellTime to 0 and the sweepType to PS2000_UPDOWN. I'm not sure if that matters, but we could try to see if that fixes it.

hexamer
Advanced User
Advanced User
Posts: 5
Joined: Tue Aug 12, 2014 10:09 pm

Re: Frequency Response Analyzer with Bode Plots

Post by hexamer »

It turns out that the frequency output was not the problem and that I do have a bug in the timebase calculation - and it literally was a single incorrect constant! I used 50MS/s as the max frequency instead of 100MS/s because I was thinking about the max frequency possible with two channels - d'oh! The timebase calculation in independent of the number of active channels and always uses the scope's maximum possible frequency. That bug probably exists elsewhere in the code, but for now I'll quickly provide you a version to test on your end: https://bitbucket.org/hexamer/fra4picos ... olkow3.zip - this still has all the limitations on time domain plotting you helped me discover.

By the way, don't be surprised if you still see something noisy looking for the simple resistor divider circuit. Since the gain and phase won't vary much, the plotting logic will zoom in on the data and amplify small changes.

Oh ... and those discontinuities (jitter) are another artifact of the time domain plotting issues mentioned earlier and don't affect the FRA. Since the buffer is re-used and the plots show more data than they should, some of the data is just leftover from earlier frequency points.

zolkow
Advanced
Posts: 0
Joined: Sun Apr 12, 2015 9:36 am
Location: Hungary

Re: Frequency Response Analyzer with Bode Plots

Post by zolkow »

Holy cr*p, it works! 8)
Yeah, I found some jitter in the plots, but finally I can use the app to check my preamps' parameters! thanks a lot!
I'm going to check that with some real samples, the resistor divider is a bit boring :wink:

hexamer
Advanced User
Advanced User
Posts: 5
Joined: Tue Aug 12, 2014 10:09 pm

Re: Frequency Response Analyzer with Bode Plots

Post by hexamer »

Great! Thanks for all your help! These fixes will go into a v0.4b, which I'm planning to release in the next week. When that's done, I'll post back here. In the meantime, let me know if your pre-amp measurements look correct.

zolkow
Advanced
Posts: 0
Joined: Sun Apr 12, 2015 9:36 am
Location: Hungary

Re: Frequency Response Analyzer with Bode Plots

Post by zolkow »

I think they look as expected.. great job!

I have some thoughts btw., maybe some of them are relevant only for me, so take these very subjective :)
-I'd like to see a fullscreen option,I like to investigate the plots in high resolution :)
-maybe really only useful for me, but if I could invert one channel's phase... some of my preamps are inverting, some are not. I know that the phase plot's usual drawing method is to jump to the other side of the plot instead of taking a continouos line beyond for example 270 degrees, so it's normal, but sometimes I'd like to see the continouos line.
Instead of inverting also a setting for phase offset could do that: inverting output=+180 degrees, non-inverting= no offset.
-Probably sometimes I would hide the phase plot, just for the cleaner look. (maybe that's already done,I didn't search for that too hard)

Anyway, for me, this tiny scope with this program became a great tool :)
Thanks again!

hexamer
Advanced User
Advanced User
Posts: 5
Joined: Tue Aug 12, 2014 10:09 pm

Re: Frequency Response Analyzer with Bode Plots

Post by hexamer »

Feedback is always appreciated. I understand what you're talking about on the continuity of the phase plot. I had realized at one time that would happen, but haven't been analyzing circuits with phase responses near the +/- 180 degree boundary. I like the idea of having a plot-center phase offset - that would be simple. It might also be simple to implement a "smart" mode that could try to automatically calculate the best plot-center. I'll have to give that some thought. Inverting the phase and hiding the phase plot would be easy too.

In the short term, although less convenient, you can always export the data and plot in another program.

hexamer
Advanced User
Advanced User
Posts: 5
Joined: Tue Aug 12, 2014 10:09 pm

Re: Frequency Response Analyzer with Bode Plots

Post by hexamer »

As I said earlier, I'm posting here to mention that 0.4b is now available:

Update log: https://bitbucket.org/hexamer/fra4picos ... %20History
Download: https://bitbucket.org/hexamer/fra4picos ... 200.4b.msi

Thanks to all those helping with the testing!

zolkow
Advanced
Posts: 0
Joined: Sun Apr 12, 2015 9:36 am
Location: Hungary

Re: Frequency Response Analyzer with Bode Plots

Post by zolkow »

hexamer wrote:As I said earlier, I'm posting here to mention that 0.4b is now available:

Update log: https://bitbucket.org/hexamer/fra4picos ... %20History
Download: https://bitbucket.org/hexamer/fra4picos ... 200.4b.msi

Thanks to all those helping with the testing!
Looks like it's working! :)
The plots look nicer with the wider lines, too.

Post Reply