element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Upcycle It
  • Challenges & Projects
  • Design Challenges
  • Upcycle It
  • More
  • Cancel
Upcycle It
Blog [Upcycle It] WiFi Connected Smoke Detector #10: Addressing False Positives
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: vlasov01
  • Date Created: 29 May 2017 2:11 AM Date Created
  • Views 2040 views
  • Likes 3 likes
  • Comments 11 comments
  • false positives
Related
Recommended

[Upcycle It] WiFi Connected Smoke Detector #10: Addressing False Positives

vlasov01
vlasov01
29 May 2017
<<Previous

Project Index

Next >>

 

Nobody likes false positives

 

I don't like them too, especially where I have control and can address them. I had two cases in the past 10 days when my connected smoke detector generated false positives. So I decided to address them.

 

Options: Neural networks vs. traditional approach

 

I was doing some machine learning courses in the past and have some ideas how to apply neural networks (NN) for sound detection. NN is the most popular way to recognize voice. But with all advantages of NN it is still considered a "black box" approach.

Alternatively I've collected statistics from the detector logs by using system journal.

journalctl -b|grep node|grep above >/tmp/logs.csv

 

Then I looked in the log at times when alarm was raised (value of the counter above 50).

 

May 18 18:09:31 gate1 node[306]: Above threshold 489 counter 10
May 18 18:09:31 gate1 node[306]: Above threshold 497 counter 18
May 18 18:09:31 gate1 node[306]: Above threshold 492 counter 26
May 18 18:09:32 gate1 node[306]: Above threshold 488 counter 36
May 18 18:09:32 gate1 node[306]: Above threshold 487 counter 44
May 18 18:09:32 gate1 node[306]: Above threshold 488 counter 52

 

May 20 22:56:20 gate1 node[306]: Above treashold 478 counter 10
May 20 22:56:21 gate1 node[306]: Above treashold 485 counter 17
May 20 22:56:21 gate1 node[306]: Above treashold 493 counter 23
May 20 22:56:21 gate1 node[306]: Above treashold 485 counter 32
May 20 22:56:23 gate1 node[306]: Above treashold 486 counter 28
May 20 22:56:23 gate1 node[306]: Above treashold 492 counter 37
May 20 22:56:23 gate1 node[306]: Above treashold 489 counter 46
May 20 22:56:24 gate1 node[306]: Above treashold 492 counter 53

 

The log file only contains entries when the microphone captures a loud signal above predefined threshold, which is now defined as 470. The signal gets measured every 100 ms. If the signal above 470 the counter get increased by 10. If it is below 470, it gets decreased by 1 while its value is above 0. And when the counter is above 50 it is raising alarm, Here is the code of my audio processing function in Node.js:

 

function processAudio(){
  // read the value to start off
  var level = audio.read();

  // If the sound is higher than the threshold, make the request
  if(level >= threshold){
    audioCounter=audioCounter+10;
    console.log('Above threshold ' + level + ' counter ' + audioCounter);
    if(audioCounter>50){
        state = true;
        setTimeout(processAudio, 60*1000); //wait 60 seconds before activating it again
        client.publish(kitchen_alarm_state_topic, 'true', {qos: 2, retain: true}, function() {
            console.log('Audio alarm detected ' + level + ' counter ' + audioCounter);
        });
        audioCounter=0; //reset counter
    }
    else {
        setTimeout(processAudio, 100);
    }
  } else {
    if(audioCounter>0){
        audioCounter--;
    }else if(state){
        state = false; //switch off alarm
        client.publish(kitchen_alarm_state_topic, 'false', {qos: 2, retain: true}, function() {
            console.log('Audio alarm switched off ' + level + ' counter ' + audioCounter);
        });
    }
    setTimeout(processAudio, 100);
    //console.log(level + ' counter ' + audioCounter);
  }
}

 

In both cases of false positives value of the counter was 52 and 53. So I've changed the threshold to be just above these values and set it to 53 instead of 50 (line 9).

I've pushed the code, restarted the detector service and verified its status after restart.

root@gate1:~# sudo systemctl restart smoke-detector
root@gate1:~# sudo systemctl status smoke-detector
● smoke-detector.service - SmokeDetectorApp
   Loaded: loaded (/lib/systemd/system/smoke-detector.service; enabled)
   Active: active (running) since Sun 2017-05-28 22:06:03 EDT; 9s ago
 Main PID: 5603 (node)
   CGroup: /system.slice/smoke-detector.service
           └─5603 /usr/bin/node /home/root/detector.js

