Frequency Response Analyzer with Bode Plots

Post discussions on applications you are writing
Post Reply
Martyn
Site Admin
Site Admin
Posts: 3507
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: Frequency Response Analyzer with Bode Plots

Post by Martyn » Mon Feb 11, 2019 8:09 am

Thank you for this.
Not sure why you were unable to post the files, the file limit is at least 10Mb, so I have added them
Attachments
ImpedanceViewer1002.zip
(424.95 KiB) Downloaded 29 times
Martyn
Technical Support Manager

_Wim_
Advanced
Posts: 0
Joined: Sun Nov 12, 2017 11:31 am

Re: Frequency Response Analyzer with Bode Plots

Post by _Wim_ » Mon Feb 11, 2019 8:16 am

Thanks for uploading the file here also. For me, the file limit was/is limited to 256K?! Could this be related to the number of post? Just tried again to upload a dummy file of 5mB, could not attach it..

_Wim_
Advanced
Posts: 0
Joined: Sun Nov 12, 2017 11:31 am

Re: Frequency Response Analyzer with Bode Plots

Post by _Wim_ » Mon Feb 11, 2019 7:57 pm

Full source code is available at:
https://github.com/WimHuyghe/FRA-Impedance-Viewer

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

Re: Frequency Response Analyzer with Bode Plots

Post by hexamer » Thu Feb 14, 2019 4:22 am

_Wim_ wrote:
Mon Feb 11, 2019 7:57 pm
Full source code is available at:
https://github.com/WimHuyghe/FRA-Impedance-Viewer
Very nice work, Wim! I'll have to try this our soon.

BTW, this is one of the kinds of application I had in mind when I made the API version of FRA4PicoScope. Had you considered integrating it that way? Should be pretty easy with C#.

_Wim_
Advanced
Posts: 0
Joined: Sun Nov 12, 2017 11:31 am

Re: Frequency Response Analyzer with Bode Plots

Post by _Wim_ » Thu Feb 14, 2019 6:44 pm

Hi Hexamer,

Thanks for your comments. I was not aware an API version of your app was available. I will definitely look into that. I briefly first considered changing your app, but as I am not a C++ guy, and also not familiar with the PLPlot lib, that seemed a bit too much work. Wrapping a dll and using it in C# however should be fairly straight forward.

_Wim_
Advanced
Posts: 0
Joined: Sun Nov 12, 2017 11:31 am

Re: Frequency Response Analyzer with Bode Plots

Post by _Wim_ » Sun Feb 24, 2019 12:57 pm

Hi Hexamer,

I have a basic version working with your API (I can perform the measurement from my app), but I am strugling with the GetMessageLog() function. Depending on timing when I call the GetMessageLog(), I get one of the following reactions:
- message is returned correctly
- message contains random characters
- API crashes with no clear exeption.
all with the same code.

Currently I am invoking your API function as follows:

[DllImport("FRA4PicoScope.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
public static extern string GetMessageLog();

I also tried returning an IntPtr instead of a string, and using the function below to convert it to a managed string:

private string GetStringFromPtr (IntPtr pptr)
{
IntPtr ptr = Marshal.ReadIntPtr(pptr);
return Marshal.PtrToStringUni(ptr);
}

I also tried adding [return: MarshalAs(UnmanagedType.LPWStr)] to the DLLImport. So far nothing works reliable.

Any tips?
Attachments
MessageLog.PNG

_Wim_
Advanced
Posts: 0
Joined: Sun Nov 12, 2017 11:31 am

Re: Frequency Response Analyzer with Bode Plots

Post by _Wim_ » Tue Feb 26, 2019 10:04 am

Attached a version with a basic user interface to control the picoscope directly. As posted above, reading the status log does not work yet, but is default disabled in the app. Source code is on Github
Attachments
ImpedanceViewer1006.zip
(565.57 KiB) Downloaded 2 times

kaimex
Newbie
Posts: 0
Joined: Tue Feb 26, 2019 4:29 pm

Re: Frequency Response Analyzer with Bode Plots

Post by kaimex » Tue Feb 26, 2019 5:17 pm

Hi,
I am using a PicoScope 2204A with FRA4PicoScope V. 0.6.2b.RC4, assuming that it is the newest version.
In recent weeks I have used this for impedance measurement on capacitors and inductances in the range 1 Hz to 100 kHz. The setup is apparently the same as the one posted by _Wim_ on Feb 10, 2019, but I only saw this about half an hour ago.
In the course of these measurements I noticed, that there are reproducable irregularities in the impedance versus frequency plots, especially pronounced in the real part of the impedance or e.g. in the dissipation factor (tan(delta)). These irregularities come from errors in the phase measurement of FRA4PicoScope, which vary with frequency. I have provided illustrations of this effect in the form of plots. The postprocessing is presently done with a MatLab-Script but could likewise be done with Octave (requiring possibly minor changes in the graphics).
In the beginning I used FRA4PicoScope with the default settings. Later I found that the phase ripple can be reduced by setting the "Extra settling time" parameter to 25 , in some case also to values as high as 50, 100, 200. Experimenting with the "Minimum cycles parameter" brought further improvement by increasing from the default 16 to 28 or 30. From 32 on the program complains that this is not compatible with a start frequency of 10 Hz. I have not found documentation about these parameters, so this was the result of experimentation.
Sometimes these settings lead to smooth result curves, at other "times" the plots still show bumps that cannot be explained by the DUT-properties. So my impression is, that there is some potential of improvement in the implemented phase calculation method.
The attached example has been produced with a 1 kOhm resistor between inputs A & B, the AWG connected to A and the DUT was a 10 uF capacitor from B to ground. I used 200 Steps/decade for this demonsration ( otherwise only 20 steps/decade).
Regards Kai
Attachments
PhaseRippleTest1.png

_Wim_
Advanced
Posts: 0
Joined: Sun Nov 12, 2017 11:31 am

Re: Frequency Response Analyzer with Bode Plots

Post by _Wim_ » Tue Feb 26, 2019 7:27 pm

Hi Hexamer,

I solved the problem of returning the message log. I declared the P/Invoke to return and InPtr, and converted this InPtr using Marshal.PtrToStringUni(ptr) directly instead of calling Marshal.ReadIntPtr(pptr) first as I found in interop examples. Now it works perfectly, and I learned a bit more about using interop :-)

_Wim_
Advanced
Posts: 0
Joined: Sun Nov 12, 2017 11:31 am

Re: Frequency Response Analyzer with Bode Plots

Post by _Wim_ » Tue Feb 26, 2019 9:18 pm

Updated version with the fixed message log.
Attachments
ImpedanceViewer1007.zip
(545.22 KiB) Downloaded 3 times

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

Re: Frequency Response Analyzer with Bode Plots

Post by hexamer » Tue Feb 26, 2019 11:36 pm

_Wim_ wrote:
Tue Feb 26, 2019 7:27 pm
Hi Hexamer,

I solved the problem of returning the message log. I declared the P/Invoke to return and InPtr, and converted this InPtr using Marshal.PtrToStringUni(ptr) directly instead of calling Marshal.ReadIntPtr(pptr) first as I found in interop examples. Now it works perfectly, and I learned a bit more about using interop :-)
Very happy you figured this out. I was going to have to dig very deep into the memory banks to help out. It's been a long while since I've P/Invoked a DLL from C# :)

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

Re: Frequency Response Analyzer with Bode Plots

Post by hexamer » Thu Feb 28, 2019 1:44 am

Kai,

Your results are a bit perplexing. I would like to see if I can reproduce them. Your description should help. Here is what I can tell you for now:

A primary reason for the extra settling time is that the Picoscope's AWG transition has discontinuities which can affect measurement. I'd be curious to see if taking it to an extreme would eliminate the issue here.

The number of cycles collected affects how many scope samples are collected. It's the number of whole stimulus cycles to collect. Total samples are this times samples per cycle. More samples will lead to more processing gain which can be important in noisy environments (simple impedance measurements of passive components are not generally noisy).

The phase measurement is done with a DFT, and though it is using a more efficient version (Goertzel), it should be mathematically equivalent. It is using double precision arithmetic, and in your use case (low DFT sample count) should not be suffering any numerical accuracy issues. But as a DFT it would have all the associated limitations like spectral leakage. But since the application maintains an integer stimulus cycle count for sampling and noise is presumed low, I doubt this is the issue here.

Edit: thinking about it a bit further ... I suppose the AWG discontinuities could be a noise source that shows up as a spectral leakage. That could be helped by both eliminating the noise (increasing settling time) or increasing processing gain (increases cycles and cycles/sample). The scalloping in your data seems to support that idea.

Thanks,

Aaron.

_Wim_
Advanced
Posts: 0
Joined: Sun Nov 12, 2017 11:31 am

Re: Frequency Response Analyzer with Bode Plots

