Announcement

Collapse
No announcement yet.

Announcement

Collapse
No announcement yet.

Induction Balance Stuff - Single/Multi Frequency Response, GB, Disc, Measurements, Ideas, Fun, etc.

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

  • Hi all,

    Claude Code delivers now a good solution for the SPLL implementation after I changed the AI query a bit.

    AI query (translated to english):
    Code:
    I have two signals, TX and RX, which are to be digitally demodulated block-wise into I/Q using a lock-in amplifier.
    Use a software PLL (SPLL4) to provide clean references for lock-in demodulation of the RX signal.
    TX and RX signals are digitized using ADC converters with a sample rate of nSR, and the ADC's timebase is coherent.
    TX signal is the reference frequency. The frequency is known and fixed.
    TX signal contains noise (amplitude and phase jitter) and fluctuates.
    Trigonometric functions should be calculated incrementally within the block (phase accumulator) to minimize
    expensive sin()/cos() calls per sample.
    Implement the solution in ANSI C (C89/C90 standard) and create a C library with a header and implementation file.
    Optimize the solution for block processing (nFrameSize). Create a data type (SPLL4) for the demodulator for internal
    variables and resources.
    All floating-point numbers should be typecast to REAL (use double as the default).
    
    Use the following functions:
    - BOOL SPLL4_Init(SPLL4 *pSPLL, long nSR, REAL fFreq)
    Initializes the demodulator with a pointer to the SPLL4 object, where nSR is the sampling rate and fFreq is
    the demodulation frequency.
    
    - BOOL SPLL4_Destroy(SPLL4 *pSPLL)
    Releases all internal resources from the demodulator.
    
    - BOOL SPLL4_Demodulate(SPLL4 *pSPLL, REAL *pTX, REAL *pRX, REAL *pI, *pQ, int nFrameSize)
    Demodulates the real RX signal (pRX) using the real reference TX (pTX) with a sample length of nFrameSize.
    pI and pQ are pointers to the demodulated I/Q of the entire block (nFrameSize).
    
    - BOOL SPLL4_Reset(SPLL4 *pSPLL)
    Resets the demodulator to start a new demodulation.
    
    Use the same names for internal variables as for the function parameters, if possible.
    The function return an error message. If successful, return TRUE, and if failed, return FALSE.
    Always declare local variables at the beginning of the function header (C89/C90 standard).
    Optimize for speed and check your solution for errors. Correct any errors and optimize further.
    Deliver a flawless production version in strict ANSI C (C89/C90 standard) that can be used in real-time systems.​
    This is the 4.th version. All function and data type names are referring to the 4.th version. I am just copying the output and placing it into the .h and .c files without any changes.
    You can find the implementation in the attached zip-file.

    Cheers

    PS: I had to stand up very early to use Claude Code.
    Attached Files
    Last edited by Aziz; 03-02-2026, 06:58 AM.

    Comment


    • Hi all,

      this is the best proof of concept of SPLL I/Q demodulation. I am observing "worms" now and looking where they go.
      The SPLL Lock-in demodulation delivers a much more stable (low drift) and low noise output.
      Whereas the other Lock-in demodulations of TX and RX with an internal reference signal (software) have large drift and noise outputs.

      Look at the "worms" now:

      Click image for larger version

Name:	SPLL-Demod.png
Views:	93
Size:	31.9 KB
ID:	445736

      Cheers

      Comment


      • It looks very good, would it work even if I only have the demodulated signals pI and pQ ? or are pTX and pRX also needed.

        Comment


        • Hi Marcel,

          Originally posted by Marchel View Post
          It looks very good, would it work even if I only have the demodulated signals pI and pQ ? or are pTX and pRX also needed.
          pTX is the reference signal out of the transmit coil signal (tapped with capacitive voltage divider)
          pRX is the receive signal out of the receive coil

          To demodulate I and Q of the RX signal, we need the TX reference signal. The software PLL creates internally a clean and normalized sine and cosine reference, which is locked in into the TX signal for the RX Lock-in demodulation.

          The comparison above shows the demodulated I/Q changes.
          Two demodulated signals (RX=green and TXref=red) use an internaly digital generated demodulation signals (sine/cosine) for the Lock-in demodulation.
          The light green is the software PLL demodulated Lock-in output.

          Comment


          • Originally posted by Aziz View Post
            Hi Marcel,


            pTX is the reference signal out of the transmit coil signal (tapped with capacitive voltage divider)
            pRX is the receive signal out of the receive coil

            To demodulate I and Q of the RX signal, we need the TX reference signal. The software PLL creates internally a clean and normalized sine and cosine reference, which is locked in into the TX signal for the RX Lock-in demodulation.

            The comparison above shows the demodulated I/Q changes.
            Two demodulated signals (RX=green and TXref=red) use an internaly digital generated demodulation signals (sine/cosine) for the Lock-in demodulation.
            The light green is the software PLL demodulated Lock-in output.
            Yes, I now understand how it works exactly, but it's a shame that I can't test it on my device because I don't have the option to get a reference signal with the TX because I would have to modify the entire schematic and PCB.

            Comment


            • Hi friends,

              what's next?
              We need a good tracking algorithm to tame drifting and other issues (temperature gradient caused effects, parasitic capacitance effects and other sources).
              The High-Q transmitter is highly sensitive to these effects.
              Before we can track, we have to detect wether the signal is a target response or something else (noise). A statistics of the finite number of last measurements will tell us, whether we have a target signal.
              This is just a check, whether the last dIQ vectors are collinear. I have put a C library for simple statistics functions in the earlier post.

              We can use the function Stat2D_Update(STAT2D *pStat, REAL fX, REAL fY) over the last dIQ measurements. Set for fX dI and for fY dQ. The fCor variable in STAT2D structure (correlation factor) must be quite high for collinearity (almost 1). The linear regression function y = fRLA*x + fRLB is defined for this case. Any new measurement of dIQ can be checked, whether it lies on the linear regression line function or how much the difference (error or variance) is. So we can decide early about the integrity of the detected signal and feed it into the statistics or dropping it.
              We would require two independent statistics of course:
              - for all dIQ measurements
              - for consistent collinear dIQ measurements (target signal), post-processed target signal without any chatter and false signals.

              And tracking can be made only if there is no target signal (no collinear dIQ signals). And we have the GB part too.
              You see, this is quite tricky and complex.

              Comment


              • Originally posted by Aziz View Post
                Hi all,

                this is the best proof of concept of SPLL I/Q demodulation. I am observing "worms" now and looking where they go.
                The SPLL Lock-in demodulation delivers a much more stable (low drift) and low noise output.
                Whereas the other Lock-in demodulations of TX and RX with an internal reference signal (software) have large drift and noise outputs.

                Look at the "worms" now:

                Click image for larger version  Name:	SPLL-Demod.png Views:	0 Size:	31.9 KB ID:	445736

                Cheers
                Mate if you are getting worms ... you need to go see a doctor .

                The IQ display should be rock solid with no worms.
                Below is what I get out of the h743 board in real time from real targets.

                The green vector is a ferrite target.
                The blue vector is a 10x10 cm foil.
                The red vector is a 5 x 5 cm copper pcb.
                The gold vector ... is a gold ring.

                The only thing I have not done is normalise the phase ( ie I am just using whatever phase the TX is set at ) .....
                The scale is set at 1e7 that is one part in 10 million ... so our sensitivity is around 100 - 150 nanovolts.

                The display is generated by a python script that takes the captured IQ samples and sends them to the PC via the USB interface that is built into the H743 chip.

                Click image for larger version

