Announcement

Collapse
No announcement yet.

Android Phone Based Metal Detector - FCMD

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

  • moodz
    replied
    .. now we will need a broadband coil so we chop the capacitor out of our test coil Leaving us with two coils one at 3.2 mH and the other 2.6 mH ..
    Its likely due to the high inductance that we will only be able to reach 50 Khz ...

    Click image for larger version

Name:	image.png
Views:	314
Size:	1.05 MB
ID:	443502​

    Leave a comment:


  • moodz
    replied
    Android USB v1.0 app completed!
    3 screens main ( detector ) , sweep for profiling and testing, configuration.

    The stm32 board is powered by the phone over usb.

    I did a 50 point sweep from 100 Hz to 99Khz with GB on ... seems to be working like a charm.

    Very little cpu usage on the phone as all the DSP is done in the STM32.


    Click image for larger version

Name:	image.png
Views:	408
Size:	134.5 KB
ID:	443397


    Click image for larger version

Name:	image.png
Views:	409
Size:	128.5 KB
ID:	443399 ​


    ​ Click image for larger version

Name:	image.png
Views:	417
Size:	176.7 KB
ID:	443401
    Attached Files

    Leave a comment:


  • moodz
    replied
    ..well I hit the limitations of the AI. You cant develop a serial port and a USB port using serial over USB aka "CDC" at the same time ... it was just too hard for its conceptual machinery to split the concept of the requirements for a relatively low speed uart and a high speed USB interface using packetised data transfer. Anyway the realtime data needs the speed of the USB port so why compromise ?
    I was interested to see if the ground balance would actually work across 50 frequencies ( it has to GB each separately ) ...it does seem to be working. If it was not I would not get the nice smooth phase curves below.
    Its been said that so many frequencies is overkill but this is as much an experiment as a project. Besides you can use it to do bode plots to test coils etc for resonances or impedance changes.
    The sweep repetition rate is 0.5 hz .... useable for fine descrimination. The fastest sweep rate with two frequency points is 25 sweeps/sec. The default ( bootup ) is 4 frequency points at 12.5 sweeps / sec.

    ... and what is truly amazing is I got to this point without writing / editing a single line of code using a 3 step process.
    1. request
    2. test
    3. goto step 1.

    Click image for larger version

Name:	image.png
Views:	354
Size:	462.8 KB
ID:	443390​

    Leave a comment:


  • moodz
    replied
    Originally posted by cristiano.sar View Post
    Amazing job, thank you for sharing. Is it all on your Github?
    it will be when I can stop the AI fixing things that are already fixed. ( building the android app for the phone ).

    This is the app ( not fully working yet ).

    Click image for larger version

