Sinewave with C#

Thread Starter

FBorges22

Joined Sep 11, 2008
109
Greetings,

I am trying to write a program that generates an array to be used in the excel to represent a sinewave signal. The signal should have the following characteristics:

Sampling Rate: 10000
Number of Samples: 2500
Amplitude: 170
Frequency: 60Hz

The image annexed in this post show how the program should works:

And here is the code that is not working as it should be... What is wrong with him?

Rich (BB code):
using System;

namespace Sinewave
{
    class Program
    {
        static double[] data = new double [2500];

        static void Main(string[] args)
        {
            for (int i = 0; i < 2500; i++)
            {
                data = 170 * Math.Sin(2 * Math.PI * 60 * i * 0.00004);
                Console.WriteLine(data.ToString());
            }
        }
    }
}


Thanks,
FBorges22
 

Attachments

peajay

Joined Dec 10, 2005
67
Frequency generation works like this:

Rich (BB code):
for (sample_number = 0; sample_number < number_of_samples; sample_number++) {
  time_in_seconds = sample_number / sample_rate;
  sample = amplitude * sin ( 2 * PI * frequency_in_hz * time_in_seconds );
}
In your code, where you multiply by 0.00004, that's effectively using a sample rate of 25000, which isn't the sample rate that you want.
 
Top