[HN Gopher] Fire alarm audio detection, using FFTs and Go
       ___________________________________________________________________
        
       Fire alarm audio detection, using FFTs and Go
        
       Author : pdubouilh
       Score  : 30 points
       Date   : 2024-04-07 12:08 UTC (10 hours ago)
        
 (HTM) web link (github.com)
 (TXT) w3m dump (github.com)
        
       | yesimahuman wrote:
       | Funny, I was just thinking about building something like this
       | since I bought a z-wave smoke alarm listener and it does not work
       | with my first alert system and it really annoys me. It can't be
       | that hard, right? Even something that just detects extremely loud
       | sounds would be useful despite false positives
        
         | pdubouilh wrote:
         | I was in a similar situation, and it turns out that setting up
         | new zigbee devices with zigbee2mqtt and a frontend was more
         | work than just detecting the sound pattern with a few lines of
         | Go ! Plus the fire-alarms are compulsory and already installed
         | and managed by my building...
        
           | BrandoElFollito wrote:
           | After a few years using Z2M I moved to the native ZHA. It
           | detects devices better in my case.
           | 
           | Device detection is a nightmare in Zigbee, I wish they made
           | it more robust, predictable, ...
        
       | beefnugs wrote:
       | Just solder a wire in there somewhere. Even if you knew
       | absolutely nothing about electronics, 50 trial and error solder
       | points sounds like less work.
        
         | ashleyn wrote:
         | These projects exist because modding life-critical safety
         | equipment is usually not the best idea. You invalidate the
         | testing originally put into the product, and it may fail when
         | you most need it.
        
           | wongarsu wrote:
           | Then put up two fire alarms, one unmodified and one where you
           | replace the speaker with an Arduino that does whatever you
           | want with the signal. They only cost $10 a piece. Or I guess
           | buy one with wifi or zigbee connectivity, but then you don't
           | have a project anymore.
        
           | morpheuskafka wrote:
           | Yeah, everything that touches them needs to be UL listed.
           | Commercial alarm panels have approved relay modules that can
           | be used to output to various unregulated devices without
           | affecting the electronics inside the panel for this reason.
           | They also use cellular now and have to use a special modem
           | that is UL-listed to connect.
        
         | pdubouilh wrote:
         | I agree ! But I have a few fire alarms, and 2 water leak
         | alarms, that would be a lot of wires lying around, and this
         | solution is wireless :)
        
         | gosub100 wrote:
         | Then what? Run 50-200 feet of wire back to an Arduino? Or buy
         | an Arduino and provision it for every smoke detector in the
         | house? How do you power them? Another wall wart?
         | 
         | If audio fingerprinting can identify Miley Cyrus in background
         | noise in a crowded bar, certainly it can identify the
         | symmetrical piercing monotone of an alarm.
        
         | Spivak wrote:
         | Agreed, I have no idea what the sibling comments are on about
         | with safety. A binary sensor reading the wire going to the
         | speaker isn't some magic modification that invalidates the
         | safety and you can get teeny tiny sensors with zigbee off the
         | shelf.
        
       | a-dub wrote:
       | bandpass filtering in the time domain seems like it may be more
       | efficient for this use case to me. if i'm reading the code
       | correctly, it seems it's computing a 512 point window and fft on
       | every non-overlapping window.
       | 
       | i guess it depends on what vector/matrix instructions are being
       | used in the underlying implementations.
        
         | KeplerBoy wrote:
         | I'm also curious about the power draw of continuously executing
         | FFTs on a rpi.
         | 
         | Seems like the kind of task where one could easily burn 10
         | watts, if the wrong FFT Implementation is chosen. You'd
         | absolutely want to do this in DSP hardware.
        
           | pdubouilh wrote:
           | yeah using a DSP for this definitely makes more sense - but
           | I'm lacking experience in the field. Same goes for using a
           | discrete band-pass filter. This project is more of an attempt
           | at "how can I build something in 2 hours that works reliably"
           | !
           | 
           | For reference, it eats ~25% of the available CPU resources on
           | my rpi zero 2w - which draws a maximum of 350mA, so this
           | implementation definitely draws less than 1 watt.
        
             | KeplerBoy wrote:
             | Nice to see that it consumes barely any power. Looks like a
             | fun and useful project!
        
             | a-dub wrote:
             | yes and it's very cool! if you're interested in learning,
             | i'd look into the filtering approach.
             | 
             | maybe could try pyfda and the filtering functions in
             | scipy.signal to start playing around.
             | 
             | or if you have access to matlab it has some really
             | excellent filter design tools.
             | 
             | regarding the hardware/dsp: many cpus include simd
             | instructions these days, which basically are an interface
             | to a hidden digital signal coprocessor. :)
        
             | _Microft wrote:
             | 1W of continuous power consumption is not great. To put it
             | into perspective: that's 1x24x365Wh, almost 9kWh per year.
             | A kettle (1.8-2kW) can run for 4-5 hours for that amount of
             | energy. If getting a kettle to boiling takes 5 minutes,
             | that's almost 50-60 kettles. That's two month of boiling
             | one kettle a day.
        
       | xchip wrote:
       | you dont need a FFT you can use a Goertzel band pass filter
        
         | qwertox wrote:
         | I was thinking the same.
         | 
         | From Wikipedia:
         | 
         | "The Goertzel algorithm is a technique in digital signal
         | processing (DSP) for efficient evaluation of the individual
         | terms of the discrete Fourier transform (DFT). It is useful in
         | certain practical applications, such as recognition of dual-
         | tone multi-frequency signaling (DTMF) tones produced by the
         | push buttons of the keypad of a traditional analog telephone.
         | The algorithm was first described by Gerald Goertzel in 1958."
         | [0]
         | 
         | It's also a nice project for an ESP32 with a MEMS microphone.
         | 
         | [0] https://en.wikipedia.org/wiki/Goertzel_algorithm
        
           | pdubouilh wrote:
           | Thanks for this, I'll toy with implementing that instead of a
           | full FFT
        
       | animex wrote:
       | My Wyze cam does this with the included functionality. I get a
       | text/notification when it detects the alarm. However, it does get
       | fooled by certain sounds from the TV.
        
         | pdubouilh wrote:
         | This is smart - minut sensors are also doing the same (afaiu).
        
       | asdefghyk wrote:
       | Is there sample audio of the fire alarm, when it is activated? Is
       | this alarms to US standards ? It seems so, It seems different
       | countries have some different requirements for this audio sound?
       | ...... There is also commercial fire alarms and residential smoke
       | alarms. which in my country have different signals ( if my
       | recollection is corrct )
        
         | pdubouilh wrote:
         | There's an audio file in the repo to simulate an alarm (works
         | for 3 different models bought in Germany, they all sound the
         | same). You can pass the target frequency, beep-length and audio
         | threshold as parameters in the CLI (you can estimate these
         | params with audacity).
        
       | asdefghyk wrote:
       | It is also quite useful to know exactly which alarm triggered. It
       | would seem it is not feasible to have a DIY system to implement
       | this
        
         | doubleg72 wrote:
         | I didn't click the link yet, but one could easily DIY with a
         | microcontroller at each alarm, picking up the alarm signal in
         | some fashion or another.
        
       | severino wrote:
       | I took a look at the source, as I was curious about how does one
       | perform a FFT of a signal, but stumbled upon this. Could somebody
       | explain to me what this calculation does? ( _in_ is the audio
       | signal, if I 'm not wrong)                 window :=
       | make([]float64, len(in))       for i, x := range in {
       | window[i] = float64(x) * (0.54 -
       | 0.46*math.Cos(2*math.Pi*float64(i)/float64(len(in)-1)))
       | 
       | Thanks
        
         | geolqued wrote:
         | It looks like a windowing function. Used to turn continuous
         | data into segments of data for FFT processing.
         | https://en.m.wikipedia.org/wiki/Window_function
        
       | bearbin wrote:
       | There's a physical product that implements the same idea [1]. I'm
       | not sure how it actually works (presumably there's a patent
       | somewhere, is there an alternative solution?) but it's quite a
       | magic feeling to hear the fire alarm go off and the doors
       | independently close by themselves. If you're in a building that
       | uses these, you can test yourself by playing a recorded fire
       | alarm sound - they work on quite a few different ones (and it
       | really doesn't have to be that loud!). They also have a
       | surprisingly long battery life, ~10 years I think so the
       | detection mustn't take much power at all.
       | 
       | [1]: https://www.fireco.uk/products/sound-activated/dorgard/
        
       ___________________________________________________________________
       (page generated 2024-04-07 23:00 UTC)