1

I have signal with these parameters: 1kHz frequency, 1Vpp. I'm trying to find the best algorithm to calculate the signal's amplitude and frequency from 20 samples. I will try to implement this algorithm in C language (on my microcontroller). I've estimated the sampling frequency to 2.5kHz Pic of sampled sine wave:

Does anyone have an idea? Thanks for help!

Spektre
  • 49,595
  • 11
  • 110
  • 380
Void
  • 23
  • 4
  • 2
    Your best choice seems DCT (discrete cosine transform). As your sample count is low it could be nicely optimized. One drawback will be limited accuracy (for freq) because of low sample count and low sampling rate. – Anty Oct 21 '18 at 11:07
  • @Anty could you elaborate on this a bit? – Void Oct 21 '18 at 11:30

1 Answers1

0
  1. rough estimate

    simply find 2 x (time) positions where y (amplitude) is the same and slope is also in same direction (rise/decline). Their distance T is the period.

    period

    You can increase the precision by handling your data as a polyline (linear or higher interpolation).

    Now amplitude is just A = (max(value)-min(value))/2.

    You can also estimate the initial phase t0 which is x position where data is crossing offset value and offset y0 = 0.5*(max(value)+min(value)) Beware y0 might be anything not just zero ...

    So your sinwave is done like:

    y(t) = y0 + 0.5*A*sin((t-t0)*2.0*M_PI/T)
    
  2. precision

    if you need much better precision then just fit a sinwave through your points. As you got already the initial estimates then this is not so slow as a blind fit. Here an example:

Spektre
  • 49,595
  • 11
  • 110
  • 380
  • 1
    `A = (max - min)/2` – Zaz Feb 12 '19 at 17:01
  • @Zaz yes for un-biased sin wave you're right I edited the answer ... In different circumstances it depends on the definition/meaning of amplitude for the task ahead – Spektre Feb 28 '19 at 14:17