Count, measure peak values and average them for finite duration ~ sinusoidal pulse?


Closed Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2009
    Location
    Colorado
    Posts
    378

    Default Count, measure peak values and average them for finite duration ~ sinusoidal pulse?

    I have an application in which I have to use an ADC for input of an analog signal on which an almost sinusoidal pulse of finite duration needs to be measured. Typical pulsed signal is 7-8 cycles (up to 500 Hz) where the peak values are not always equal, so it is close to a sinusoid, but not exactly sinusoidal. I need to use PICBASIC code to sample the analog input at Nyquist (1200 Hz?) with an ADC input to my PIC 12F676 and then count the number of peaks in the waveform, measure each of the peaks, and average the counted peak values. Can anyone give me tips on how to do this...or better yet some example PICBASIC PRO code?

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: Count, measure peak values and average them for finite duration ~ sinusoidal puls

    Hi,
    I'd probably sample at atleast 10 times the input frequency dependning on what else the PIC has to do while doing this thing.

    Here's one idea, from the top of my head, untested....
    Code:
    Sample     VAR WORD
    LastSample VAR WORD
    Average    VAR WORD
    Peaks      VAR WORD [8]
    i          VAR BYTE
    j          VAR BYTE
     
    ' You might want to insert some form of "trigger" mechanism here.
    ' Perhaps sample the input in a loop and wait until there's a 
    ' positive going trend or something - then move on the following:
     
    For i = 0 to 7                    ' Get 8 peaks
     
      LastSample = 0                  ' Set up
      Average = 0                     ' Set up
      Sample = 0                      ' Set up
     
      DO 
         LastSample = Average         ' Save previous sample
         Average = 0                  ' Reset accumulator  
     
         For j = 0 to 3               ' Take 4 samples quickly    
           ADCIN 1, Sample            ' Get current input
           Average = Average + Sample ' Add to accumulator
         Next                         ' Next sample
     
         Average = Average >> 2       ' Divide by 4
      UNTIL Average < LastSample      ' Stop if this sample is lower than the last one.
     
      Peaks[i] = LastSample           ' Current sample is lower than last one, we've found the peak.
     
    NEXT
     
    For i = 0 to 7
      HSEROUT ["Peak number", DEC (i+1), ": ", DEC Peaks[i], " ADC counts", 13]
    Next
    /Henrik.

Members who have read this thread : 2

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts