Ad Widget

Collapse

Announcement

Collapse
No announcement yet.

Software for performing pickup analysis with a recording interface.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Software for performing pickup analysis with a recording interface.

    This discussion: http://music-electronics-forum.com/t30634/ introduced the idea of using a two channel recording interface as the hardware for a device to measure the impedance of guitar pickups. Commercial software was used to demonstrate the feasibility of the idea. Now I have written software for the task in a platform/hardware independent way and tested it on a mac with my duet 2. It should work on other systems/hardware, although usually there are some glitches in getting something like this fully functional. The language used is python, or actually the ipython/scipy/numpy package that provides free functionality similar to Matlab or IDL. The audio interface is handled by the pyaudio package, which provides an interface to the cross platform portAudio C routines.

    Random 24 bit integers are converted to analog and sent to the test setup. Two 24 bit samples are measured to allow the voltage across and current through the pickup to be measured. Cross spectral analysis is used to determine an answer that is independent of the details of the output waveform.

    This Version 0 works only with 24 bit hardware. Obviously 16 or 32 bit hardware would be easier to support in software since those sizes match native word sizes, but is this necessary? The sampling rate is 44100 Hz; it might be nice to go to 96000, but with the control implemented here, the antialiasing filter on the D/A remains set to 20KHz even when faster sampling is used, and so there is no significant advantage.

    Before describing how to obtain the necessary software and set it up (later post), here is what it does:

    Assuming that ipython is running in a terminal window, here is how to use module pan to measure pickup impedance:

    Load the pickup analysis module, pan.py:

    import pan

    Measure the impedance of a pickup, after connecting it as described in a later post:

    sc1 = pan.imp(pan.d24, 1000)

    d24 is a dicionary containing some parameters controlling the process. 1000 is the requested number of individual sample measurements to average. sc1 is a name assigned to the object for this measurement. This object contains the parameters and results. You can have an indefinite number of measurements (objects) active at once. A plot of the impedance is made. (More on this below)

    The name 'noname' appears on the plot. If you want to keep this data, you should give it a name. It need not be sc1, but could be something longer such as model number/serial number, etc. Here is how to give it a name:

    sc1.pdict['pickup'] = 'sc1'

    or whatever name you want instead of "sc1".
    The dictionary pdict of object sc1 contains many other parameters.

    Now redo the plot so that it appears with the name:

    pan.plotZ(sc1, 20000.)

    (This plot is attached to this post.Click image for larger version

Name:	sc1.png
Views:	1
Size:	84.8 KB
ID:	867996)

    Save the object sc1:

    pan.save(sc1, 'sc1')

    The first argument is the object name; the second is the file name. It can be restored into another python session. (sc1 = pan.restore('sc1')) Measurements are saved in a directory that you specify when you set up pan. (More on this below.)

    The plot can be saved to a file using the right most icon in the lower bar of the plot window.

    Now measure another pickup, with a different object name in order to keep the results of the first for easy comparison. First open another:

    figure(2)

    Then the next measurement is very much like the first:
    (There is a minor bug in this process with a work around described in a later post.)

    hb1 = pan.imp(pan.d24, 1000)

    hb1.pdict['pickup'] = 'hb1'

    pan.plotZ(hb1, 20000.)

    (plot attachedClick image for larger version

Name:	hb1.png
Views:	1
Size:	86.0 KB
ID:	867997)

    pan.save(hb1, 'hb1')

    The blue and red lines on the plots show where the resonance occurs, formally defined as the frequency where the angle crosses zero; this is the same as the imaginary part crossing zero, since it is the tangent of the angle. Lcoil is derived from a linear least squares fit to the very low frequencies of the imaginary part, and Rcoil is derived in a similar way from the real part. The relevant equation for deriving the capacitance, 2*pi*f = 1/sqrt(Lcoil*Rcoil) is not quite accurate enough because of the effects of eddy currents. Thus, a model for eddy currents has been derived and a non linear least squares fit near the peak is used to derive a better value for C. Once C has been derived, it can be removed from the measured impedance, revealing the effects of the eddy currents. If there were no eddy currents, the yellow line would lie on the dashed gray line, and the green line would lie on the dot-dashed gray line.

    It can be seen that the effects of eddy currents on the single coil and the humbucker are different. This is because the conductivity and permeability of steel and alnico are different. There is a way to see a direct comparison, showing just the lower frequencies most important to the sound with this command:

    pan.plotEC(hb1, sc1, 3000.)

    (plot attached Click image for larger version

Name:	sc1hb1EC.png
Views:	1
Size:	65.8 KB
ID:	867998)
    Each impedance is divided by the inductance of the pickup to take out the effect of different overall impedances to facilitate the comparison between the two. You can adjust the upper frequency range as desired.

  • #2
    Getting the software:
    ipython can be obtained here: Installing IPython ? IPython. I am using the Anaconda version; you need to follow the instructions for setting up whichever version you get. The anaconda version comes from pyaudio already installed, at least for the mac, but you can down load that separately if you have to.

    You need to obtain the file pan.py, and edit it to set up a couple of things. First, look at the definition of savepath. You need to change that to a path where you can write files. Second, look at the definition of the dictionary d24. You need to replace the number for Rsense with a measurement you make on your sense resistor. Use the most accurate meter you have. Also, be aware that you might have to change the numbers for scaleFactor, and angle. This is determined by the first measurements you make with the system.

    The hardware:

    The pickup under test is connected in series with a 1K resistor (Rsense). The free end of the resistor goes to ground. Instrument channel 1 connects across the resistor. Channel 2 connects to the free end of the pickup and ground. It is best to make a test jig to make it easier to make changes.

    I set both of gains to zero db. The voltage across the resistor is not large, but there are 24 bits available, and it is not necessary to increase the gain of this channel. When you start the first measurement, make sure that channel 2 is not overloading. If it is, decrease scaleFactor in the definition of dictionary d24. If for some reason you cannot make the gains the same, you can compensate by fudging the value for Rsense that you put into d24. At some point you should measure a 1K resistor. If the imaginary part departs significantly from 0 at high frequencies, change the angle setting in d24.



    From a mac, start the terminal program and type:

    cd anaconda

    ./bin/ipython --pylab

    and then follow the instructions above in the first post in this discussion.

    A bug; On my system, if you change the pickup, the Duet is put in some state from which the pyaudio software cannot recover. You can quit ipython and reenter, but this is not convenient. The Duet comes with software for monitoring/setting values. Doing a rescan fixes the state of the Duet.

    I have attached pan.py as pan.txt. This system does not allow attaching .py files. The file must be put where it can be imported (for example your anaconda directory if you downloaded that version, and the extension must be changed to .py).
    Last edited by Mike Sulzer; 11-26-2013, 12:30 AM. Reason: typo

    Comment


    • #3
      Verifying the operation:

      The results of measuring a 1K resistor should look like the attached plot. If the capacitance of your system differs significantly from mine, then it might not. That is, if the imaginary part departs significantly from 0 at high frequencies, it is necessary to introduce some compensation into the software. This is done by changing the angle setting in d24 until the imaginary part is close to zero at all frequencies.

      How good is the measurement of the effects of eddy currents? To check this, here is a comparison to hb1 and an air core coil. Of course, there is still some level of eddy currents in nearby metal, for example, the ground plane of my jig, and so the effect is not exactly zero.

      Comment


      • #4
        Interesting graphs, Mike. The forum isn't handling your attachments as desired so they are unavailable.
        "Det var helt Texas" is written Nowegian meaning "that's totally Texas." When spoken, it means "that's crazy."

        Comment


        • #5
          Originally posted by salvarsan View Post
          Interesting graphs, Mike. The forum isn't handling your attachments as desired so they are unavailable.
          Thanks. I have no trouble seeing the plots, but the text is marked as invalid. I do not know why; I had no trouble downloading it last night when I tested it.

          I will try again.

          Comment


          • #6
            Here is another attempt to download the text file:

            pan.txt

            The extension must be changed to .py for it to import into Python.

            Comment


            • #7
              It seems to be working now. I can download it into a text editor.

              Comment


              • #8
                A note on eddy currents:

                Predicting the effects of eddy currents as a function of frequency is complicated. That is why the results concerning the effects of eddy currents are measurements to as full extent as possible. In addition to other effects, eddy currents vary with frequency because the skin depth of the conductor changes with frequency. However, the theory used here as a basis for finding the pickup capacitance uses only a narrow frequency range surrounding the resonance. The variation of skin depth is not important over this narrow range. Once the capacitance has been derived, its effect can be removed from the measured impedance, leaving the inductance with its series resistance and the effects of eddy currents. This theory of eddy currents is described here.MutualInductanceLoading.pdf The model used is based on equation 7.

                Comment


                • #9
                  Originally posted by Mike Sulzer View Post
                  A note on eddy currents:

                  Predicting the effects of eddy currents as a function of frequency is complicated. That is why the results concerning the effects of eddy currents are measurements to as full extent as possible. In addition to other effects, eddy currents vary with frequency because the skin depth of the conductor changes with frequency. However, the theory used here as a basis for finding the pickup capacitance uses only a narrow frequency range surrounding the resonance. The variation of skin depth is not important over this narrow range. Once the capacitance has been derived, its effect can be removed from the measured impedance, leaving the inductance with its series resistance and the effects of eddy currents. This theory of eddy currents is described here.[ATTACH]26471[/ATTACH] The model used is based on equation 7.
                  You're right that it's complicated. There is a large literature developed by the NDT (Non Destructive Test) community. The pulsed approach may be simpler to understand and mathematically model.

                  Here is one entry point: Background on Pulsed Eddy Current.

                  Another entry point is the pulse induction metal detector community. The best analyses I've seen were written by the de-mining (to find and remove antipersonnel mines in former war zones) community as they surveyed different mine-detection approaches.

                  One way to test the math is to compare it against a coil with a replaceable core, which can be anything from a copper slug to lead to stainless steel to an alnico rod - can the math predict what the oscilloscope sees when the coil is pulsed. In the past, I used 10 microsecond pulses, so this explores all frequencies from 100 KHz down, and is much faster than a frequency sweep.

                  Another way to test the math is to go to extremes. For instance, what would happen if the core were a superconductor? Compared to air?

                  Tech Editing comments: I had some trouble following the argument, because a coil could be the core or could be the winding, and so on. A better separated nomenclature could help. There are misspelled words on lines 3 and 7 of the first paragraph.

                  Comment


                  • #10
                    Thanks, Joe, I have fixed the typos and changed the terminology to eliminate the use of the word "core" except when referring to an actual transformer core. There term "secondary" now refers to slugs, screws, or other conductors in which current is induced. This agrees with the subscript "s" used in the equations.

                    I do consider extremes in the match, but not explicitly the case where Rse goes to zero (supercoducting(). However, this is the same as the high frequency limit I describe, where omega*Ls is much greater than Rse. In both cases, it is just like adding an inductor in parallel, that is, reducing the inductance. Going to air makes Rse go to infinity, and all effects disappear.



                    Originally posted by Joe Gwinn View Post
                    You're right that it's complicated. There is a large literature developed by the NDT (Non Destructive Test) community. The pulsed approach may be simpler to understand and mathematically model.

                    Here is one entry point: Background on Pulsed Eddy Current.

                    Another entry point is the pulse induction metal detector community. The best analyses I've seen were written by the de-mining (to find and remove antipersonnel mines in former war zones) community as they surveyed different mine-detection approaches.

                    One way to test the math is to compare it against a coil with a replaceable core, which can be anything from a copper slug to lead to stainless steel to an alnico rod - can the math predict what the oscilloscope sees when the coil is pulsed. In the past, I used 10 microsecond pulses, so this explores all frequencies from 100 KHz down, and is much faster than a frequency sweep.

                    Another way to test the math is to go to extremes. For instance, what would happen if the core were a superconductor? Compared to air?

                    Tech Editing comments: I had some trouble following the argument, because a coil could be the core or could be the winding, and so on. A better separated nomenclature could help. There are misspelled words on lines 3 and 7 of the first paragraph.

                    Comment


                    • #11
                      Originally posted by Mike Sulzer View Post
                      Thanks, Joe, I have fixed the typos and changed the terminology to eliminate the use of the word "core" except when referring to an actual transformer core. There term "secondary" now refers to slugs, screws, or other conductors in which current is induced. This agrees with the subscript "s" used in the equations.
                      Good. Is the new version posted? When I went to what's pointed at in prior postings, I got the old version.

                      I do consider extremes in the match, but not explicitly the case where Rse goes to zero (supercoducting(). However, this is the same as the high frequency limit I describe, where omega*Ls is much greater than Rse. In both cases, it is just like adding an inductor in parallel, that is, reducing the inductance. Going to air makes Rse go to infinity, and all effects disappear.
                      OK, but my larger points are that:

                      1) One must validate equations against actual measured values, so it's best to set up a simple and repeatable experiment, like the coil with replaceable cores, so one can both compute and measure, and then compare the results.

                      2) That working out in detail the edge cases, being what happens in the equations when one tries various extremes, can be very instructive.

                      One classic example is the Correspondence Principle: We know that Newtonian Mechanics is correct, but approximate (not handling very high speeds or very small things), so Quantum Mechanics and Relativity must reduce to Newtonian Mechanics when Planck's Constant is set to zero and the speed of light is set to infinity respectively.

                      Correspondence principle - Wikipedia, the free encyclopedia


                      These two are very useful intellectual tools, both for getting to the bottom of something, and for proving that one has done so.

                      Comment


                      • #12
                        Originally posted by Joe Gwinn View Post
                        Good. Is the new version posted? When I went to what's pointed at in prior postings, I got the old version.
                        Sorry, I screwed up again. Here is the new version. MutualInductanceLoading.pdf I have not figured out how to make the old references refer to the new version.

                        Comment


                        • #13
                          Originally posted by Mike Sulzer View Post
                          Sorry, I screwed up again. Here is the new version. [ATTACH]26509[/ATTACH] I have not figured out how to make the old references refer to the new version.
                          That one worked. Thanks.

                          Comments: In general, I now can follow the argument, which seems plausible enough. However, I would cleanly separate the variation of skin depth with frequency from the effect at any specific frequency, because it simply is not true that the eddy current distribution is invariant with frequency (as stated in the first paragraph), which is alluded to in various places. If one applies this assumption inconsistently, trouble will follow.

                          Said another way, the inductance and resistance of the secondary will vary with frequency, because the effective size of the secondary loop will vary with skin depth. Think of the effect if one had a collection of secondaries, all of the same outer diameter, but varying in wire diameter. Both the effective diameter and the loop resistance will vary. See Circular Loop in <http://en.wikipedia.org/wiki/Inductance>.

                          But the effects are separable. If one does multiple analyses, one to a frequency, each such analysis with its own secondary loop (with varying wire diameter), one can then sum these analyses by superposition to yield the overall effect in a form amenable to experimental verification.

                          Tech Editor note: in the last full line of the paragraph after (2), change "It" to "The capacitance". (The justification for ignoring self-capacitance is that the test frequency is low enough - the effect scales by the difference of the squares of the test frequency and the self-resonant frequency.)

                          Comment


                          • #14
                            The analysis I did applies when the current flows in a thin layer. The thickness of this layer can vary with frequency, but as long as it is thin, the analysis is valid; you just have to replace Ls with Ls(f) and Rse with Rse(f). However, if the layer is not thin (and it is not thin if you go to a low enough frequency in something like a humbucker slug), then you need to solve a quite complicated differential equation because you do not know what the current distribution is.

                            Originally posted by Joe Gwinn View Post
                            That one worked. Thanks.

                            Comments: In general, I now can follow the argument, which seems plausible enough. However, I would cleanly separate the variation of skin depth with frequency from the effect at any specific frequency, because it simply is not true that the eddy current distribution is invariant with frequency (as stated in the first paragraph), which is alluded to in various places. If one applies this assumption inconsistently, trouble will follow.

                            Said another way, the inductance and resistance of the secondary will vary with frequency, because the effective size of the secondary loop will vary with skin depth. Think of the effect if one had a collection of secondaries, all of the same outer diameter, but varying in wire diameter. Both the effective diameter and the loop resistance will vary. See Circular Loop in <http://en.wikipedia.org/wiki/Inductance>.

                            But the effects are separable. If one does multiple analyses, one to a frequency, each such analysis with its own secondary loop (with varying wire diameter), one can then sum these analyses by superposition to yield the overall effect in a form amenable to experimental verification.

                            Tech Editor note: in the last full line of the paragraph after (2), change "It" to "The capacitance". (The justification for ignoring self-capacitance is that the test frequency is low enough - the effect scales by the difference of the squares of the test frequency and the self-resonant frequency.)

                            Comment


                            • #15
                              Originally posted by Mike Sulzer View Post
                              The analysis I did applies when the current flows in a thin layer. The thickness of this layer can vary with frequency, but as long as it is thin, the analysis is valid; you just have to replace Ls with Ls(f) and Rse with Rse(f). However, if the layer is not thin (and it is not thin if you go to a low enough frequency in something like a humbucker slug), then you need to solve a quite complicated differential equation because you do not know what the current distribution is.
                              It's true that the relation is not simple to solve the first time, but once one has solved it, the variation with frequency is simple enough, at least to the first order, which is all one usually needs.

                              Comment

                              Working...
                              X