Show Posts
Pages: 1 ... 70 71 [72] 73 74 ... 110
1066  Using Arduino / Audio / Re: DTMF decoder library on: September 05, 2012, 09:37:17 pm
Quote
The tone length is very strict. If the tone is too short it wont work
How short a tone are you trying? The dialabc example uses 50ms tones. The example code uses a sample length of 128 which means that a sample block is 14 milliseconds long. It should have 3 good blocks in one 50ms tone and might detect tones down to around 30ms - I haven't tried that. You could try making the sample length shorter (try 64) so that the algorithm samples the tone more times. If you do that, you'll have to reduce the threshold amplitude as well.

Quote
and if it plays too long it will put print the number multiple times.
When the code detects a tone it won't return it again until it sees something that is not a tone. If for any reason the amplitude drops a bit to just below the threshold it can think it has seen the end of the tone when there's actually still more to come. Try lowering the threshold amplitude just a bit.

Quote
Is their any chance you could make it modifiable?
Make what modifiable?

Quote
Also, the goertzel algorithm  is supposed to compensate for magnitude on its own.
I saw one implementation which divided the resulting magnitude by the number of samples. I don't know if that's actually part of the Goertzel algorithm itself.
I'll play with it in the next day or so.

Quote
Again, great job and thanks for your help!
You're welcome ;-)

Pete
1067  Using Arduino / Sensors / Re: DSP on: September 05, 2012, 04:26:15 pm
You would almost certainly be better off adding external filtering circuits. A 16MHz Arduino isn't fast enough to do more than very basic filtering. It certainly wouldn't be up to doing an FIR of any reasonable size.
I don't think there are any Arduino DSP libraries anyway.

Pete
1068  Using Arduino / Programming Questions / Re: Goertzel for reliable DTMF Decoding on: September 04, 2012, 08:20:45 pm
See my new post at http://arduino.cc/forum/index.php/topic,121540.0.html

Pete
1069  Using Arduino / Audio / DTMF decoder library on: September 04, 2012, 08:19:22 pm
I have modified the Goertzel algorithm implementation here:
https://github.com/jacobrosenthal/Goertzel
so that it can be used to detect DTMF tones. The new version, like the original, is not interrupt driven.
It is provided AS IS for you to play with.
There are two sample audio files in the zip which, when the windows audio is turned up full, the sample code detects with no errors.
There is also a circuit diagram of how I connected the audio from the computer's headphone output to the Arduino's analog Pin 0. Use at your own risk.
Unzip the attached file into your libraries directory.

Pete
1070  Using Arduino / Programming Questions / Re: Efficient method to split comma-separated values? on: September 04, 2012, 04:03:06 pm
Quote
but about 30 values long
If you have 30 values within < and > then an 80 byte string is too short to hold them all. Assuming that the maximum integer is 4 characters, the whole string can be 152 characters long.
Your code won't blow up if the received string is too long but it throws away everything after the 79th character including the > character, so it won't process the input.



Pete
1071  Using Arduino / Programming Questions / Re: FYI: Exponential Smoothing: on: September 03, 2012, 12:20:49 pm
It works a lot better when alpha is a value like .8 or .9 and then average doesn't need to be initialized to the current ADC value.

Pete
1072  Using Arduino / Programming Questions / Re: Goertzel for reliable DTMF Decoding on: September 02, 2012, 07:50:24 pm
BTW. This, of course, only decodes one tone. To do DTMF it would have to be modified to decode 8 tones and then compare the amplitudes to figure out whether there's a DTMF tone there and if so which one it is.

Pete
1073  Using Arduino / Programming Questions / Re: Goertzel for reliable DTMF Decoding on: September 02, 2012, 07:46:35 pm
I tested it with a slightly modified version of the library which I've attached to this post. I've added code to toggle the output of digital pin 4 so that you can test it yourself. When you do the test, you should modify your code so that it does:
Code:
  while(1)goertzel.sample(sensorPin); //Will take n samples
This will force it to loop in the sample routine all the time, otherwise you won't get an accurate frequency reading. Then whatever frequency you get on your frequency counter, you use double that value as the sampling frequency.
It is best to leave the counter code in there all the time because removing it will speed up the loop a bit which knocks the sampling frequency out of whack again.

Changes to the library:
- added code to initialize and toggle pin 4 so that a frequency counter can be used to determine the sampling rate
- the library was storing the sampled values as bytes - not integers!
- offset the sample by 512 so that the Goertzel algorithm then uses values in the range -512 to 511



Quote
Also I don't believe you can just change the sampling rate without changing "N".
Yes you can. The two values are independent. N determines the bandwidth of the detector. Larger N gives smaller bandwidth. For example with a sampling frequency of 9000 and N=45 the bandwidth will be 200Hz (9000/45). Change N to 90 and the bandwidth will be 100Hz.
NOTE that the maximum value of N allowed by the library is 160. If you exceed that value your sketch will just crash in mysterious ways.

