Goertzel

Hi
First of all, I would like to thank you for great support in my previous thread.
I am trying to implement c code to Arduino IDE, the problem is with serial monitor, it does not shows anything.

Does anyone see the mistake ?

#include <stdio.h>
#include <math.h>
#include <stdlib.h>

#define PI 3.141592653589793
#define SAMPLING_RATE        8000.0        //8kHz
#define TARGET_FREQUENCY        941.0        //941 Hz
#define N        205        //Block size


int sigPin = 0;

float n = 128.0;
int testData[128];

double A1;
double U1;
double U2;
double U0;
double SA0;
double CA0;
double omega;
double step;
double amplitude;
double phasein;
double phaseout;
double sig[N];
double real;
double imag;
//int index;

void setup()
{
  /*
  // 8000 is the sampling frequency
  //   941 is the tone frequency
  omega = 2.0 * PI * 941.0 / 8000.0;
  CA0 = cos(omega);
  SA0 = sin(omega);
  //  A1 = (double) 2.0 * CA0;
  U1 = 0.0;
  U2 = U1;
  step = 941 * (2.0 * PI) / 8000.0;
  phasein = PI / 4.0;
*/
  Serial.begin(115200);
}
void loop() {

  ////////////////////////
  for (char index = 0; index < n; index++)
    for (index = 0; index < N; index++)
    {
      testData[index] = analogRead(sigPin);
    }
  //////////////////////
  for (char index = 0; index < n; index++)
    // for (index = 0; index < N; index++)
  {
    sig[index] = 100.0 * sin(index * step + phasein);


    U0 = sig[index] + A1 * U1 - U2;
    U2 = U1;
    U1 = U0;
  }
  //and iterate over that signal, I end up with the Goertzel

  real = U1 - U2 * CA0;
  imag = U2 * SA0;
  amplitude = (2.0 / (double)N) * sqrt(real * real + imag * imag);
  phaseout = atan2(imag, real);

  Serial.println();
  Serial.print(amplitude);
// return 0;
}

pic.

serial 2.jpg

I am not sure what the title of your post means.

If I were trying to troubleshoot problems with the serial monitor, I would want to test just that.

Try something like this:

void setup() {
Serial.begin(9600);
Serial.println("Hello World!");
}

void loop() {
}

And then use the serial monitor set to 9600

Can you think of a better title for this thread?

What is your theory regarding how this unusual construction is supposed to work?

 for (char index = 0; index < n; index++)
    for (index = 0; index < N; index++)

jremington:
Can you think of a better title for this thread?

What is your theory regarding how this unusual construction is supposed to work?

 for (char index = 0; index < n; index++)

for (index = 0; index < N; index++)

I fixed this = no difference

the problem is with serial monitor, it does not shows anything.

Since the original, posted code does not compile without errors, I'm not surprised.

I'm still interested in what the two improperly nested "for" loops, using the same index, are supposed to do.

But let us worry about that after you post code that DOES compile, with no errors.

With another program is working ok

serial.jpg

Vik321:
With another program is working ok

So, problem solved?

vinceherman:
I am not sure what the title of your post means.

If I were trying to troubleshoot problems with the serial monitor, I would want to test just that.

Try something like this:

void setup() {

Serial.begin(9600);
Serial.println("Hello World!");
}

void loop() {
}




And then use the serial monitor set to 9600

switching the speed is working

AWOL:
So, problem solved?

= Post #8

So, you FINALLY got "Hello World!" to print on the serial monitor?

yes

Good start. Now, you might try using this Goertzel code: GitHub - jacobrosenthal/Goertzel: Arduino Library implementation of the Goertzel algorithm which did work, some years ago.

Since serial is working I see that is my new problem.
I got straight line and no respond to input signal, this part is now activated

    // 8000 is the sampling frequency
    //   941 is the tone frequency
    omega = 2.0 * PI * 941.0 / 8000.0;
    CA0 = cos(omega);
    SA0 = sin(omega);
    //  A1 = (double) 2.0 * CA0;
    U1 = 0.0;
    U2 = U1;
    step = 941 * (2.0 * PI) / 8000.0;
    phasein = PI / 4.0;

Post #5

jremington:
Good start. Now, you might try using this Goertzel code: GitHub - jacobrosenthal/Goertzel: Arduino Library implementation of the Goertzel algorithm which did work, some years ago.

there is no phase measurement there

this is what I have, the right side is growing in numbers, already I have 17700 on scale on the left since last upload , no respond to input.

serial 3.jpg

You complain about "no phase measurement" with someone else's working code, but your code does nothing useful.

Successful approaches start with code that works.

Good luck with your project!

I am not complaining, I did run this program before, that was my first experience with Goertzel,

My impression was that Goertzel is frequency only, no phase, a bit like a DCT.

Good point. The Goertzel Algorithm