<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Mikhail Baranov on Medium]]></title>
        <description><![CDATA[Stories by Mikhail Baranov on Medium]]></description>
        <link>https://medium.com/@baranov.mv?source=rss-a73476520a77------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*-tqRRGzCmQwBxckIFBeICw.png</url>
            <title>Stories by Mikhail Baranov on Medium</title>
            <link>https://medium.com/@baranov.mv?source=rss-a73476520a77------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 23:52:05 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@baranov.mv/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Deep Active  Noise Cancellation]]></title>
            <link>https://medium.com/data-science/deep-active-noise-cancellation-e364ce4562d4?source=rss-a73476520a77------2</link>
            <guid isPermaLink="false">https://medium.com/p/e364ce4562d4</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[noise-cancelling]]></category>
            <category><![CDATA[signal-processing]]></category>
            <dc:creator><![CDATA[Mikhail Baranov]]></dc:creator>
            <pubDate>Sun, 24 Feb 2019 23:18:24 GMT</pubDate>
            <atom:updated>2019-07-15T22:36:08.615Z</atom:updated>
            <content:encoded><![CDATA[<h3>Recurrent Neural Active Noise Cancellation</h3><h4>RNN predicts a structured noise to suppress it in a complex acoustic environment</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*rwsQHpbU_bzpB5ycsyzPlg.jpeg" /><figcaption><a href="https://flic.kr/p/RVPv83">Flickr</a>, CC BY-NC 2.0</figcaption></figure><p>In my <a href="https://medium.com/coinmonks/acoustic-noise-cancellation-by-machine-learning-4144af497661">previous post</a> I told about my Active Noise Cancellation system based on neural network. Here I outline my experiments with sound prediction with recursive neural networks I made to improve my denoiser.</p><p>The noise sound prediction might become important for Active Noise Cancellation systems because non-stationary noises are hard to suppress by classical approaches like FxLMS. That’s why I tried simple two layered perceptron before and why I’ve tried Recursive network for this time.</p><p>The work is simple: I challenged the task of predicting the samples ahead and I use<a href="https://www.youtube.com/watch?v=sBvt0lsoInc"> Leva’s Polka</a> as a guinea pig. The task requires a lot of computational power, so I shrink the song to the first 5 seconds in order to be able to train RNN on my laptop without discrete GPU.</p><h3>Waybackprop</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*PTum7hLjpwZkmWcok3wgJQ.gif" /><figcaption>Image from <a href="https://magenta.tensorflow.org/blog/2017/06/01/waybackprop/">Magenta blog</a></figcaption></figure><p>The core idea of the network architecture was derived from the <a href="https://magenta.tensorflow.org/blog/2017/06/01/waybackprop/">post</a> in the Magenta project blog. The author has brought a spirit of multi-speed signal processing in RNN domain. The post describes the idea perfectly, it even has lucid illustrations, so I’m not going to compete with it. Although, I’m giving short description of the idea here.</p><p>Music or audio in general has long-term underlying processes so the model needs to be learnt with such long examples. In that experiment I made NN with 400 samples input width. It’s only 50 ms, other information NN took from previous outputs.</p><p>The main problem with RNN in music prediction (or generation) problem is the complexity of learning. Truncated backpropagation unwinds history of input samples and input states in tens or hundreds times. That means feed-forward path is tens or hundreds times faster to compute than feedback path.</p><p>The main idea is to build several layers of common Recursive Neural Networks cells,usually comprise cells which take state of the previous stage and input values and returns next state and output.</p><h3>Implementation</h3><p>As in the previous experiment, I used python 3.4, tensorflow 1.0, Linux Mint 17.2, no real-time experiments was conducted though due to extensive computational requirements.</p><p>I’ve made a three-layer deep neural network of <a href="https://en.wikipedia.org/wiki/Gated_recurrent_unit">GRU</a> cells. GRU cells was implemented by myself too cause it simpler to integrate in the whole system. Each layer takes inputs from:</p><ul><li>the output of the layer below, which is faster one (greater sample rate);</li><li>itself previous output;</li><li>output of the layer above.</li></ul><p>The first layer takes raw samples with 8 kHz of sample rate, the width of input is 1 samples. The internal state is vector of 64 values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/579/1*of42LQuXh-siMazu7k3tlQ.png" /><figcaption>Outline</figcaption></figure><p>I’ve also tried my own cells made of plain perceptrons, and it worked too, but the performance of GRU cells was better and I stopped on them. The most top layer didn’t give any sufficient value in that experiment, but I’ve left it anyway.</p><h3>Results</h3><p>The song’s part used for the experiment:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fw.soundcloud.com%2Fplayer%2F%3Furl%3Dhttps%253A%252F%252Fapi.soundcloud.com%252Ftracks%252F580659555%26show_artwork%3Dtrue%26in%3Dm4kvw8oph3bi%252Fsets%252Fdeep-levas-polka-prediction&amp;url=https%3A%2F%2Fsoundcloud.com%2Fm4kvw8oph3bi%2Foriginal-1%3Fin%3Dm4kvw8oph3bi%2Fsets%2Fdeep-levas-polka-prediction&amp;image=http%3A%2F%2Fa1.sndcdn.com%2Fimages%2Ffb_placeholder.png%3F1550159185&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=soundcloud" width="800" height="166" frameborder="0" scrolling="no"><a href="https://medium.com/media/618738e71b6c892bcb5836b0811aa3d4/href">https://medium.com/media/618738e71b6c892bcb5836b0811aa3d4/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fw.soundcloud.com%2Fplayer%2F%3Furl%3Dhttps%253A%252F%252Fapi.soundcloud.com%252Ftracks%252F580659546%26show_artwork%3Dtrue%26in%3Dm4kvw8oph3bi%252Fsets%252Fdeep-levas-polka-prediction&amp;url=https%3A%2F%2Fsoundcloud.com%2Fm4kvw8oph3bi%2F50-samples-ahead-prediction-1%3Fin%3Dm4kvw8oph3bi%2Fsets%2Fdeep-levas-polka-prediction&amp;image=http%3A%2F%2Fa1.sndcdn.com%2Fimages%2Ffb_placeholder.png%3F1550159185&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=soundcloud" width="800" height="166" frameborder="0" scrolling="no"><a href="https://medium.com/media/fe09d07d8699e3f98a2c57147cfaff34/href">https://medium.com/media/fe09d07d8699e3f98a2c57147cfaff34/href</a></iframe><p>The original and reproduced samples (top) and their spectrum:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/425/1*sVRx_SESPGQeN4OYgHNTGA.png" /></figure><p>Another part:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/405/1*BLr-_5y23Q62NWPQuQVtLw.png" /></figure><p>The target norm was mean square error, the first epoch has 0.0176689 error norm, and the last 800th has 0.000453576 norm.</p><p>There’s no patents about that problem, neither I don’t have commercial plans so far. However, I’d love to have a full-time job devoted to that theme, and that’s why I don’t put the source code to github.com. However, may be someday I’ll release them.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e364ce4562d4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/deep-active-noise-cancellation-e364ce4562d4">Deep Active  Noise Cancellation</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Acoustic Noise Cancellation by Machine Learning]]></title>
            <link>https://medium.com/data-science/acoustic-noise-cancellation-by-machine-learning-4144af497661?source=rss-a73476520a77------2</link>
            <guid isPermaLink="false">https://medium.com/p/4144af497661</guid>
            <category><![CDATA[noise-cancelling]]></category>
            <category><![CDATA[tensorflow]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[dsp]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Mikhail Baranov]]></dc:creator>
            <pubDate>Mon, 25 Jun 2018 22:04:09 GMT</pubDate>
            <atom:updated>2019-02-27T15:50:34.981Z</atom:updated>
            <cc:license>https://creativecommons.org/licenses/by-sa/4.0/</cc:license>
            <content:encoded><![CDATA[<h4>DIY Noise-Cancellation System prototype made with TensorFlow.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*Oi4_jD2tyo7AGMUaR9_pJw.jpeg" /><figcaption>Image by TheDigitalArtist on Pixabay</figcaption></figure><p>In this post I describe how I built an active noise cancellation system by means of neural networks on my own. I’ve just got my first results which I am sharing, but the system looks like a ravel of scripts, binaries, wires, soundcard, microphone and headphones, so I am not going to publish any sources yet. May be later.</p><h3>Pet project with Tensorflow, ALSA, C++ &amp; SIMD, and Python</h3><p>During the last year I’ve been building an Acoustic Noise Cancellation system based on an Artificial Neural Network. I did it in my spare time, so that’s why it took so long for a relatively small experiment. The system I’ve built is a proof-of-concept, it showed consistency of an idea of NN as a noise canceller.</p><p>I was impressed by recent achievements of ML in image processing like neural style transfer. And I thought: “What if we teach RNN with repeated audio noise patterns in order to suppress it by ANC?” I had implemented perceptron on a DSP for some radar stuff before, so I wasn’t afraid by necessity of implementing neural network in a real-time software. Although I haven’t deal with tensorflow and gpu before, I was eager to do something with them. So far it seems to me that that was interesting trip and at last I achieved some results and had a lot of developers fun.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*uP71unfJGsii4UZUwS-JHg.png" /><figcaption>Artificial Brain Denoising</figcaption></figure><h4>Why do we need ML to suppress noise?</h4><p>Modern ANC systems successfully suppresses stationary noises like one in an aircraft. Common approach incorporates adaptive filters like <a href="https://en.wikipedia.org/wiki/Least_mean_squares_filter">LMS</a> or <a href="https://en.wikipedia.org/wiki/Recursive_least_squares_filter">RLS</a>. The main flaw of this methods is that they are just FIR-filters at their core, which coefficients are being constantly adapted, and it fits the noise only after a few thousand samples. It means that an adaptive filter starts re-adapting to every changes of the environmental noise, even if it heard that pattern several seconds before. The use of ML methods in ANC could improve its performance because neural networks are able to adapt to signals with very complex internal structure.</p><blockquote>NN in ANC is used for predicting values of noise samples in a moment when the black noise should meet the noise in a position of the microphone.</blockquote><p>I expect outdoor noises like a loud exhaust system or a dishwasher aren’t stationary in a broad sense but pretty repetitive and could be learnt by a NN relatively easily.</p><h3>Test set-up</h3><p>My pet-project works as classic noise cancelling headphones except the fact that the microphone is located <strong>inside</strong> an ear-cup. The test set-up looks plain and simple:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/276/1*7f7FTXH621K6Eu0XQ-svwg.png" /></figure><p>I didn’t locate the microphone on an outside (like all noise cancellation headphones do) because I wanted to solve the ANC problem in more broader case. This set-up lets me easily tune my code to a room or car environment because the structure in all that cases looks the same.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/227/1*Bmtw1li4M7HX2nN14SPJfg.jpeg" /></figure><h4>Software layout</h4><p>The software consists of three processes:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/532/1*KHcXBMKBLZ2f7XLMC4hhvQ.jpeg" /></figure><ul><li><strong>C++ program</strong> for real-time signal processing,</li><li><strong>The Manager</strong> is a Python script with tensorflow to teach NN,</li><li>And <strong>the Learner</strong> is another Python script to manage the whole process.</li></ul><p>The manager script communicates with others by <a href="https://grpc.io/">gprc</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0WnQSyktwS8AJ6HopnYCNQ.jpeg" /><figcaption>DIY mic-preamp and my old and dirty audio-technica ATH-910PRO</figcaption></figure><p>The microphone preamp and headphones are connected to a sound card, which is attached via USB to a laptop with Linux Mint 17 on it.</p><p>The microphone measures combination of a noise with a black-noise. Then C++ program does following things:</p><ol><li>reads samples,</li><li>splits external noise and the counter-signal from the headphones,</li><li>passes noise samples to the feed-forward pass of neural network to get black noise samples,</li><li>playback black noise samples produced by NN to the headphones,</li><li>transfer noise samples to the learner script via the manager script, gets new NN coefficients from the manager.</li></ol><p>I playback noises by my mobile phone standing couple meters aside the headphones. That construction managed to suppress different noise patterns, even non-stationary signals like bunches of sinuses, turned on and off arbitrarily by hands.</p><h3>Internal details</h3><p><strong>The input sound</strong> is being sampled at 48 kHz, 16 bits width. It is being down sampled by 8x times by the code and forwarded to the splitter.</p><p><strong>The splitter</strong> is needed to isolate the external noise from the input samples, as if there was no signal playedback to the headphones.</p><p><strong>The perceptron </strong>is implemented on my own in C++ with intrinsics of SIMD instructions in order to meet the requirement of real time processing. The perceptron consists of two hidden layers:</p><ul><li>The input layer tanh[304 x 64] takes last 304 samples of previously isolated external noise.</li><li>Intermediate layer tanh[64 x 64].</li><li>Output layer is linear [64 x 1].</li></ul><p>It is relatively small network and it is able to manage with the horizon of last 304 samples. It has simple implementation and it takes 30–60 seconds to be taught. I’m going to upgrade it to some recursive variant, I’ve already checked the ability of RNN model to adapt to some complex sounds in a Jupyter notebook. It looks promising, but takes way more time to converge. I hope I’ll write a post about this notebook later.</p><p><strong>The output signal</strong> is upsampled by 8x times and is sent to the headphones.</p><p>At the same time the program is sending bunches of external noise samples to the python script which is constantly adapting the weights of perceptron to newly measured noise patterns and sending it back to the c++ program. I run this python script in a cloud in vm with GPU. BTW, I found Paperspace is the best for ML experiments! Here is my <a href="https://www.paperspace.com/&amp;R=DUWONN">referral link</a>.</p><h3>Results</h3><p>Here is some plots demonstrating acheived results. This data is a log from C++ program, there is no objective measurements for now. However I tried to wear this headphones on my head and it seems working just like the plots show.</p><h4>Terms</h4><p><strong>Black noise </strong>is the signal that was sent to microphone.</p><p><strong>Pure noise </strong>is the external noise isolated by the splitter.</p><p><strong>Black noise transformed to mic’s input </strong>is residual part of signal isolated by the splitter.</p><p><strong>samples_in </strong>is raw sound samples measured by the microphone (and downsampled by 8x times of course).</p><p>Here is on the plot below how the perceptron senses the input and starting operating.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o2V6cZuiWZLIYvmEF8pltA.jpeg" /><figcaption>Single sine-wave @ 880 Hz</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WFTX_DyNdDzRUgiyKDcsTQ.jpeg" /><figcaption>Multiple sine-waves and longer period of time.</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4144af497661" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/acoustic-noise-cancellation-by-machine-learning-4144af497661">Acoustic Noise Cancellation by Machine Learning</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How I was listening to a sine sweep all day long]]></title>
            <link>https://medium.com/@baranov.mv/how-i-was-listening-to-a-sine-sweep-all-day-long-294c374995f6?source=rss-a73476520a77------2</link>
            <guid isPermaLink="false">https://medium.com/p/294c374995f6</guid>
            <category><![CDATA[sound]]></category>
            <category><![CDATA[signal-processing]]></category>
            <category><![CDATA[dsp]]></category>
            <category><![CDATA[sound-design]]></category>
            <category><![CDATA[acoustic]]></category>
            <dc:creator><![CDATA[Mikhail Baranov]]></dc:creator>
            <pubDate>Fri, 16 Dec 2016 16:05:24 GMT</pubDate>
            <atom:updated>2018-04-09T11:58:15.011Z</atom:updated>
            <cc:license>http://creativecommons.org/publicdomain/zero/1.0/</cc:license>
            <content:encoded><![CDATA[<p>I’ve just made some experiments with Room Response Estimation method described in “Simultaneous measurement of impulse response and distortion with a swept-sine technique” Angelo Farina [1]. The code measures Impulse Response of the room by playing a probe impulse (just specially prepared audio-signal) and recording the sound which appears to reflect back to a microphone. It’s available on <a href="https://github.com/baranovmv/RoomResponse">github</a>. So maybe someone will come into sight to share their opinion or even improvements.</p><p>These weird plots show how I correct my laptop speakers (I’ll tell you about it later):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KhHXYdvuynXR5yr4.png" /></figure><h3>Impulse Response</h3><p>Impulse Response of a room is an acoustic signal you can hear in a particular place in the room when someone makes a super short impulse in another place in the room. Strictly speaking, Room Response is a sum of acoustic reflections of Diracs impulse. Why measure it? Because this signal affects every sound you hear. It’s actually is the primary characteristics of the room reverberation. Estimating reverberation let us compensate it with predistortion of the audio signal we’re going to playback.</p><p>Homer produces very short and loud impulse, the arrows are some particular ways of acoustic waves:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/0*xcq1hQca50YToxJM.jpg" /></figure><p>And this is the signal that approaches the microphone:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/0*KCTzXiKJAFynVxg2.png" /></figure><p>Modern high-end audio receivers can perform a so-called Active Room Correction on their own, though I haven’t a chance to check how it affects an impression of the listening. There’re lots of experts reviews about such receivers and this feature. Also, there are several programs aimed to measure the impulse response that let you know what the environment is.</p><p>I’ve made this small piece of code just out of curiosity. It showed interesting results so I hope I’ll continue digging this deeper in my spare time.</p><h3>How to measure a Room Response</h3><p>In ancient times it was common to measure an impulse response by recording on a tape the shortest sound one could make (e.g. piercing a balloon). However, nowadays there’re several wide-known modern computational techniques for Room Response Estimation. They all involve speakers and microphone, though they use different math underneath. In short, the basic idea beyond all of them is producing a long self-orthogonal signal with a speaker and calculating cross-correlation between played and measured signals.</p><h4>Why don’t just measure an amplitude and phase characteristic</h4><p>Realy, why don’t we just play a sine of a particular frequency, record the response then increase the frequency and play and record again etc, then perform Inversed Fourier Transform and voilà — here we’ve got the Room Response! Just like all digital network analyzers do!</p><p>Every tiny error in measurements would make the result of the IFFT complex. And the fact is that Farina’s method is almost the same but much more usable.</p><h4>What methods can we actually use</h4><p>The most popular modern digital methods of measuring the room response are:</p><ul><li>MLS (Maximum Length Sequence) technique: a program playbacks a periodic pseudo-random signal, which is almost the same as white noise, but the program is able to correlate it’s acquired copy with original signal in order to recover room impulse response.</li><li>IRS (inverted repeated sequence): the sequence consists of MLS where every even sample is inverted.</li><li>Time-Stretched Pulses: “this method is based on a time expansion and compression technique of an impulsive signal. The aim of using an expansion process for the excitation signal is to increase the amount of sound power emitted for a fixed magnitude of this signal and therefore to increase the signal-to-noise ratio without increasing the nonlinearities introduced by the measurement system” [2]</li><li>Logarithmic SineSweep technique: probe signal is built with a sine-sweep with logarithmic changing frequency, so as to diminish harmonics influence on the result.</li></ul><p>Here is a comparison SNRs of these methods [2]:</p><ul><li><strong>MLS</strong> 60.5 dB</li><li><strong>IRS </strong>63.2 dB</li><li><strong>Time-Stretched Pulses </strong>77.0 dB</li><li><strong>SineSweep </strong>80.1 dB</li></ul><h3>Farina’s method</h3><p>Logarithmic SineSweep is the widely used method of the room response so far. This method performs very alike to a pulse radar: it emits a probe sound and records the reflection (and of course it gets the direct signal too because transmitters and receivers are not actually the same as in a radar). It lets us measure a pure linear room response vanishing out all non-linearity of the sound tract. Although it’s very sensitive to an external noise. Fortunately, it’s easier to get rid of the noise than to decrease non-linear harmonics volume.</p><p>I’ve chosen this method to implement on my own because of the content of the table in the previous part. It appeared to be simpler to implement than I expected, despite of it’s improved performance. It has a straightforward algorithm and clean description in the Farina’s paper [1]. I’ll give a short overview in the text below.</p><h4>Probe impulse</h4><p>So, in order to measure the response, we need to playback a probe sound. This impulse must satisfy following requirements:</p><ul><li>it has to contain all frequencies you want to measure,</li><li>it has to be self-orthogonal, so as to compress itself into Dirac’s impulse during auto-correlation.</li></ul><p>The Farina’s method also eliminates non-linear parts of recorded signal which is a very useful feature too.</p><p>The logarithmic sine-sweep impulse is very similar to widely-known sine-sweep signal which is described by following equation:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BZ_oLufkhIRcO1HPYQYoMQ.png" /><figcaption>eq. 1 Linear sweep chirp</figcaption></figure><p>This signal lasts for <strong>T</strong> seconds and contains a sine with linearly increasing frequency from ω¹ to ω². This is what most radars emit and receive.</p><p>But we can get more if we use exponential law for changing the frequency. In that case cross-correlation of the recorded signal won’t produce fake copies of the probe impulse.</p><p>The log sweep is made with this not-so-simple formula:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8sKaJDU2d7fjnlnOHUhbnA.png" /><figcaption>eq.2 logarithmic chirp</figcaption></figure><p>Here is how it’s looks like (it’s smoothy on the boundaries on purpose, I modulated it with exponential windows):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*An_DCG46KGMqYntS.png" /></figure><p>And what’s more important, spectrogram of probe impulse of range from 100 to 15 000 Hz:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*yqyM2jwMerUDqlaY.png" /></figure><p>And its spectrum:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*XIZoC0YawMdMa1oc.png" /></figure><p>It only remains for us to build inverse filter — the time-reversed copy of the x_logsweep(t), compensate its amplitude characteristic and convolve the record with it.</p><h4>How to build a correct reconstructing filter</h4><p>The log-sine-sweep impulse has skewed spectrum so that we need to correct the amplitude characteristic of its counterpart. Farina recommends in [1]:</p><blockquote><em>The generation of the inverse filter is simply matter of time-reversing the excitation signal, and then applying to it (the reversed impulse) an amplitude envelope to reduce the level by 6 dB/octave, starting from 0 dB and ending to</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/407/1*2zYJdeUX0JiYamnvjtVnsQ.png" /><figcaption>eq3. Upper frequency boundary</figcaption></figure><p>The inverse filter spectrogram:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*aADVcXtVhPEdH-4i.png" /></figure><p>Its actual graph is like that:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*IFl9t4jSUCTtMtU9.png" /></figure><p>And its spectrum:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*XphaizG2SADzOboR.png" /></figure><p>Now we can check the whole system by filtering original probe impulse with the inverse filter. I use for this the same frequency range from 100 Hz to 15 000 Hz and 10 seconds.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*YiJ2VAU2nYyaUQv0.png" /></figure><p>If you expected to see a delta impulse on this plot, I’m sorry than, it’s impossible until you’d have an unlimited bandwidth. Actually, this signal is a <a href="https://en.wikipedia.org/wiki/Sinc_function">sinc</a> (approximately), mixed with (multiplied by) a carrier frequency in the middle of the range (7 550 Hz). This simply means that we perform Room Response estimation over a limited bandwidth.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*HLxL9kqdx1UJglMo.png" /></figure><h3>The Code</h3><p>All code is available in this <a href="https://github.com/baranovmv/RoomResponse">repository</a>.</p><p>The heart of the room response estimation is inside <strong>RoomResponseEstimator</strong> class (room_response_estimator.py). Scripts <strong>evaluation.py</strong> and <strong>measure.py</strong> includes examples of its use. Class <strong>SoundEnvirenment</strong> (signal_env.py) mocks the real process of measurements. It receives an impulse response as an argument and do everything else inside its method <strong>run(…)</strong>. I used it while I was digging inside the math as a playground, but this code wasn’t preserved for descendants.</p><p>The probe impulse is generated inside <strong>probe</strong> method, which is called from the constructor:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8e056e15c68ef7175997ebaa8f5e5774/href">https://medium.com/media/8e056e15c68ef7175997ebaa8f5e5774/href</a></iframe><p>Everything must be pretty clear here, I’ve just implemented equations you saw in <a href="#6cd9">Probe impulse</a> part of this post. <strong>w1</strong> and <strong>w2</strong> are the boundaries of our target frequency range, <strong>T</strong> is the number of samples in the probe impulse.</p><p>The counterpart of the impulse response is made by just time reverse and frequency-dependent gain compensation of the probe pulse itself (mentioned in <a href="#89b3">How to build correct a reconstructing filter</a>)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/904ddb3f90a1f5bf332a500c2c8a5d7d/href">https://medium.com/media/904ddb3f90a1f5bf332a500c2c8a5d7d/href</a></iframe><p>And then a small workaround comes:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/febca7fca784b8361e473180bd85c91a/href">https://medium.com/media/febca7fca784b8361e473180bd85c91a/href</a></iframe><p>I just divide the impulse response of the reconstructing filter by the amplitude of the harmonic from the middle of the spectrum.</p><p>The whole process of estimation is just applying reconstructing filter to the recorded response, it’s implemented in the same class in <strong>estimate</strong> method:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2473c8b2bbf0a6eaa320d26ae6c22694/href">https://medium.com/media/2473c8b2bbf0a6eaa320d26ae6c22694/href</a></iframe><h4>How to use it on your own</h4><p>You can run measure.py and get several wave files, some of them you can reuse for debug.</p><p>This script just creates the probe impulse, stores it in the wav, calls for <strong>SoX</strong> to playback it and record the result (I call sox just because didn’t find any lib for python playing and recording sound that works for me), then it reads the record and plots some stuff which I describe little bit later.</p><p>The good way to start is just to call that: ./measure.py -b 100 -e 15000 -d 10. It should play the sweep and show you plots (and store the sweep and the record in wave-files).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*TCJwh6AD8rZHO0kL.png" /></figure><p>Here is what you can see on the plots:</p><ul><li><strong>Measured Room Response</strong> is the reason I did this piece of code,</li><li><strong>Deconvoluted Room Response</strong> is the result of Wiener Deconvolution of room response with itself just for check,</li><li><strong>Recorded log-sine sweep</strong> is the sound the microphone has just heard,</li><li><strong>Spectrum of the record</strong> is the spectrum of the previous signal,</li><li><strong>Deconvolved sine sweep</strong> is the result of Wiener Deconvolution of record with the measured room response just for check,</li><li><strong>Spectrum of deconvolved sine sweep</strong> is the spectrum of the previous signal.</li></ul><h3>ARC</h3><p>Active Room Correction in common sense is just a predistortion of samples to be played by a speaker in order to achieve almost exactly the same sound that was designed by a record engineer of a music recording studio. That implies applying a linear filter which attenuates peaks of the Room Response spectrum, though it’s hard to pull out zeros of standing waves by only digital means. Also one may want to tune phase characteristics of each channel in order to achieve right panorama.</p><p>I’m going to use <a href="https://www.reddit.com/r/linux_gaming/comments/2ot5ov/enable_system_wide_hrtf_with_pulseaudio/">hrir-module</a> of PulseAudio to make amplitude-frequency characteristic of my speakers and room response spectrum smoother.</p><p>Stay tuned</p><p><a href="http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.33.1614&amp;rep=rep1&amp;type=pdf">[1]</a> Simultaneous measurement of impulse response and distortion with a swept-sine technique, <strong>Angelo Farina</strong></p><p><a href="http://www.montefiore.ulg.ac.be/~stan/ArticleJAES.pdf">[2]</a> Comparison of different impulse response measurement techniques, <strong>Stan Guy-Bart, Embrechts Jean-Jacques, Archambeau Dominique</strong></p><p><em>Originally published at </em><a href="https://tarabah.me/roomresponse1/"><em>tarabah.me</em></a><em> on December 16, 2016.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=294c374995f6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>