|

楼主 |
发表于 2024-6-9 00:47:57
|
显示全部楼层
用的 Arduino Goertzel 库,
参考 fsk 的例子做双音识别,失败
- #define A1 PA6
- // Define the ADC midpoint (512 is the default)
- #define ADC_MIDPOINT 512
- // Define the sample rate (8800 S/s is the default for 16 MHz Boards)
- #define SAMPLE_RATE 8800
- // include the Goertzel library
- #include <Goertzel.h>
- // Array buffer for ADC samples
- int Samples[100];
- // Variable for resulting magnitude
- float Mag;
- // Instantiate class for 440 Hz tone detection
- Goertzel f1(697);
- Goertzel f2(770);
- Goertzel f3(852);
- Goertzel f4(941);
- Goertzel f5(1209);
- Goertzel f6(1336);
- Goertzel f7(1477);
- void setup() {
- Serial.begin(115200);
- }
- void loop() {
- int DEPTH = sizeof(Samples) / sizeof(Samples[0]);
- // Get 100 ADC samples from A1 and store them in the buffer
- for (int n = 0; n < DEPTH; n++) {
- Samples[n] = analogRead(A1);
- }
- // Determine the amount of Samples
- char str[]="Num: ",num=0;
- float r1,r2,r3,r4,r5,r6,r7;
- r1 = f1.Mag(Samples, DEPTH);
- r2 = f2.Mag(Samples, DEPTH);
- r3 = f3.Mag(Samples, DEPTH);
- r4 = f4.Mag(Samples, DEPTH);
- r5 = f5.Mag(Samples, DEPTH);
- r6 = f6.Mag(Samples, DEPTH);
- r7 = f7.Mag(Samples, DEPTH);
- if(r5>r1>0){
- num='1';
- }else if(r6>r1>0){
- num='2';
- }else if(r7>r1>0){
- num='3';
- }else if(r5>r2>0){
- num='4';
- }else if(r6>r2>0){
- num='5';
- }else if(r7>r2>0){
- num='6';
- }else if(r5>r3>0){
- num='7';
- }else if(r6>r3>0){
- num='8';
- }else if(r7>r3>0){
- num='9';
- }else if(r5>r4>0){
- num='*';
- }else if(r6>r4>0){
- num='0';
- }else if(r7>r4>0){
- num='#';
- }
- str[sizeof(str)-2]=num;
- // print result to serial
- Serial.println(str);
- }
复制代码 |
|