Click here to Skip to main content
15,882,152 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Friends, I am Brazilian, sorry if my english has some error. I have a very basic question. 'm Inciante in C #, I would like to know a simple way to plot a graph of sine where through a numeric up down box, I can vary the frequency of the graph. I'm using a panel for this task. Thank you! My email to contact is [Edited away].

Att

Christiano De Carli
Caxias do Sul - Brazil
Posted
Updated 5-Jun-14 1:27am
v2
Comments
S Houghtelin 5-Jun-14 7:23am    
You would do well to remove your email from your post, unless you want a lot of spam. When someone answers your question you will automatically get an email.
ZurdoDev 5-Jun-14 7:24am    
Use the chart control.

You can use your up down box to set the variables in this simple function to generate a sine wave of the desired frequency and sample rate.
C#
class SineGen
{
    public double phaseCnt = 0;     // Sample location in sine wave
    public double sampleRate = 300; // Number samples in one second
    public double freq = 10000;     // Desired frequency, Default set to 10Khz

    /* Simple Sine Wave Generator
     * Make a call to this function for every point
     * in the wave form.
     */
    public double sineWave()
    {
        double result = Math.Sin(freq * (2 * Math.PI) * (phaseCnt) / sampleRate);
        phaseCnt++;
        if (phaseCnt > sampleRate) phaseCnt = 0;
        return result;
    }
}

Within the loop or timer event you can populate a chart control using following lines of code.
C#
mySineWave = _SineGen.sineWave();
this.chart1.Series["SineWave"].Points.AddXY(_SineGen.phaseeCnt, mySineWave);

For more on chart controls see here: ASP.NET 4.0 Chart Control[^]

Good luck.
 
Share this answer
 
 
Share this answer
 
Comments
Christiano De Carli 5-Jun-14 7:39am    
What is Zed Graph? How active this function in Visual Studio?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900