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
Acoustics
  • Challenges & Projects
  • Project14
  • Acoustics
  • More
  • Cancel
Acoustics
Blog Synthetic Mains Hum Noise
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Acoustics to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: neuromodulator
  • Date Created: 6 Mar 2020 1:49 PM Date Created
  • Views 4372 views
  • Likes 10 likes
  • Comments 12 comments
  • p14acousticsch
  • acousticsch
Related
Recommended

Synthetic Mains Hum Noise

neuromodulator
neuromodulator
6 Mar 2020

  • Introduction
  • Getting the sample
  • Audio analysis and synthesis
  • Conclusion

 

Introduction

 

The mains hum is generated by alternating current and contains multiple harmonics of its fundamental, which typically is either 50 or 60 Hz. I was wondering how I could synthesize the noise, which of course does not have much practical use as according to a small poll (Mains hum) the noise makes most people anxious.

 

 

Getting the sample

 

To get a good audio sample I began looking for samples in Youtube and found this one (which Dave Farmer kindly allowed me to use in this project):

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

Dave Farmer

The video was downloaded with JDownloader2 and ~26 s of audio were extracted with ffmpeg.

 

 

Audio analysis and synthesis

 

The spectrogram of the extracted audio sequence looked like this:

image

 

As it can be seen, it contains multiple harmonics of the 50 Hz fundamental. I then extracted a "clean" 5 s segment at the 13 s timestamp and computed the power spectrum density using Welch's method:

image

 

I then measured the amplitude of the fundamental and 99 harmonics and ran 100 oscillators at random phase shifts. The spectrum looked like this:

image

 

Even though the spectrums look quite different, they sound similar. Two important differences are that the synthetic hum is stationary, while the recorded one is not (it changes with time), and the second difference is that the recorded hum contains noise (wind on the microphone, etc), while the synthetic hum doesn't. The video compared the recorded segment to the synthetic segment:

 

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

 

I tried covering all harmonics up to lower frequencies using fewer oscillators, but I noticed that with fewer than 80 oscillators the synthetic hum began sounding quite different to the original.

Here's the code used to generate the audio and the figures:

import numpy
import sounddevice as sound
import scipy.io.wavfile as wavfile
import scipy.signal as signal
import matplotlib.pyplot as pyplot

duration = 5
sampleRate = 44100

fundamental = 50.085
nHarmonics  = 100
delta       = 25

audioRate, wave = wavfile.read('../Data/hum.wav')
wave = wave[:, 0].astype(numpy.float)

pyplot.specgram(wave, NFFT = 8000, Fs = audioRate, noverlap = 4000, detrend = 'mean')
pyplot.ylim(0, 8000)
pyplot.xlabel('Time (s)')
pyplot.ylabel('Frequency (Hz)')
pyplot.tight_layout()
pyplot.savefig('../Data/Spectrogram.png', dpi = 300)
pyplot.close()

wave = wave[int(13. * audioRate) : int(18. * audioRate)]
wave = wave / numpy.abs(wave).max()

frequency, power = signal.welch(wave, fs = audioRate, nperseg = 1024 * 16)

harmonics   = numpy.zeros(nHarmonics)
frequencies = numpy.zeros(nHarmonics)

for i in range(nHarmonics):
    higher = frequency > ((i + 1) * fundamental) - delta / 2
    lower  = frequency < ((i + 1) * fundamental) + delta / 2
    harmonics[i]   = numpy.max(power[numpy.logical_and(lower, higher)])

t = numpy.arange(sampleRate * duration) / sampleRate
f = numpy.zeros(sampleRate * duration)

for i, h in enumerate(harmonics):
    f += numpy.sin(2 * numpy.pi * (fundamental) * (i + 1) * t + numpy.random.random(1)[0]* numpy.pi * 2) * numpy.sqrt(h)

f = f / numpy.abs(f).max()

frequency1, power1 = signal.welch(wave, fs = audioRate, nperseg = 1024 * 128)
frequency2, power2 = signal.welch(f, fs = audioRate, nperseg = 1024 * 128)

pyplot.plot(frequency1, 10 * numpy.log10(power1 / power1.max()))
pyplot.xlim(0, 8000)
pyplot.ylim(-120, 0)
pyplot.xlabel('Frequency (Hz)')
pyplot.ylabel('Power (dB)')
pyplot.tight_layout()
pyplot.savefig('../Data/Recorded.png', dpi = 300)
pyplot.close()

pyplot.plot(frequency1, 10 * numpy.log10(power1 / power1.max()))
pyplot.plot(frequency2, 10 * numpy.log10(power2 / power2.max()))
pyplot.xlim(0, 8000)
pyplot.ylim(-120, 0)
pyplot.xlabel('Frequency (Hz)')
pyplot.ylabel('Power (dB)')
pyplot.legend(['Recorded', 'Synthesized'], frameon = False)
pyplot.tight_layout()
pyplot.savefig('../Data/Synthesized.png', dpi = 300)
pyplot.close

wavfile.write('../Data/Recorded.wav', 44100, (wave * ((2. ** 15.) - 1)).astype(numpy.int16))
wavfile.write('../Data/Synthesized.wav', 44100, (f * ((2. ** 15.) - 1)).astype(numpy.int16))

sound.play(wave, 44100)
sound.wait()
sound.play(f, 44100)
sound.wait()

 

 

Conclusion

 

This simple project showed that it is possible to mimic a relatively simple "real sound" through simple wave analysis and audio synthesis. It also shows that the auditory system puts different emphasis on different aspects of acoustic waves, the oscillator phase difference for instance was likely very different to that of the recording and still sounded very similar to the original recording.

  • Sign in to reply

Top Comments

  • shabaz
    shabaz over 5 years ago +4
    Very interesting : ) I'm now thinking, of ways to capture it. My mains hum sounds different : ) Maybe inductive or capacitive pick-up. One option could be a transformer. I wonder if an audio transformer…
  • neuromodulator
    neuromodulator over 5 years ago in reply to shabaz +3
    A musical instrument might be interesting too...
  • genebren
    genebren over 5 years ago in reply to shabaz +3
    I would believe that the mains sound is heavily influenced by the harmonic/resonance of the mechanical device/enclosure, so the no two device will necessarily sound the same.
Parents
  • John
    John over 2 years ago

    Hi Neuromodulator, can you synthesize this electric hum sound: www.youtube.com/watch

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • neuromodulator
    neuromodulator over 2 years ago in reply to John

    I think it should work. Just give it a try

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Comment
  • neuromodulator
    neuromodulator over 2 years ago in reply to John

    I think it should work. Just give it a try

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
  • John
    John over 2 years ago in reply to neuromodulator

    I am new to sound synthesis and MatLab. What do need to synthesize the sound in Java? I couldn't get MatLab. Thanks. 

    • 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