How to use float arrays to store the values

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)

you can define x, y and z as arrays so (running on a Arduino Due)

 float x[1000],y[1000],z[1000];
  for (int i = 0; i < 1000; i++) {
    x[i]= A * sin(wf * t + q);     // fundamental signal
    y[i] = A * sin(wf2 * t + q);    // noise signal
    z[i] = x[i] + y[i];                   // signal embed with noise

what do you wish to do with the information in the arrays?
if you are processing large arrays consider using a raspberry pi which has 1Gbyte of SRAM

Hi Horace

Thank you for the input. I will try the same on the Arduino Uno..

I am trying to write code to implement a bilinear transfer function to filter the signal.

the Arduino UNO only has 2Kbyte of SRAM
each float variable is 32bits so if x, y and z have a 1000 elements each they will require 12Kbytes
I would think a Due which has 96K or SRAM would be more suitable
if you do a web search for ardino due signal processing and ardino due matlab you will get plenty of useful links