Pete
1074  Using Arduino / Programming Questions / Re: Goertzel or FFT for reliable DTMF Decoding on: September 02, 2012, 06:16:18 pm
I think I have figured out what's happening in that library. As I mentioned, the sampling loop just goes as fast as possible. Your code sets the sampling rate to 9000Hz but I've measured that loop on my Duemilanove with a frequency counter and the loop is more like 8300Hz.
Change your sampling frequency to 8300 and give it a try. On my Arduino it shows a definite peak at 440Hz now.

Pete
1075  Using Arduino / Programming Questions / Re: FYI: Exponential Smoothing: on: September 02, 2012, 11:59:52 am
That doesn't work the way you say. When I read pin A0 on my Duemilanove and print the raw value, it prints 506 or 507, so the average is 506.5.
With your code and an alpha of .01, it takes about two seconds to settle down to 408. This is not even close to the average of 100 readings.

Pete
1076  Using Arduino / Programming Questions / Re: Goertzel or FFT for reliable DTMF Decoding on: September 02, 2012, 10:41:33 am
I tried your code with that library. After fixing a few problems with the library, with code to recognize a 440 Hz tone, it was responding much stronger to tones up around 550z and I couldn't figure out why so I gave up.

Pete
1077  Development / Suggestions for the Arduino Project / Re: Where to report compiler bug? on: September 01, 2012, 05:36:16 pm
Oh rats.

Thanks very much :-)

Pete
1078  Using Arduino / Programming Questions / Re: Goertzel or FFT for reliable DTMF Decoding on: September 01, 2012, 05:09:15 pm
I don't see how that library can possible work. The initialization of the sampling rate, sample size and target tone looks fine. But Goertzel.sample just reads N samples as fast as it can without any attempt to do the sampling at the rate you've specified. It would need to have the correct delay between each sample for this to work.

Pete
1079  Development / Suggestions for the Arduino Project / Where to report compiler bug? on: September 01, 2012, 04:48:42 pm
I ran into a problem with the way that the compiler handles multiplication of integers.
This code:
Code:
void setup(void)
{
  int x,y,z;
 
  Serial.begin(115200);
 
  x = 1024;
  y = 1024;
  z = (x*y)>>14;
  // This prints zero - should be 64
  Serial.println(z);
  z = ((long)x*y)>>14;
  // This prints 64
  Serial.println(z);
while(1); 
}

void loop(void){}
prints:
Quote
0
64

The first print should also be 64 - not zero. (x*y) multiplies 16-bit ints together which produces a long result. C retains this for as long as it can so that the shift operator >>14 will shift the long integer down 14 bits to give a result of 64 but the compiler is apparently converting the intermediate result to a 16-bit int before it should and ths results in zero. The second multiplication "((long)x*y)" explicitly forces the multiply be done as a long and produces the correct result.

The equivalent version of this sketch when compiled using either MSVC or the Cygwin GCC compiler prints 64 for both multiplications as they should.

If you change the sketch to its equivalent form using char instead of int, it gets it right. i.e. this:
Code:
void setup(void)
{
  char x,y,z;
 
  Serial.begin(115200);
 
  x = 64;
  y = 64;
  z = (x*y)>>10;
  // This prints 4
  Serial.println((int)z);
  z = ((int)x*y)>>10;
  // This prints 4
  Serial.println((int)z);
while(1); 
}

prints:
Quote
4
4
The first multiplication involves two 8-bit signed integers and the result is a 16-bit signed integer which is then shifted down before being assigned to an 8-bit integer.

Where do I report this problem?

Pete
1080  Using Arduino / Programming Questions / Re: Goertzel or FFT for reliable DTMF Decoding on: September 01, 2012, 03:45:35 pm
Quote
I'm confused on how to use the FFT Library you linked me to.
For single tone detection stick with Goertzel's algorithm. It's much faster.

Quote
I put an LED between digital 13 and the ground right above it.
Not a good idea. You must have a resistor (220 ohms or higher) in series with the LED otherwise you'll probably damage pin 13 and even the whole Arduino.
But which Arduino are you using? Arduino boards have an LED on Pin 13 anyway.

Quote
Then I plugged the headphone out from my iphone into A0 and ground.
As has been pointed out, this is also not a good idea. You should connect the headphone output through a capactor (about 0.1uF) to the centre of a 1:1 voltage divider. Then the analog input pin is also connected to the centre of the divider. The headphone output should also have a resistor to ground.

Quote
Volume was set at full
You might have been overloading the input and all it was seeing was 1023, 1023, 1023, .....

Quote
Either the LED never triggered or it would trigger in +/-200 range of the target frequency.
Post your code. There's no way to know what's wrong without seeing it - all of it.


Pete


Pages: 1 ... 70 71 [72] 73 74 ... 110