Quantcast
Channel: ADC to sine
Viewing all articles
Browse latest Browse all 16

ADC to sine

$
0
0

Okay, I was thinking about this last night, and think the easiest solution may be to plot the lines using the DrawCurve method of a graphics object. It seems to exhibit good presentation behavior with a sine wave (although it's not 'true' data, of course...):

 

See what you think - as before, paste a timer and a panel. This will plot two lines based off the same dataset:

 

Code Snippet

PublicClass Form1

 

    Private Points As List(Of PointF)

 

    PrivateSub Form1_Load(ByVal sender As System.Object, _

                    ByVal e As System.EventArgs) _

                    HandlesMyBase.Load

        ' Create a new point array

        Points = New List(Of PointF)

        ' Enable the timer

        Timer1.Interval = 500

        Timer1.Enabled = True

    EndSub

 

    PrivateSub Timer1_Tick(ByVal sender As System.Object, _

                    ByVal e As System.EventArgs) _

                    Handles Timer1.Tick

        ' Create a new point to add to the list of points

        Dim p As PointF

        If Points.Count > 0 Then

            p.X = Points.Item(Points.Count - 1).X + 10

        EndIf

        p.Y = Convert.ToSingle(Math.Sin(p.X * 0.1) * 100 + 100)

        ' Add this point to a list

        Points.Add(p)

        Panel1.Invalidate() ' Redraw the panel

    EndSub

 

    PrivateSub Panel1_Paint(ByVal sender As System.Object, _

                    ByVal e As System.Windows.Forms.PaintEventArgs) _

                    Handles Panel1.Paint

        ' Paint the points on the panel

        If Points.Count > 1 Then

            e.Graphics.DrawCurve(Pens.Blue, Points.ToArray)

            e.Graphics.DrawLines(Pens.Black, Points.ToArray)

        EndIf

 

    EndSub

 

EndClass

 

The bold lines are the lines I changed. You can change the 'tension' of the curve with one of the overloaded methods. It depends on your dataset as how it will look. I'd give it a try with multiple datasets and see what it looks like. I exgerated the jaggedness (too few sample points on the sine wave) to demonstrate the difference between the 'lines' and the 'curve'.

 

Note: even with an FFT, you will need to filter it, or you will end up generating signals that aren't there.

 

 


Viewing all articles
Browse latest Browse all 16

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>