May 28 22:06:03 gate1 systemd[1]: Started SmokeDetectorApp.
May 28 22:06:06 gate1 node[5603]: /home/root/node_modules/mraa/build/Release/mraa.node
May 28 22:06:06 gate1 libmraa[5603]: libmraa version v1.6.1 initialised by user 'root' with EUID 0
May 28 22:06:06 gate1 libmraa[5603]: edison: Arduino board detected
May 28 22:06:06 gate1 libmraa[5603]: libmraa initialised for platform 'Intel Edison' of type 2
May 28 22:06:06 gate1 node[5603]: MRAA Version: v1.6.1
May 28 22:06:06 gate1 node[5603]: Kitchen alarms detector connected

 

I'll keep looking to see if false positive will reappear again. But in this case it seems the simple approach of adjusting thresholds based on statistical data is good enough.

  • Sign in to reply

Top Comments

  • vlasov01
    vlasov01 over 8 years ago in reply to mcb1 +2
    It allows to have a time perspective. It will take a 10 measurements over 1 second without any loud sounds to completely negate one that is above threshold. A smoke alarm generates sound with some constant…
  • Workshopshed
    Workshopshed over 8 years ago +1
    >If the signal above 470 the counter get increased by 10. If it is below 470, it gets decreased by 1 while its value is above 0. How about a simple hysteresis ? That should help detect a continually loud…
  • DAB
    DAB over 8 years ago in reply to mcb1 +1
    I too used to laugh until I finally understood that it was a very useful way to combine a state machine with more flexible detection points. The result is a system that smoothly transitions states without…
Parents
  • DAB
    DAB over 8 years ago

    Nice update.

     

    Now you are beginning to understand why many systems have gone to fuzzy logic.

    Binary decision points are great in absolute environments, but not so good for real world applications.

     

    Fuzzy logic permits you to enter multiple levels of decision making using different levels of analysis depending upon all of the available data and system state.

     

    So far, the results of using these Fuzzy decision point algorithms have proven to be very useful in these types of applications.

     

    DAB

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • mcb1
    mcb1 over 8 years ago in reply to DAB

    fuzzy logic

    I always laughed at this term ... and still do when used with microcontrollers or even discrete chips.

     

    It's still a decision (or not), what changes is the threshold around the decision.

    In some respects vlasov01 has created that with his +10 and -1 approach.

     

    It's a bit late now, but I have a nice circuit we used to adjust the gain of a microphone stage used to detect the bass.

    It involved a diode and capacitor to effectively alter the gain in relation to the ambient noise level, and then filter out the bass component to drive the controller.

    I never sat down and measured the range since it worked so well in practice.

     

    Mark

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Comment
  • mcb1
    mcb1 over 8 years ago in reply to DAB

    fuzzy logic

    I always laughed at this term ... and still do when used with microcontrollers or even discrete chips.

     

    It's still a decision (or not), what changes is the threshold around the decision.

    In some respects vlasov01 has created that with his +10 and -1 approach.

     

    It's a bit late now, but I have a nice circuit we used to adjust the gain of a microphone stage used to detect the bass.

    It involved a diode and capacitor to effectively alter the gain in relation to the ambient noise level, and then filter out the bass component to drive the controller.

    I never sat down and measured the range since it worked so well in practice.

     

    Mark

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
  • DAB
    DAB over 8 years ago in reply to mcb1

    I too used to laugh until I finally understood that it was a very useful way to combine a state machine with more flexible detection points.

     

    The result is a system that smoothly transitions states without binary decision states that always results in confused responses.

     

    So If you have questions about how to use Fuzzy Logic usefully, let me know.  I have found it very useful, even in simple systems.

     

    DAB

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • vlasov01
    vlasov01 over 8 years ago in reply to DAB

    DAB It will be great if you can point to some resources that can help to pickup application of the fuzzy logic in this domain of sensing and control.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • DAB
    DAB over 8 years ago in reply to vlasov01

    Unfortunately, I have been out of this business for over 15 years.

    I am sure that a few web searches will provide you with many current technology views.

     

    Feel free to provide me with questions about what you find and how you might exploit it.

     

    DB

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • vlasov01
    vlasov01 over 8 years ago in reply to DAB

    Thank you a lot for your offer!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube