Skip to content

Commit

Permalink
Some fixes from arduino forums from user El_Supremo
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobrosenthal committed Dec 4, 2013
1 parent d031e6f commit eadc950
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
2 changes: 2 additions & 0 deletions Contributors.md
@@ -0,0 +1,2 @@
@jacobrosenthal
El_Supremo
8 changes: 4 additions & 4 deletions Goertzel.cpp
Expand Up @@ -30,7 +30,7 @@ float Q2;
float sine;
float cosine;

byte testData[160];
int testData[160];

Goertzel::Goertzel(float TARGET_FREQUENCY, float BLOCK)
{
Expand Down Expand Up @@ -71,10 +71,10 @@ void Goertzel::ResetGoertzel(void)


/* Call this routine for every sample. */
void Goertzel::ProcessSample(byte sample)
void Goertzel::ProcessSample(int sample)
{
float Q0;
Q0 = coeff * Q1 - Q2 + (float) sample;
Q0 = coeff * Q1 - Q2 + (float) (sample - 512);
Q2 = Q1;
Q1 = Q0;
}
Expand All @@ -94,7 +94,7 @@ void Goertzel::sample(int sensorPin)
{
for (int index = 0; index < N; index++)
{
testData[index] = (byte) analogRead(sensorPin);
testData[index] = analogRead(sensorPin);
}
}

Expand Down
4 changes: 2 additions & 2 deletions Goertzel.h
Expand Up @@ -12,7 +12,7 @@
simply massaged it into an Arduino library. I recommend reading his article
for a full description of whats going on behind the scenes.
Created by Jacob Rosenthal, June 20, 2012.
See Contributors.md and add yourself for pull requests
Released into the public domain.
*/

Expand All @@ -36,7 +36,7 @@ class Goertzel
// library-accessible "private" interface
private:
void GetRealImag(float*,float*);
void ProcessSample(byte);
void ProcessSample(int);
void ResetGoertzel(void);

};
Expand Down
12 changes: 8 additions & 4 deletions examples/DetectA4/DetectA4.ino
Expand Up @@ -16,18 +16,22 @@
simply massaged it into an Arduino library. I recommend reading his article
for a full description of whats going on behind the scenes.
Created by Jacob Rosenthal, June 20, 2012.
See Contributors.md and add yourself for pull requests
Released into the public domain.
*/
#include <Goertzel.h>

int sensorPin = A0;
int led = 13;

float target_freq=440.0; //must be an integer of 9000/N and be less than

float sampling_freq=8800; //on 16mhz, ~8928.57142857143, on 8mhz ~44444
//But we want clean math so rounding to 8800 for a 4440 example
// with a bucket the size of 20

float target_freq=440.0; //must be an integer of sampling_freq/N and be less than
//sampling_frequency/2 (thanks to Nyquist)
float n=20.0;
float sampling_freq=9000.0;
float n=20.0;

Goertzel goertzel = Goertzel(target_freq,n,sampling_freq);

Expand Down

0 comments on commit eadc950

Please sign in to comment.