Name:	image.png
Views:	368
Size:	121.5 KB
ID:	443378​

    Leave a comment:


  • cristiano.sar
    replied
    Amazing job, thank you for sharing. Is it all on your Github?

    Leave a comment:


  • moodz
    replied
    Project - Lines of Code Summary

    | Component | Lines |
    |--------------|--------|
    | Firmware (C) | 11,056 |
    | Python GUI | 2,851 |
    | Total | 13,907 |

    Firmware Breakdown (largest files)

    | File | Lines | Purpose |
    |---------------------|-------|----------------------------------------------|
    | main.c | 2,153 | Main loop, CLI commands, initialization |
    | ground_balance.c | 1,231 | Multi-frequency ground balance tracking |
    | adc_dma.c | 745 | ADC sampling, packet building, USB streaming |
    | stm32h7xx_hal_msp.c | 621 | HAL peripheral initialization |
    | uart_packet.c | 599 | UART packet protocol (for VLFDEV) |
    | mf_sweep.c | 492 | Multi-frequency sweep control |
    | target_audio.c | 467 | Audio feedback generation |
    | ground_balance.h | 431 | GB structures and API |
    | dac_nco.c | 408 | NCO sine wave generation |

    Python GUI Breakdown

    | File | Lines | Purpose |
    |------------------|-------|---------------------------------------|
    | stm32_adc_gui.py | 2,186 | PyQt5 GUI with plots, controls |
    | serial_thread.py | 665 | USB CDC communication, packet parsing |


    ⏺ Flash Image Size

    | Section | Size | Description |
    |---------|--------------|--------------------------------------------------------|
    | text | 75,116 bytes | Code + constants (stored in Flash) |
    | data | 416 bytes | Initialized variables (stored in Flash, copied to RAM) |
    | bss | 29,496 bytes | Uninitialized variables (RAM only, not in Flash) |

    Flash usage: 75.5 KB (text + data)

    RAM usage: 29.9 KB (data + bss)

    The STM32H750VB has 128 KB of Flash, so you're using about 59% of available Flash.​

    Leave a comment:


  • moodz
    replied
    Nearly finished

    VLF Metal Detector Theory - Multi-Frequency Ground Balance

    Basic Principle

    A VLF (Very Low Frequency) metal detector works by transmitting a sinusoidal magnetic field and measuring the response from the ground and targets.

    TX Coil -> Magnetic Field -> Target/Ground -> Induced Currents -> Secondary Field -> RX Coil

    Synchronous Detection (IQ Demodulation)

    The received signal is mixed with the transmitted frequency to extract two components:

    - I (In-phase): Component in phase with TX - represents resistive response
    - Q (Quadrature): Component 90° out of phase - represents reactive response

    Signal = I*cos(wt) + Q*sin(wt)

    From I and Q we derive:
    - Amplitude = sqrt(I^2 + Q^2)
    - Phase = atan2(Q, I)

    Why Ground is a Problem

    Mineralized soil contains iron oxides (magnetite, maghemite) that respond to the magnetic field. This ground signal can be 100-1000x stronger than a coin at depth.

    Ground characteristics:
    - Primarily resistive (high I component)
    - Phase typically 0-30 degrees (close to TX phase)
    - Response varies with frequency (dispersive)

    Target characteristics:
    - Non-ferrous metals are primarily reactive (high Q component)
    - Phase typically 60-90 degrees for good conductors
    - Different metals have characteristic phase angles

    Ground Balance by Vector Subtraction

    The key insight: ground response is relatively stable over time, while targets appear and disappear as the coil moves.

    Raw Signal = Ground Vector + Target Vector

    If we know Ground Vector:
    Target Vector = Raw Signal - Ground Vector

    Why Multi-Frequency?

    Ground mineralization is dispersive - its response changes with frequency:

    Frequency Ground Phase Ground Amplitude
    --------- ------------ ----------------
    5 kHz 15 deg 0.8
    10 kHz 18 deg 0.6
    20 kHz 22 deg 0.4
    40 kHz 28 deg 0.3

    Single-frequency GB can only cancel ground at one frequency. Multi-frequency GB tracks the ground vector at each frequency independently, providing better cancellation
    across the spectrum.

    Tracking Ground Balance

    Rather than manual calibration (pumping coil), tracking GB continuously adapts:

    // Exponential moving average
    ground_i = ground_i + alpha * (new_i - ground_i)
    ground_q = ground_q + alpha * (new_q - ground_q)

    Where alpha (tracking_alpha) is small (0.001-0.01) for slow adaptation.

    Motion detection prevents target signals from corrupting the ground estimate:
    - If amplitude changes rapidly -> target detected -> pause tracking
    - Resume tracking after signal stabilizes

    VDI (Visual Discrimination Index)

    Phase angle correlates with target conductivity:

    VDI Range Phase Typical Targets
    --------- ----- ---------------
    -95 to -40 0-20 deg Iron, steel
    -40 to 0 20-40 deg Ferrous, foil
    0 to 40 40-60 deg Nickel, pull tabs, zinc
    40 to 70 60-75 deg Copper, brass
    70 to 95 75-90 deg Silver, large copper

    Multi-frequency improves VDI accuracy by averaging across frequencies and detecting frequency-dependent behavior (ferrous targets show phase reversal at different
    frequencies).

    Ground Severity Index (GSI)

    Quantifies how mineralized the ground is (0-100):

    GSI = f(ground_amplitude, phase_spread, frequency_response)

    - 0-20: Clean ground (beach sand, low mineral)
    - 20-50: Moderate (typical soil)
    - 50-80: Difficult (red clay, black sand)
    - 80-100: Extreme (hot rocks, heavy mineralization)

    Higher GSI means the detector is working harder to reject ground, potentially reducing depth on small targets.

    Signal Flow Summary

    NCO (DAC) -> TX Coil -> Ground/Target -> RX Coil -> ADC
    |
    v
    Sync Detector (I, Q)
    |
    v
    Ground Balance Subtract
    |
    v
    VDI Calculation
    |
    v
    Target ID / Audio
    ​

    Leave a comment:


  • moodz
    replied
    Came to realise that in a multifrequency VLF detector GB has to be done at each frequency. So that means if you say have 10 frequencies then you need 10 tracking GB values.
    The code now supports tracking on 2 - 50 frequencies. The GB is greatly control simplified now ... its either on ( tracking ) or paused ( fixed ). To GB you just pump the coil over the ground and hit the GB reset button and it will track the ground. For fine target resolution the GB is paused. The code also provides a GSI ... ground signal intensity signal from the GB code that tells you what the ground is like. On the waveform display you can see a frequency switch occurring as we use stepped frequency sweep to maintain s/n ratio.

    Click image for larger version

