Tuesday, April 30, 2019

Arduino Neural Net:  A Cook-Coo sound detector:


I created a small neural net along with a FFT in my genuine Arduino UNO for the novelty purpose of detecting a Cook-Coo whistle. 

It is a microphone capacitively coupled to a uni-sided op-amp that feeds the A0 pin of the UNO

The code inside the UNO converts the sound into frequency spectrum and sends the outpt to the Neural network.  The Job of the Neural Network is to decide if the Cook-Coo sound is heard. The UNO then blinks lights if it is a yes.



So there are some issues with the device.  The neural net is very small. It must be small to fit into the Arduino UNO.  The  ATMEGA328P CPU has only 2K of dynamic memory space for Neural net.  I have needed to make this network with only 11 input nodes, 5 hidden nodes and 1 output node.  I have initially divided the input nodes so  that 6 of them correspond to the initial sound (Cook-) and 5 nodes correspond to the final sound (Coo).  However I am now thinking that  there is waste in the first 6 nodes since I focus on the part of the stream that is always shifted to where the FFT output is maximized.  The training for the first 6 input nodes is nearly identical:

   Number:          Input Training vector:                        Expected response to output Node
         0                  Cook-                     Coo
         1                0, 0, 0, 0, 0, 1,       0, 0, 0, 1, 0                  1                         
         2                0, 0, 0, 0, 0, 1,       0, 0, 0, 1, 1                  1
         3                0, 0, 0, 0, 0, 1,       0, 0, 0, 0, 1                  1    
         4                0, 0, 0, 0, 0, 1,       0, 0, 0, 1, 0                  1  
         5                0, 0, 0, 0, 0, 1,       0, 0, 1, 0, 0                  1  
         6                0, 0, 0, 0, 0, 1,       0, 0, 1, 0, 0                  1 
         7                0, 0, 0, 0, 0, 1,       0, 0, 1, 1, 0                  1  
         8                0, 0, 0, 1, 0, 0,       0, 0, 0, 0, 1                  0    
         9                0, 0, 0, 0, 0, 1,       0, 0, 0, 0, 0                  0    
       10                0, 0, 0, 0, 1, 1,       0, 0, 0, 0, 0                  0    
       11                0, 0, 0, 0, 0, 1,       1, 0, 0, 0, 0                  0    
       12                0, 0, 0, 0, 0, 1,       1, 1, 0, 0, 0                  0     
       13                0, 0, 0, 0, 0, 1,       0 ,1, 0, 0, 0                  0    
       14                0, 0, 0, 0, 0, 1,       1, 1, 1, 0, 0                  0     

Note that in every case where the expected result is "1" or true, the first  6 input nodes have always an identical pattern.  Also when the expected result is "0" of false, the first 6 nodes often have the same pattern.   Really the network is focusing on the one and only FFT maximum for the incoming COOK- sound and then around that location looking for a similar but lower COO sound ; but not to low.  Notice that the training data does not focus on a sound that is too high except  test patterns 8 through 10.  These patterns are the only ones that have a different initial 6 input nodes.

Therefore  we can instead almost completely focus our attention on the last COO sound and look both above and below the ith data point that has the FFT maximum.  I think this should give better results.

In addition I accumulated the spectrum data and divided it by the the accumulation value so that I can uncouple the broad spectrum noise and focus on the whistle sound.  The results are much better. Talking noise does not seem to generate false positive results in the neural net.

I have shown this in the following video:

Updated Cook-Coo detector


As always let me know what you think.



No comments:

Post a Comment