Post by _Wim_ » Thu Feb 28, 2019 8:17 pm

kaimex wrote:
Tue Feb 26, 2019 5:17 pm
Hi,
I am using a PicoScope 2204A with FRA4PicoScope V. 0.6.2b.RC4, assuming that it is the newest version.
In recent weeks I have used this for impedance measurement on capacitors and inductances in the range 1 Hz to 100 kHz. The setup is apparently the same as the one posted by _Wim_ on Feb 10, 2019, but I only saw this about half an hour ago.
In the course of these measurements I noticed, that there are reproducable irregularities in the impedance versus frequency plots, especially pronounced in the real part of the impedance or e.g. in the dissipation factor (tan(delta)). These irregularities come from errors in the phase measurement of FRA4PicoScope, which vary with frequency. I have provided illustrations of this effect in the form of plots. The postprocessing is presently done with a MatLab-Script but could likewise be done with Octave (requiring possibly minor changes in the graphics).
In the beginning I used FRA4PicoScope with the default settings. Later I found that the phase ripple can be reduced by setting the "Extra settling time" parameter to 25 , in some case also to values as high as 50, 100, 200. Experimenting with the "Minimum cycles parameter" brought further improvement by increasing from the default 16 to 28 or 30. From 32 on the program complains that this is not compatible with a start frequency of 10 Hz. I have not found documentation about these parameters, so this was the result of experimentation.
Sometimes these settings lead to smooth result curves, at other "times" the plots still show bumps that cannot be explained by the DUT-properties. So my impression is, that there is some potential of improvement in the implemented phase calculation method.
The attached example has been produced with a 1 kOhm resistor between inputs A & B, the AWG connected to A and the DUT was a 10 uF capacitor from B to ground. I used 200 Steps/decade for this demonsration ( otherwise only 20 steps/decade).
Regards Kai
Hi Kai,

I am probably misunderstanding, but ss the Z the impendance of the DUT only in your plot? Because normally for a 10µF capacitor this should be around 1600 for 10Hz, and around 8 ohm at 2kHz.

Attached it the impendanc plot I get running the same test. No matter how much I zoom in, I do not see any ripples.
Attachments
Imedance 10µF.png

_Wim_
Advanced
Posts: 0
Joined: Sun Nov 12, 2017 11:31 am

Re: Frequency Response Analyzer with Bode Plots

Post by _Wim_ » Thu Feb 28, 2019 9:06 pm

New version:

Bugfix:
- was not possible any longer to open multiple FRA4Pico plots (was always opening new plot).

Other changes:
- cursor info always same nr of lines (so chart does not move when right mouse button is used)
- pompt on exit when unsaved files are present
Attachments
ImpedanceViewer1008.zip
(530.99 KiB) Downloaded 3 times

kaimex
Newbie
Posts: 0
Joined: Tue Feb 26, 2019 4:29 pm

Re: Frequency Response Analyzer with Bode Plots

Post by kaimex » Sat Mar 02, 2019 1:50 pm

Hi Aaron and Wim,
thank You for responding to my message.
Wim: the left end of my plot starts at 40 Hz, so 10 µF -> ~ -j400 Ohms and I guess I was not mistaken. when I tried to remember the nominal capacitance value of the test candidate.
Normally I make more broadband plots from e.g. 10 Hz to 20 kHz with only 20 steps/decade. Then the plots look more irregular and you don't realize the periodicity of the underlying phase error.
This plot was done with the default settings (no extra settling time; minimum cycles captured = 16). I also made plots with extra settling time set to 25ms, 30ms, 40ms, 50ms, which showed much less but apparently not yet random ripple. 50ms seemed to have more ripple than 25ms. Later I noticed/explored that increasing the minimum cycles number led to further improvement of the smoothness of the traces. In my opinion (without fully understanding, what the software does in detail) it should however be possible to reduce the systematic phase errors by a better calculation method without using the settling time and minimum cycles parameters. The FFT phase result is always depending on how much signal cycles fit into the time intervall. The phase error is zero, when an integer number fits exactly in. It is totally predictable, when non-integer numbers of cycles are in the intervall. But you can put this in different terms: it is possible to calculate phase exactly by using the proper mathematics (and not just the FFT result).
One method might be to fit a sine/cosine to the sample-vector with least squares methods, if no direct or easily invertible analytical solution can be found. It should be possible to improve the phase calculation to a level, that the residual errors look like random or quantization noise.
Regards Kai

Post Reply