int F = 2; //frequency of signal
int Fs = 500; //sampling frequency
int n = 500; //number of samples
float t; //time instance
int sampling_interval;
byte samples[500]; //to store the samples
void setup()
{
pinMode(10, OUTPUT);
for (int n=0; n<500; n++){
t = (float)n/Fs; //create time instance to find the 500 samples
samples[n] = (byte)(127*sin(2*3.14*t)+127);
}
sampling_interval = 1000000 / (F * n);
//sampling inverval Ts = 1/frequency x number of sample (Ts = 1/Fn or Ts = T/n)x1000000 to convert to uS
}
void loop()
{
for (int j=0; j<500; j++){
analogWrite(10, samples[j]);
delayMicroseconds(sampling_interval);
}
}
reference:
No comments:
Post a Comment