I want to know if my code is well written

Okay bro... ill go with my BS question to another platform, but no before learning about the culture....

Because if i dont do that the people there are gonna have their egos hurt...

I just wanted to ask something, but you guys made a big deal out of it. I repeat, if my question was not what you are USED TO just let me know without this big fuss....

pd: your comment about "culture" was very good LOL

If you want to learn how to write the code, people will help you. Start, step by step, for example, write the code which controls AD9833.
ESP32 ADC needs to read 20Hz to 20KHz sweep, from the output of the filter you are testing? If that is the case, ESP32 internal ADC is not adequate.

Look for Teensy mcu .

As what should be an obvious starting point, to accurately capture a 20kHz sine wave for analysis, the A/D sample rate has to be AT LEAST 40kHz, rather than the 10Hz sample rate in the existing code.

And a 200-sample capture buffer is useless for any frequency below 100Hz.

Thanks for your answer!

I have already controlled the ad9833, I have also had success in performing the frequency sweep and I have done my previous research previously.
The idea is to perform a frequency sweep and with each frequency increase read a voltage value at the output of an audio filter, let's say it as follows...

generate a 100hz signal --> read voltage
generate a 200hz signal --> read voltage
generate a 300hz signal --> read voltage
.
.
generate a 1000hz signal --> read voltage
.
generate a 20000hz signal --> read voltage

Therefore, it is not necessary for the ESP32 to have a high sampling speed, since the only thing that must be stable is the signal from the AD9833, the ESP32 only has to read the voltage of the filter output and send it through the serial port. ..

I am using pin 34 of the ESP. And I would like to know if, according to your criteria, you see the code aimed at the case, or if there is something that you would change about the code.

I should not capture a 20khz signal, I should take the voltage value at the output of an audio filter that is fed with that signal... that is...

I must generate a stable signal of (say) 10Khz, give it to the input of a filter, and read the output voltage of that filter...
Therefore, the ESP sampling rate does not need to be 40KHz.

Below I show you a scheme that uses an Arduino instead of an ESP32, but the idea is the same,

Here is something of a "code review."

I am doing a project to graph the frequency response of an audio filter

You code is currently devoid of comments. While there are some theories that say your code should be obvious enough to not need comments in the code itself, you should at least have a header at the top of the file, saying what it does. And your name. And a copyright notice/license.

AD9833 gen(FNC_PIN);

I had to guess that an AD9833 was some sort of function generator, since there was no comment, and "gen" is pretty short for a descriptive name. How about:

   AD9833 funcGen(FNC_PIN);    // AD9833 Function generator on the designated pin

#define Lectura 34

Similarly, I don't know what is on pin34, so another comment would be nice.

int frequencyStep = EndFrequency / vectorLength;

This assumes that StartFrequency is 0. That seems unnecessary and potentially dangerous.


delay(10);

10ms seems a very short time to measure response at audio frequencies. It just won't work at all for frequencies below 200Hz, right (below Nyquist)? That's well within audio range.

10 should be one of the constants you #define at the top of the program. Unless you decide to make it variable depending on the current frequency (which might be a good idea.)


JsonArray jsonArray = doc.to<JsonArray>();

I'm not familiar with the JSON libraries, but they seem like they might be pretty heavy-weight for what you are doing (at least, so far.) For instance, during acquisition, you could store one integer ADC value per frequency...

I would probably implement separate functions for the acquisition of data from the send/print of the data. That would make it easier to change output routines.


This has the usual Serial issues (are lines going to be terminated with "\n", or will it be "\r\n", or something else?

An error message as an else clause would be good (showing the "invalid command.")

the signal should be a sine wave, not a square wave

what is the device measuring the output of the filter?

typically it's an ADC that is sampling the signal, expected to be a sinusoid, and capturing it peak-to-peak amplitude

How`s that?? If you want to measure 20KHz, you need at least 40KHz sample rate.
Why D1 on the input of ADC, you are measuring half wave?

How will A0 ever get lower?
Through the diode it will get higher and higher...

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.