Hi all
I am trying to generate two sine waves using a formula and add them.
I implemented the same in MATLAB (source code and plot attached) and it is working.
I tried to implement the same in arduino uno using C coding and i don't get exactly what i want..
Q1. How to implement the time code as in MATLAB (Please refer to the full program in the attachment)
dt = 1/Fs; % seconds per sample
StopTime = 0.1; % seconds
t = (0:dt:StopTime-dt)'; % seconds
Q2. How to store the float values of the signal in an array ?
The following is my program
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
float Fs = 8000; //sampling frequency
float Fs2 = 8000; //sampling frequency
float A = 3.0; //amplitude
float wf = 10; //frequency
float wf2 = 20; //frequency
float Ts = 0.01; //sampling time
float t = 0.0; //time
float q = 0.0; //phase angle
for (int i = 0; i < 1000; i++) {
float x = A * sin(wf * t + q); // fundamental signal
float y = A * sin(wf2 * t + q); // noise signal
float z = x + y; // signal embed with noise
t = Ts + t;
Serial.print(x);
Serial.print(" ");
Serial.print(y);
Serial.print(" ");
Serial.println(z);
// delay(100);
}
}
sine_wave_addition.txt (1.34 KB)