<?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 Tiago Martins on Medium]]></title>
        <description><![CDATA[Stories by Tiago Martins on Medium]]></description>
        <link>https://medium.com/@ta.amfp?source=rss-b385fea31805------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*M4hKLlro0Hqi59uGNijKQg.jpeg</url>
            <title>Stories by Tiago Martins on Medium</title>
            <link>https://medium.com/@ta.amfp?source=rss-b385fea31805------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 21:39:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ta.amfp/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[Accelerated Signal Processing with GPU support]]></title>
            <link>https://medium.com/data-science/accelerated-signal-processing-with-gpu-support-767b79af7f41?source=rss-b385fea31805------2</link>
            <guid isPermaLink="false">https://medium.com/p/767b79af7f41</guid>
            <category><![CDATA[signal-processing]]></category>
            <category><![CDATA[gpu-computing]]></category>
            <dc:creator><![CDATA[Tiago Martins]]></dc:creator>
            <pubDate>Fri, 09 Jul 2021 01:41:48 GMT</pubDate>
            <atom:updated>2021-07-10T15:48:21.797Z</atom:updated>
            <content:encoded><![CDATA[<h4>Speed up your signal processing tasks with GPU supported ecosystems.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*InFiEh0CFd5xQtce" /><figcaption>Photo by <a href="https://unsplash.com/@nanadua11?utm_source=medium&amp;utm_medium=referral">Nana Dua</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3><strong>Introduction</strong></h3><p>Signal processing is part of a set of important techniques applied in a variety of fields, whether for scientific investigations or business applications, ranging from the analysis of large astrophysical phenomena to the development of speech recognition apps. It envolves different tasks such as filtering or transforming the original data to frequency domain.</p><p>A wide variety of code frameworks are currently available for general purpose programming languages, which can be used to implement these tasks, but it is still difficult to combine the speed of code execution from programming languages like <em>C++</em> with a greater ease of development in higher-level ones like <em>Python</em>. For scientific computing, the latter is highly used, with complete <em>API</em> sources and libraries like <em>Numpy</em> and <em>SciPy</em>. Despite slower than other low-level solutions, specially in case of intensive data computing, these environments are being supported with accelerated hardware like GPUs. More specifically with backend support from <a href="https://developer.nvidia.com/cuda-downloads"><em>CUDA</em></a> functions, thus optimizing time consumption from scientific tasks.</p><p>In this article, we will look through the capabilities of some GPU supported frameworks available for two specific signal processing techniques (Short-Time Fourier Transform and Power Spectral Density) and compare with a CPU inference based library.</p><h4>Hardware</h4><ul><li>CPU: AMD Ryzen 7 2700X;</li><li>GPU: NVIDIA GTX 1060 6GB.</li></ul><h3>Short-Time Fourier Transform Algorithm</h3><p>The Short-Time Fourier Transform (<em>STFT</em>) is a mathematical technique highly used for analysing non-stationary signals (time varying frequency). The basis of its functioning is to compute consecutive Fourier transforms (<em>FFT</em>) in different segments of equal length within a certain signal. The time-frequency <em>STFT</em>, <em>X[f,n]</em>, can be briefly described by Eq.1,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/951/1*uGe6VVWjA5CrfK3eZ5ZNxw.png" /><figcaption>Equation 1 — STFT.</figcaption></figure><p>where <em>w[m] </em>is the window function, <em>v </em>the frequency index, <em>n</em> is the time segment, <em>H </em>the distance between different window centers (<em>hop length</em>), <em>x[m+nH] </em>denotes the input signal with the overlap data of the <em>nH</em> segment, and <em>N </em>is the length of each segment. A more detailed description of how computationally the <em>STFT</em> is applied can be seen in <a href="https://www.researchgate.net/publication/346243843_Area-Efficient_Short-Time_Fourier_Transform_Processor_for_Time-Frequency_Analysis_of_Non-Stationary_Signals">this paper</a>.</p><p>The window function chosen for this work is a special case of the cosine window, defined in Eq. 2, were <em>α</em> is a nonnegative rational number.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/497/1*XvTkmdPYqsMTz2hiFM2yoA.png" /><figcaption>Equation 2 — Generalized cosine window function.</figcaption></figure><p>For <em>α</em> = 25/46 (or 0.54 approximately) we have the known <em>Hamming</em> window function, defined in Eq. 3.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*sbmlJDH-j9ZiQf_SQipTrQ.png" /><figcaption>Equation 3 — Hamming window function.</figcaption></figure><p>Fig. 1 shows a general illustration of the described process, with consecutive <em>FFT</em> being calculated in the original signal <em>x[m]</em> with a certain window function <em>w[m].</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/1*_uvtKjxUEHQvW8IakK-_TQ.png" /><figcaption>Figure 1 — Ilustration of the STFT (“Image by author”).</figcaption></figure><p>With this short revision about the mathematical background of <em>STFT,</em>we can now move forward to performance analysis.</p><h3>Scipy vs Tensorflow vs RAPIDS cuSignal</h3><p>To compute the <em>STFT</em>, we can use two <em>API</em> (<a href="https://www.tensorflow.org/api_docs/python/tf/signal/stft"><em>TensorFlow</em></a> and <a href="https://docs.rapids.ai/api/cusignal/stable/api.html"><em>RAPIDS cuSignal</em></a>) built-in functions with GPU suppport and compare their performance with the <a href="https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.stft.html"><em>SciPy</em></a> implementation.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ee5f728e9644c02d0facb2ffad72b78f/href">https://medium.com/media/ee5f728e9644c02d0facb2ffad72b78f/href</a></iframe><p>For the purpose of this comparison, we will use a snippet from a <em>wav</em> file, with a sample rate of 48 <em>kHz</em>, which is a personal attempt to cover Heitor Villa-Lobos classical guitar piece “<em>Prelude №1</em>”. You can have a listen through this <a href="https://soundcloud.com/user-121644687/tiagomartins-h-villa-lobos-prelude-no-1">link</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0a120ab027ac934d006472d2bda4363a/href">https://medium.com/media/0a120ab027ac934d006472d2bda4363a/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/504/1*ZvMWvyuiWJEoChTe7_vWTg.png" /><figcaption>Figure 2 — Signal data.</figcaption></figure><p>The chosen <em>STFT</em> segment length is 8192, with an half overlapped window. To measure the execution time of each <em>STFT</em> built-in method, the <a href="https://docs.python.org/3/library/timeit.html"><em>timeit</em></a> module is used. It is also possible to use other runtime methods such as <a href="https://docs.python.org/3/library/time.html"><em>time</em></a> and <a href="https://docs.python.org/3/library/profile.html"><em>cProfile</em></a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ad65c97fa53b545e74eb16e1046fbb43/href">https://medium.com/media/ad65c97fa53b545e74eb16e1046fbb43/href</a></iframe><p>With the obtained runtime values for each <em>API</em>, we can now plot a bar plot to evaluate the results.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/16b4a9e9d65e485903e679eb82342acc/href">https://medium.com/media/16b4a9e9d65e485903e679eb82342acc/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/604/1*us3bkqWZ7hCs_uLqIaQcSg.png" /><figcaption>Figure 3 — STFT runtime results.</figcaption></figure><p><em>SciPy </em>implementation can be speed up by a factor of almost 10 and 75 with <em>TensorFlow</em> and <em>cuSignal</em>, respectively. The best performance by <em>cuSignal</em> may be partially explained with the additional backend support of <em>CUDA </em>accelerated libraries for array computing.</p><p>For representation purposes, we can also represent the results from the <em>STFT</em> calculations in time <em>vs </em>frequency representation or, in other words, with a spectrogram (Fig.4).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FvQK1e4asDutGa5dKvnF2w.png" /><figcaption>Figure 4 — Signal Spectrogram (“Image by author”).</figcaption></figure><p>To increase temporal resolution <em>Δt</em>, one can decrease the window size of the <em>FFT</em>, but having in mind that doing that would have the disadvantage of decreasing frequency resolution <em>Δf</em>, as stated in the uncertainty relation below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/151/1*xt8KGd4xwiKEeLIgX-b_zQ.png" /><figcaption>Time vs Frequency Uncertainty Relation.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZVAzwrDunc7MpzA5lTfAWA.png" /><figcaption>Figure 5 — Signal Spectrogram with higher <em>Δt (</em>“Image by author”).</figcaption></figure><p>Let us now move forward to the second signal processing technique approached in this work.</p><h3>Power Spectral Density using Welch’s method</h3><p>The power spectral density (<em>PSD</em>) describes the power distribution as function of the different frequency components of a certain signal, considering Fourier Transform real part. There many options to estimate the power spectra. In particular, this work will focus on the <a href="https://www.osti.gov/servlets/purl/5688766/"><em>Welch’s method</em></a>, which can be divided in the following steps:</p><ul><li>Divide the signal into <em>K</em> segments;</li><li>For each segment <em>K</em> compute the discrete Fourier Transform (<em>DFT</em>);</li><li>Using the calculated <em>DFT</em> obtain the periodogram value, defined in Eq. 4, where <em>M</em> is the length of each segment <em>k</em>;</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/394/1*7EFGwyDWJuMFZL0o90-GUg.png" /><figcaption>Equation 4 — Periodogram.</figcaption></figure><ul><li>Average for <em>K</em> segments all periodogram values, giving the desired PSD (Eq. 5).</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/405/1*spkuityGaYjvlnnLazjw4A.png" /><figcaption>Equation 5 — Welch’s method PSD.</figcaption></figure><h3>Scipy vs RAPIDS cuSignal</h3><p>The calculation of the <em>PSD </em>in this case is done just considering <em>SciPy</em> and <em>cuSignal API</em>, with the same <em>FFT</em> parameters defined previously.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5910b123f1ccd8d341548a9ba65b4ddb/href">https://medium.com/media/5910b123f1ccd8d341548a9ba65b4ddb/href</a></iframe><p>Again, we analyse the performance of both methods using a bar plot.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3f5722abb7cf046ef9a6b4ea39481116/href">https://medium.com/media/3f5722abb7cf046ef9a6b4ea39481116/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/594/1*RoRhwI9eclpXuUq9sPtohw.png" /><figcaption>Figure 7 — PSD runtime results.</figcaption></figure><p>Results show once more that <em>cuSignal</em> has potential to optimize processing tasks. Runtime computing of the <em>PSD </em>with <em>cuSignal </em>can increase by a factor of 50. The resulting spectrum can be seen in Fig. 8.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cEF5CFh5GbPjIJKFgQECQA.png" /><figcaption>Figure 8 — PSD plot (“Image by author”).</figcaption></figure><h3><strong>Summary and Future Work</strong></h3><p>As expected, the results demonstrate the potential of these <em>APIs</em> with GPU support for signal processing, whether for post-acquisition analysis or real-time applications, although the last are still preferentially treated with low-level code for high acquisition rate signals. The results shown may be slightly different depending on the hardware and software that each user holds, but it is sufficient to provide a general perspective.</p><p>As future work, it would be interesting to compare these high-level implementations with <em>C</em> and <em>C++</em> functions in order to extract all the information about the capacity of the presented <em>APIs</em>. Additionally, as a suggestion for the reader, one may substitute the used <em>wav</em> file with a higher sample frequency signal ( &gt; 100 <em>MHz</em>) and different <em>FFT</em> parameters, performing a new benchmark.</p><p>Feel free to give any suggestions regarding this work.</p><h3><strong>References</strong></h3><p><strong>[1] </strong>Hohyub Jeon, Yongchul Jung, Seongjoo Lee and Yunho Jung, “<a href="https://www.researchgate.net/publication/346243843_Area-Efficient_Short-Time_Fourier_Transform_Processor_for_Time-Frequency_Analysis_of_Non-Stationary_Signals"><em>Area-Efficient Short-Time Fourier Transform Processor for Time–Frequency Analysis of Non-Stationary Signals</em></a>”, Applied Sciences, 2020;</p><p><strong>[2] </strong>M. Solomon, “<a href="https://www.osti.gov/biblio/5688766-psd-computations-using-welch-method-power-spectral-density-psd"><em>PSD computations using Welch’s method</em></a><em>”, </em>U.S. Department of Energy, 1991.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=767b79af7f41" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/accelerated-signal-processing-with-gpu-support-767b79af7f41">Accelerated Signal Processing with GPU support</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>
    </channel>
</rss>