<?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 Ashwini Verma on Medium]]></title>
        <description><![CDATA[Stories by Ashwini Verma on Medium]]></description>
        <link>https://medium.com/@ashwini7verma?source=rss-7d8896d1e1ac------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*PGfcvDikPUns0UafpOUkIA.jpeg</url>
            <title>Stories by Ashwini Verma on Medium</title>
            <link>https://medium.com/@ashwini7verma?source=rss-7d8896d1e1ac------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 23:08:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ashwini7verma/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[Understanding Audio Fingerprinting]]></title>
            <link>https://medium.com/swlh/understanding-audio-fingerprinting-b39682aa3b5f?source=rss-7d8896d1e1ac------2</link>
            <guid isPermaLink="false">https://medium.com/p/b39682aa3b5f</guid>
            <category><![CDATA[audio-signal-processing]]></category>
            <category><![CDATA[spectrogram]]></category>
            <category><![CDATA[visualizing-audio-signal]]></category>
            <category><![CDATA[shazam]]></category>
            <category><![CDATA[audio-fingerprinting]]></category>
            <dc:creator><![CDATA[Ashwini Verma]]></dc:creator>
            <pubDate>Sun, 18 Oct 2020 19:36:11 GMT</pubDate>
            <atom:updated>2021-01-05T13:07:35.652Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vF3YfLmSiTYUtwWy1IXxsw.png" /><figcaption><a href="https://iwcmc.org/2021/wp-content/uploads/2020/06/S3-SP_Ver3-1.jpg">https://iwcmc.org/2021/wp-content/uploads/2020/06/S3-SP_Ver3-1.jpg</a>, <a href="https://inpublicsafety.com/wp-content/uploads/sites/13/2018/08/Police_fingerprints_weiss.jpg">https://inpublicsafety.com/wp-content/uploads/sites/13/2018/08/Police_fingerprints_weiss.jpg</a></figcaption></figure><p>You are at a resto, waiting for your coffee. There is faint music playing in distance. You are smiling listening to it as you are trying to figure out which song is that. You have heard it before but not able to figure which song it is. Despite your hard attempt to figure out that song, you still couldn’t recall. You take out your phone, open the Shazam app, record the noisy music, and there you have it. Now you are thanking the shazam app teams. Thinking how cool and creative this idea is, you want to know how is this working.</p><p>Hi, I am Ashwini Verma, a data science enthusiast and taking a small attempt to explain the similar mechanism which is being used in the outstanding app. So let’s get started.</p><p>The mechanism is called <strong>Audio Fingerprinting</strong>. You know about fingerprints right? They say, no two people have been found to have the same fingerprints — they are totally unique. A similar phenomenon we are going to use for matching two similar audio samples.</p><p>The music we hear from any instrument such as guitar, or piano are analog signals. But when we store it in our electronic devices they need to be digitized. If you wanna know more about their conversion from analog to digital signals read it <a href="http://coding-geek.com/how-shazam-works/">here</a>.</p><h4>Loading Audio File</h4><p>Let’s read a digital audio file and look at it in an interesting way. The song here is a very beautiful one called “Something Like This” by “The Chainsmokers”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*_9md3A5-7-jxstqu5UzdkQ.png" /></figure><p>This audio signal here has 2 channels as it is stereo. Let’s deal with 1 channel at a time.</p><h4>Visualizing Signal</h4><p>A channel is just some numbers representing the audio signal which looks quite boring. But there some other way we can look at it. It is the image representation of the signal called a spectrogram. It’s a two-dimension graph with time on the horizontal axis and frequency on the vertical axis. Now you can imagine the third dimension as amplitude (loudness of sound) which is a function of time and frequency described by the intensity of color across the graph.</p><p>As <a href="https://matplotlib.org/api/mlab_api.html?highlight=specgram#matplotlib.mlab.specgram">matplotlib</a> states <em>specgram compute and plot a spectrogram of data in x. Data are split into NFFT length segments and the spectrum of each section is computed. The windowing function window is applied to each segment, and the amount of overlap of each segment is specified with noverlap</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/779/1*DibRTSL1QuZScj7_NuGlzA.png" /><figcaption>Code for spectrogram</figcaption></figure><p>Here we take NFFT value to be 2¹² as it should always be the power 2. The value of Fs should be 44,100 Hz because it is a customary rate used to sample audible frequencies as it is based on the limits of human hearing and the <a href="https://en.wikipedia.org/wiki/Nyquist%E2%80%93Shannon_sampling_theorem">Nyquist–Shannon sampling theorem</a>. You would have noticed that the frame rate of the audio file we uploaded is the same as 44100 Hz. We take half the window size for overlapping and receive the array of spectrograms. In order to get the linear array, we apply the logarithmic transformation on the spectrogram. Let’s plot it. Now it looks quite interesting, right?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/441/1*n5puujXyYo_uMR0cl3pVsw.png" /><figcaption>Spectrogram of the complete song</figcaption></figure><p>Let’s just look at the very tiny portion of the spectrogram closely.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*i908pjxTRqCZLO-0vcvJFw.png" /><figcaption>Spectrogram of the tiny portion of the song</figcaption></figure><h4>Finding Peaks</h4><p>Now we want to figure out some features about this signal which should be unique. Looking at the figure what do you think.<br>You see the amplitudes represented by colors could be useful. Let’s call blue color high-intensity blocks as peaks. We are choosing only the highest amplitudes because they are more robust in the presence of noise. But this peak alone cannot be a unique feature. Almost every other audio signal will have those peaks somewhere in its spectrogram.</p><p>So can we take peaks along with time as a feature? But tell me what is the probability of us recording the song from the exact start time of the actual song. Next to impossible.</p><p>So what should we do now? We will take a unique representation of any two peaks and the time difference between these two as two features. It is less likely that (magnitudes of two peaks and their time difference) would match with other song’s. Even if it matches not every pair of peaks with their time difference are going to match. So at last, we have decided what are our features going to be. Let’s extract them now.</p><p>We will import a few functions from <em>scipy</em>, which will come in very handy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/539/1*DImqr_yVN-CFIp3A8hu0ZA.png" /></figure><p>Okay, okay. Don’t be scared, I will explain every function and our intentions to use them.</p><p>So back when I said, we will get all those peaks, how are we deciding which peaks are one we are interested in. We cannot just have a threshold to filter peaks. Each audio is different when it comes to loudness (amplitude). Consider the spectrogram made up of blocks or a matrix with frequency and time as axes. So we will take a chunk of blocks and figure out the maximum peak for that chunk. We will repeat this for all chunks available. Now how big this chunk could be. It can be 1 with the size of the matrix or just 2 blocks. Keeping the size smaller will give us more no of peaks but take more space to store them and vice versa.</p><p>So <em>scipy</em> function <em>generate_binary_structure</em> helps us to define the shape of chunk and <em>iterate_structure</em> helps us iterate the chunk pattern n number of times. The below example will clear this up.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/479/1*0ASPyKvJIFe-Xp2hauxodQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/644/1*pad0QO8YrWJu_HHMAc-Dcg.png" /></figure><p><em>maximum_filter</em> helps to find out maximum peak at each index considering only the neighboring peaks. Imagine a window of (3 X 3) sliding over the array moving through every index as its center.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/757/1*LW6exx_5VFSpdkd4TrUIsQ.png" /><figcaption>Maximum Filter implementation</figcaption></figure><p>Now the <a href="https://en.wikipedia.org/wiki/Erosion_%28morphology%29"><em>binary_erosion</em></a><em> </em>method uses a structuring element for shrinking the shapes in an image. The below code snippet is self-explanatory. This is explained <a href="https://stackoverflow.com/a/3689710/8129056">here</a> in detail.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/573/1*umGzhCx35ZSCDPDMCP0hJA.png" /><figcaption>Binary erosion implementation</figcaption></figure><p>Here is the complete code for finding the peaks in the spectrogram.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*Jykro2YzypISMWjHJ5Eoyg.png" /></figure><p>After using the above helper functions, we plot the peaks in the small portion of the spectrogram we took earlier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/465/1*lzzEHcTmlTq1g9H2mOnjuw.png" /><figcaption>Peaks in a small portion of the spectrogram</figcaption></figure><h4>Combinatorial Hashes</h4><p>We decided that we will take 2 peaks pair and their time difference as features. We form a string using them and create their hashes using a <a href="https://en.wikipedia.org/wiki/Hash_function"><em>hash function</em></a>.</p><blockquote>hash_function(“freq1|freq2|time_difference”)</blockquote><p>If we plot a combination of peaks from one source peak, it will look like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/408/1*ib-AwGAX3R_4YiaFB3P9cw.png" /><figcaption>Combinatorial peaks</figcaption></figure><h4>Finding Matches</h4><p>We can store all these hashes/fingerprints somewhere. We can perform the same process of finding the peaks and their hashes for our new audio sample which we want now to find a match for. We can simply cross-check for hashes in both the audio sample and the original audios we have in our system. The greater the number of matches, the more are the chances for that audio to be similar.</p><h4>Aligning Matches</h4><p>Now that we have our match from the system for the sample audio, we can find the alignment of it on the original audio. What I mean is to find out the best possible position of the sample audio in the original audio.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/443/1*s1Dr7vqbcT2vhPUG6O7AJQ.png" /><figcaption>Alignment of sample audio on original audio</figcaption></figure><p>So this is it. I hope my small attempt to briefing how audio fingerprinting helps match two similar audio signals appears interesting and beneficial to you all lovely readers. You may find a short implementation <a href="https://github.com/ashva7/audio_fingerprinting.git"><em>here</em></a>.</p><p>Adios!</p><h4>References</h4><p><a href="https://www.researchgate.net/publication/220723446_An_Industrial_Strength_Audio_Search_Algorithm">(PDF) An Industrial Strength Audio Search Algorithm.</a></p><p><a href="https://www.researchgate.net/publication/220723652_A_Highly_Robust_Audio_Fingerprinting_System">https://www.researchgate.net/publication/220723652_A_Highly_Robust_Audio_Fingerprinting_System</a></p><ul><li><a href="https://willdrevo.com/fingerprinting-and-audio-recognition-with-python/">Audio Fingerprinting</a></li><li><a href="http://coding-geek.com/how-shazam-works/">How does Shazam work</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b39682aa3b5f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/understanding-audio-fingerprinting-b39682aa3b5f">Understanding Audio Fingerprinting</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>