Name:	image.png
Views:	391
Size:	444.7 KB
ID:	443367​

    Leave a comment:


  • moodz
    replied
    Added more sophisticated audio with selectable tone and morse code target ID. The morse code is the first letter of the target type ... eg "I" or "dit dit" for Iron etc. Its surprising but you can recognise the tones much faster than looking at display and reading a moving VDI.
    Some people can read morse at 100 wpm ... not me . I ( and me AI mate ) also added haptic output ... to drive a vibrating target indicator with selectable threshold. Finally added a rotary encoder also for controlling stuff manually for those who like playing with knobs.

    Click image for larger version

Name:	image.png
Views:	363
Size:	124.0 KB
ID:	443358​


    Click image for larger version

Name:	image.png
Views:	425
Size:	496.5 KB
ID:	443357​

    Leave a comment:


  • moodz
    replied
    Performance on a noisy input signal ... the VDI / conductivity vs time shows the stability of the system.

    Click image for larger version

Name:	image.png
Views:	293
Size:	419.8 KB
ID:	443339​

    Leave a comment:


  • moodz
    replied
    All the code to make a VLF detector that can run upto 50 frequencies between 100 Hz and 100 Khz with ground bal and disc has now been built in stm32H750 chip. There is a blue tooth interface to an android app for control and status and a USB interface for looking at the python app below for realtime data. All of the DSP is done in the chip ... the apps just send commands or display data .. no processing. The hardware could concievably fit into a matchbox size.
    Auto and manual groundbalance, selectable frequencies from 1 to 50, phase slope disc, conductivity, VDI etc etc. Once you set the controls the chip will work quite happily without the apps. Target audio comes from the chip.

    Click image for larger version

Name:	image.png
Views:	321
Size:	368.6 KB
ID:	443336​

    Leave a comment:


  • moodz
    replied
    Now building the whole detector in the 750 chip. The android app just runs a GUI over bluetooth to configure the 750 chip and report status but is not necessary anymore for the detector to work. Audio comes straight from the 750 chip.

    GROUND BALANCE :
    Click image for larger version

Name:	image.png
Views:	294
Size:	238.9 KB
ID:	443326

    TARGET TONES

    Click image for larger version

Name:	image.png
Views:	282
Size:	79.9 KB
ID:	443327

    TARGET INDICATION :
    Click image for larger version

Name:	image.png
Views:	265
Size:	87.4 KB
ID:	443328​​​

    Leave a comment:


  • moodz
    replied

    So to answer my own question the "bode mode" sets the detector to transmit a stepped frequency signal or multipoint scan and calculate the phase and amplitude at each point.

    The number of point can be 1 ( as per single frequency detector ) or 2 .... upto 50.
    However because there is only one frequency at any time then the power is maximised and SNR is improved.

    The fastest rate is a two frequency point signal which allows for 25 two point analysis per second. ( unless single frequency operation selected. ).

    | Integration | Rate | 2 pts | 3 pts | 5 pts | 10 pts | 20 pts |
    |----------------|--------|--------|--------|---------|---------|----------|
    | 10ms | 100 Hz | 25.0/s | 16.7/s | 10.0/s | 5.0/s | 2.5/s |
    | 50ms | 20 Hz | 5.0/s | 3.3/s | 2.0/s | 1.0/s | 0.5/s |
    | 100ms | 10 Hz | 2.5/s | 1.7/s | 1.0/s | 0.5/s | 0.25/s |
    | 500ms | 2 Hz | 0.5/s | 0.33/s | 0.2/s | 0.1/s | 0.05/s |

    Formula: sweeps/sec = (sample_rate / integration_samples) / (2 × num_points)

    - Sample rate: 200 kSPS
    - 2 integrations per point (1 settle + 1 measure)

    The IQ integrators can settle to 0.1 degrees and 1 millivolt within 20 milliseconds.

    Below is the system running with 5 frequency points and 10 scans per second.

    ​

    ​Click image for larger version

Name:	image.png
Views:	339
Size:	578.9 KB
ID:	443228​

    Leave a comment:


  • Carl-NC
    commented on 's reply
    Not me, I don't wear glasses.

  • ivconic
    replied
    Kinda reminds a bit on Carl, isn't he?

    Leave a comment:

Working...
X