Name:	image.png
Views:	61
Size:	196.5 KB
ID:	445747

                Comment


                • Hi Paul,

                  I see straight line worms! Everywhere worms! Call the doctor please!

                  Nice plot. I like it. A typical half-space complex/polar plane. A good task for Cayley-Transform.

                  But I don't have a rock-solid digital transmit signal in my sound card. The DAC output goes through an output amplifier and I have both noise sources. This is causing to much noise and drift. And my worms travel around. I wouldn't have these issues with a STM32 board. That's for sure.

                  I have not decided to change to STM32 devs yet. And I would require a permanent and professional Claude Code AI account to make devs fast and efficient. I am just playing around with the AI's and getting some experience.
                  And I am just exploring, what is possible.
                  Particularly, whether we can eliminate the EMI noise induction with TX and RX processing? I have two coils: TX and RX. Both induce EMI noise and target signals. This is quite interesting.
                  Aziz

                  Comment


                  • Originally posted by moodz View Post

                    Mate if you are getting worms ... you need to go see a doctor .

                    The IQ display should be rock solid with no worms.
                    Below is what I get out of the h743 board in real time from real targets.

                    The green vector is a ferrite target.
                    The blue vector is a 10x10 cm foil.
                    The red vector is a 5 x 5 cm copper pcb.
                    The gold vector ... is a gold ring.

                    The only thing I have not done is normalise the phase ( ie I am just using whatever phase the TX is set at ) .....
                    The scale is set at 1e7 that is one part in 10 million ... so our sensitivity is around 100 - 150 nanovolts.

                    The display is generated by a python script that takes the captured IQ samples and sends them to the PC via the USB interface that is built into the H743 chip.

                    Click image for larger version

Name:	image.png
Views:	61
Size:	196.5 KB
ID:	445747
                    This is a very good result, I was wondering if it would be possible to generate the pTX signal using a timer that drives the TX output in IRQ using the sin(); function, or use the timer as a trigger for the DAC and generate pTX using the DAC.

                    Comment


                    • Originally posted by Marchel View Post

                      This is a very good result, I was wondering if it would be possible to generate the pTX signal using a timer that drives the TX output in IRQ using the sin(); function, or use the timer as a trigger for the DAC and generate pTX using the DAC.
                      I just use a timer to generate a square wave and into a resonant coil.

                      Comment


                      • Originally posted by moodz View Post

                        I just use a timer to generate a square wave and into a resonant coil.
                        Yes, I understand that, but I meant to try to generate the pTX signal in a different way, for example so that it does not have to be taken directly from the TX coil by a capacitive voltage divider, but generated in some other way.

                        Comment


                        • Wouldn't it work if you generated a fixed pTX reference signal, for example, this way, and just chose the number of samples and amplitude and just put it in your buffer ?.

                          https://ppelikan.github.io/drlut/

                          Comment


                          • Hi Paul,

                            Originally posted by moodz View Post

                            I just use a timer to generate a square wave and into a resonant coil.
                            are you still using the bipolar rectangular CC TX?
                            Or a true tuned (resonant) TX coil?

                            Comment


                            • Originally posted by Aziz View Post
                              Hi Paul,



                              are you still using the bipolar rectangular CC TX?
                              Or a true tuned (resonant) TX coil?
                              I have a coil for a Minelab Vanquish that uses a square wave signal.

                              Comment


                              • Here is my concept for the STM32H7 metal detector development board, you can download it and view it in KiCad.

                                https://www.geotech1.com/forums/foru...e11#post444779

                                Comment

                                Working...
                                X