Joined: 18 Mar 2010 Posts: 53 Location: Cluj-Napoca
Posted: Fri Mar 08, 2019 12:12 am Post subject: Signal period and DC offset by ADC
Hi
I need to measure a triangular signal with a 10bit ADC and display the DC offset and Frequency (period).
The singnal is mostly symetrical, 5 to 100Hz, aprox. 2.5V DC offset and DC deviation needs to be measured.
I have made a simple simulator in Autoit to test the code that would be inside a 1ms timer interrupt, results in the screen capture.
This is some code (full script is attached, Autoit 3.3.14.2)
$adc=$adc+Random(-$noise_ampl,$noise_ampl,1);add random noise over signal
;----- signal capture an proccessing ----- ;this would be in a 1ms timer interrupt (1Ks/s) $sig_period =$sig_period +1;count period ticks
if$adc>$sig_max then$sig_max =$adc ;max peak detector
if$adc<$sig_min then$sig_min =$adc ;min peak detector
$sig_offset =(($sig_max-$sig_min)/2)+$sig_min ;signal DC offset
if$adc>$sig_offset then;detect "rising" signal
if$sig_dir=0then;signal was "falling" before
$sig_max=$adc ;reset maximum
$sig_avg_offset =($sig_avg_offset +$sig_offset)/2;average DC offset
if$sig_trans_cnt=2then;second transition, full period
$avg_smin=($avg_smin+$sig_min)/2;average minimum
$sig_avg_period=($sig_avg_period+$sig_period)/2;average signal period
ConsoleWrite(@crlf & "! instant period : " & $sig_period & " avg: " & $sig_avg_period) $sig_period=0;reset period counter $sig_trans_cnt=1;reset transition counter
_GraphGDIPlus_Refresh($Graph) endif endif $sig_dir =1;signal is"rising" endif if$adc<$sig_offset then;signal is"falling" if$sig_dir=1then;signal was "raising" before
$sig_min=$adc ;reset minimum
$sig_avg_offset =($sig_avg_offset +$sig_offset)/2;average DC offset
if$sig_trans_cnt=1then;first transition
$sig_trans_cnt=2;next transition
$avg_smax=($avg_smax+$sig_max)/2;average maximum
_GraphGDIPlus_Refresh($Graph) endif endif $sig_dir =0;signal is"falling" endif ;----- draw graph -----
In short a min/max peak detector is implemented, the offset= ((max-min)/2 )+min, signal transitions are detected when signal intersects the offset and by counting two transitions in same direction a period is detected.
Is there a better way of doing this while keeping it low resource/simple ?
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum