如何在Python中加速信号处理
如何在Python中加速信号处理
This post is the eighth installment of the series of articles on the RAPIDS ecosystem. The series explores and discusses various aspects of RAPIDS that allow its users solve ETL (Extract, Transform, Load) problems, build ML (Machine Learning) and DL (Deep Learning) models, explore expansive graphs, process signal and system log, or use SQL language via BlazingSQL to process data.
You may or may not be aware that every bit of information your computer has received from a server miles away, every pixel your screen has shown, or every tune your speakers has produced was some form of a signal that was sent over a ‘wire’. That signal was most likely encoded by the sender end so it could carry the information and the receiver side decoded it for further usage.
本文介绍RAPIDS生态系统系列。该系列探讨并讨论了RAPIDS的各个方面,这些方面使RAPIDS的用户可以解决ETL(提取,转换,加载)问题,构建ML(机器学习)和DL(深度学习)模型,探索膨胀图,过程信号和系统日志,或者通过BlazingSQL使用SQL语言处理数据。
可能会或可能不会意识到,计算机从一英里之外的服务器接收到的每点信息,屏幕上显示的每个像素或扬声器产生的每个音调都是通过“电线”发送的某种信号。该信号最有可能是由发送方编码的,因此可以携带信息,而接收方则对其进行解码以备将来使用。
信号丰富:音频,无线电或其它电磁波(例如伽马,红外或可见光),无线通信,海浪等。这些波浪中有一些是人造的,许多是自然产生的。甚至图像或股市时间序列也可以被视为信号。
cuSignal是RAPIDS库生态系统的更新版本。旨在分析和处理任何形式的信号,并在scikit-learn信号库之后进行了紧密建模。与scikit-learn不同,cuSignal将NVIDIA GPU的功能带到信号处理中,从而导致计算速度提高了几个数量级。
Signals are abundant: audio, radio or other electromagnetic waves (like gamma, infrared or visible light), wireless communications, ocean wave, and so on. Some of these waves are man-made, many are produced naturally. Even images or stock market time series can be seen and processed as signals.
cuSignal is a newer addition to the RAPIDS ecosystem of libraries. It is aimed at analyzing and processing signals in any form and is modeled closely after the scikit-learn signal library. However, unlike scikit-learn, cuSignal brings the power of NVIDIA GPUs to signal processing resulting in orders-of-magnitude increase in speed of computations.
In this post, we will introduce and showcase the most common functionality of RAPIDS cuSignal. As with the other libraries we already discussed, to help with getting familiar with cuSignal, we provide a cheat sheet that can be downloaded here: cuSignal cheatsheet, and an interactive notebook with all the current functionality of cuSignal showcased.
本文将介绍并展示RAPIDS cuSignal的最常用功能。与已经讨论过的其它库一样,为了帮助熟悉cuSignal,提供了一个备忘单,可以下载:cuSignal备忘单,以及展示 cuSignal所有当前功能的交互式笔记本。
Frequency
One of the most fundamental properties of signals is frequency. Hertz (abbreviated Hz) is a fundamental unit of frequency defined as a single cycle per second; it was named after Heindrich Rudolf Hertz who provided conclusive proof of the existence of electromagnetic waves. Any signal we detect or store is closely related to time: you could probably safely argue that any signal is a time series with ‘slightly’ different tools to analyze it.
The Alternating Current (AC) supplied to each home is an electric current that oscillates at either 50Hz or 60Hz, audio signals normally cover roughly the spectrum between 20Hz – 20,000Hz (or 20kHz), mobile bands cover some narrow bands in 850-900MHz, 1800Mhz (1.8GHz) and 1900MHz, Wifi signals oscillate at some predefined frequencies around either 2.4GHz or 5GHz. And these are but a few examples of signals that surround us. Ever heard of radio telescopes? The Wilkinson Microwave Anisotropy Probe is capable of scanning the night sky and detecting signals centered around 5 high-frequency bands: 23 GHz, 33 GHz, 41 GHz, 61 GHz, and 94 GHz, helping us to understand the beginnings of our universe. However, this is still just in the middle of the spectrum of electromagnetic waves.
信号的最基本特性之一是频率。赫兹(缩写为Hz)是频率的基本单位,定义为每秒一个周期。以Heindrich Rudolf Hertz的名字命名,后者为电磁波的存在提供了确凿的证据。检测到或存储的任何信号都与时间密切相关:可能可以肯定地说,任何信号都是一个 时间序列, 使用“略有不同”的工具进行分析。
提供给每个家庭的交流电(AC)是一种以50Hz或60Hz振荡的电流,音频信号通常覆盖20Hz-20,000Hz(或20kHz)之间的频谱,移动频段覆盖850-900MHz的一些窄带, 1800Mhz(1.8GHz)和1900MHz,Wifi信号以2.4 GHz或5 GHz附近的一些预定义频率振荡。这些只是围绕信号的一些示例。听说过射电望远镜吗?威尔金森微波各向异性探测器能够扫描夜空和检测信号围绕着5高频带的:23千兆赫,33千兆赫,41千兆赫,61千兆赫和94千兆赫,从而帮助了解宇宙的开端。但是,仍处于电磁波频谱的中间。
Figure 1: Source: Electromagnetic spectrum, https://www.nasa.gov/directorates/heo/scan/spectrum/txt_electromagnetic_spectrum.html
Digital or analog
In the early 20th century, almost all signals we dealt with were analog. Amplifying or recording speech or music was done on tapes and through fully analog signal paths using vacuum tubes, transistors, or, nowadays, operational amplifiers. However, the storage and reproduction of signals (music or else) have changed with the advent of Digital Signal Processing (or DSP). Still, remember CDs? Even if not, the music today is stored as a string of zeros and ones. However, when you play a song, the signal that drives the speaker is analog. In order to play an MP3, the signal needs to be converted from digital to analog and this can be achieved by passing it through the Digital-to-Analog converter (DAC): then the signal can be amplified and played through the speaker. The reverse process happens when you want to save the signal in a digital format: an analog signal is passed through an Analog-to-Digital converter (ADC) that digitizes the signal.
With the emergence of the high-speed Internet and 5th Generation mobile networks, signal analysis and processing has become a vital tool in many domains. cuSignal brings the processing power of NVIDIA GPUs into this domain to help with the current and emerging demands of the field.
在20世纪初,处理几乎所有信号都是模拟信号。使用磁带,晶体管或当今的运算放大器,在磁带上通过完全模拟的信号路径来放大或记录语音或音乐。但是,随着数字信号处理(或DSP)的出现,信号(音乐或其它)的存储和再现已发生了变化。还是记得CD吗?即使不是,今天的音乐也存储为零和一串。但是,当播放歌曲时,驱动扬声器的信号是模拟信号。为了播放MP3,需要将信号从数字转换为模拟,可以将其通过数模转换器(DAC)来实现:然后可以将信号放大并通过扬声器播放。当以数字格式保存信号时,将发生相反的过程:数字化信号。
随着高速互联网和第五代移动网络的出现,信号分析和处理已成为许多领域的重要工具。cuSignal将NVIDIA GPU的处理能力带入了这一领域,以帮助满足该领域的当前和新兴需求。
Convolution
One of the most fundamental tools to analyze signals and extract meaningful information is convolution. Convolution is a mathematical operation that takes two signals and produces a third one, filtered. In the signal processing domain, convolution can be used to filter some frequencies from the spectrum of the signal to better isolate or detect some interesting properties. Just like in Convolutional Neural Networks, where the network learns different kernels to sharpen, blur or otherwise extract interesting features from an image to, for example, detect objects, the signal convolutions use different windows that help to refine the signal.
Let’s assume that we have a digital signal that looks as below.
卷积是分析信号和提取有意义的信息的最基本工具之一。卷积是一种数学运算,需要两个信号并产生第三个信号(经过滤波)。在信号处理领域,可以使用卷积从信号频谱中滤除某些频率,以更好地隔离或检测一些有趣的属性。就像在卷积神经网络中一样,该网络学习不同的内核以锐化,模糊或以其它方式从图像中提取有趣的特征以(例如)检测对象,信号卷积使用不同的窗口来帮助改善信号。
假设有一个如下所示的数字信号。
Figure 2: Sample signal with an exponentially decaying noise component.
The signal above is a 2 Vrms (Root Mean Squared) a sine wave with its frequency slowly modulated around 3kHz, corrupted by the white noise of exponentially decreasing magnitude sampled at 10 kHz. To see the effect different windows would have on this signal, we will use Hamming and Dolph-Chebyshev windows.
上面的信号是一个2 Vrms(均方根)正弦波,其频率在3kHz左右缓慢调制,并被在10 kHz采样的幅度呈指数下降的白噪声破坏。为了查看不同窗口对信号的影响,将使用 Hamming 和 Dolph-Chebyshev 窗口。
window_hamming = cusignal.hamming(51)
window_chebwin = cusignal.chebwin(51, at=100)
filtered_hamming = cusignal.convolve(
data
, window_hamming
, method='direct'
) / cp.sum(window_hamming)
filtered_chebwin = cusignal.convolve(
data
, window_chebwin
, method='direct'
) / cp.sum(window_chebwin)
Figure 3: Effects of applying Hamming and Dolph-Chebyshev windows on the original signal.
On the right, you can see the difference between the two windows. They are of similar shape but the Dolph-Chebyshev window is narrower and is effectively a more narrow band-pass filter compared to the Hamming window. Both of these methods can definitely help to find the fundamental frequency in the data.
For a full list of all the windows supported in cuSignal, refer to the cheat sheet you can download cuSignal cheatsheet, or try any of them in an interactive cuSignal notebookhere.
在右侧,可以看到两个窗口之间的区别。具有相似的形状,但是与汉明窗相比,Dolph-Chebyshev窗更窄,并且实际上是更窄的带通滤波器。这两种方法绝对可以帮助找到数据中的基本频率。
有关cuSignal支持的所有窗口的完整列表,请参考备忘单,可以下载cuSignal备忘单,或在交互式cuSignal笔记本中尝试其中的任何一种。
Spectral analysis
While filtering the signal using convolution might help to find the fundamental frequency of 3KHz, it does not show if (and how) that frequency might change over time. However, spectral analysis should allow us to do just that.
尽管使用卷积对信号进行滤波可能有助于找到3KHz的基本频率,但并未显示该频率是否(以及如何)随时间变化。但是,频谱分析应该允许做到这一点。
f, t, Sxx = cusignal.spectrogram(x, fs)
plt.pcolormesh(
cp.asnumpy(t),
cp.asnumpy(f),
cp.asnumpy(Sxx)
)
plt.ylabel('Frequency [Hz]') plt.xlabel('Time [sec]')
The above code produces the following chart:
Figure 4: Spectrogram of slowly 3Hz signal with a compound 0.25Hz oscillation.
We can now clearly see not only the fundamental frequency of 3kHz is slowly, at 0.25Hz, modulated slightly over time, but we can also observe the initial influence of the white noise shown as lighter blue dots.
With the introduction of cuSignal, the RAPIDS ecosystem gained another great package with a vast array of signal processing tools that can be applied in many domains. You can try the above examples and more for yourself at app.blazingsql.com, and download the cuSignal cheat sheethere!
现在可以清楚地看到,不仅3kHz的基频在0.25Hz处缓慢变化,而且随着时间的流逝略有调制,还可以观察到白噪声的初始影响,显示为较亮的蓝点。
随着cuSignal的引入,RAPIDS生态系统获得了又一个伟大的软件包,具有可应用于许多领域的大量信号处理工具。可以在app.blazingsql.com上尝试上述示例以及更多示例,并下载cuSignal备忘单!
如何在Python中加速信号处理的更多相关文章
- 如何在Python中从零开始实现随机森林
欢迎大家前往云+社区,获取更多腾讯海量技术实践干货哦~ 决策树可能会受到高度变异的影响,使得结果对所使用的特定测试数据而言变得脆弱. 根据您的测试数据样本构建多个模型(称为套袋)可以减少这种差异,但是 ...
- 如何在Python中快速画图——使用Jupyter notebook的魔法函数(magic function)matplotlib inline
如何在Python中快速画图--使用Jupyter notebook的魔法函数(magic function)matplotlib inline 先展示一段相关的代码: #we test the ac ...
- 如何在Python中使用Linux epoll
如何在Python中使用Linux epoll 内容 介绍 阻塞套接字编程示例 异步套接字和Linux epoll的好处 epoll的异步套接字编程示例 性能考量 源代码 介绍 从2.6版开始,Pyt ...
- 如何在Python 中使用UTF-8 编码 && Python 使用 注释,Python ,UTF-8 编码 , Python 注释
如何在Python 中使用UTF-8 编码 && Python 使用 注释,Python ,UTF-8 编码 , Python 注释 PIP $ pip install beauti ...
- 面试官问我:如何在 Python 中解析和修改 XML
摘要:我们经常需要解析用不同语言编写的数据.Python提供了许多库来解析或拆分用其他语言编写的数据.在此 Python XML 解析器教程中,您将学习如何使用 Python 解析 XML. 本文分享 ...
- 如何在python中使用Elasticsearch
什么是 Elasticsearch 想查数据就免不了搜索,搜索就离不开搜索引擎,百度.谷歌都是一个非常庞大复杂的搜索引擎,他们几乎索引了互联网上开放的所有网页和数据.然而对于我们自己的业务数据来说 ...
- 如何在Python中实现这五类强大的概率分布
R编程语言已经成为统计分析中的事实标准.但在这篇文章中,我将告诉你在Python中实现统计学概念会是如此容易.我要使用Python实现一些离散和连续的概率分布.虽然我不会讨论这些分布的数学细节,但我会 ...
- 如何在Python中调用Matlab
检查您的系统是否具有受支持的 Python 版本和 MATLAB R2014b 或更新版本.要检查您的系统上是否已安装 Python,请在操作系统提示符下运行 Python. 1)打开Prompt,输 ...
- 如何在python中调用C语言代码
1.使用C扩展CPython还为开发者实现了一个有趣的特性,使用Python可以轻松调用C代码 开发者有三种方法可以在自己的Python代码中来调用C编写的函数-ctypes,SWIG,Python/ ...
随机推荐
- Selenium3自动化测试【15】元素定位之Class、Name
@ 目录 1.name定位 2.class定位 1.name定位 通过name定位是另外一种常用的定位元素的方式. 当一个元素存在name属性时,可以使用name定位,依旧以Bing搜索框为例(nam ...
- 13- APP接口测试以及postman使用
postman安装与操作 ---------------------- 接口操作图片 -------------------- 一.postman操作key值:来源于聚合 请求-->聚合-- ...
- 路由器逆向分析------QEMU的下载和安装(Linux平台)
本文博客地址:http://blog.csdn.net/qq1084283172/article/details/68953160 一.QEMU源码的下载和编译 QEMU源码的github下载地址:h ...
- Python小游戏 -- 猜数字
Python初学者小游戏:猜数字 游戏逻辑:电脑随机生成一个数字,然后玩家猜数字,电脑提示猜的数字大了还是小了,供玩家缩小数字范围,达到既定次数后,玩家失败.若在次数内猜对,玩家获胜. 涉及知识点:r ...
- Windowsw核心编程 第13章 Windows内存结构
第1 3章 Wi n d o w s的内存结构 13.1 进程的虚拟地址空间 每个进程都被赋予它自己的虚拟地址空间.对于 3 2位进程来说,这个地址空间是4 G B,因为3 2位指针可以拥有从0 x ...
- Portswigger web security academy:WebSockets
Portswigger web security academy:WebSockets 目录 Portswigger web security academy:WebSockets Lab: Mani ...
- C++ Socket 简单封装
以下代码一部分来自于<网络多人游戏架构与编程>, 其它的都是我瞎写的. 备忘. 一个简单的Socket封装,没有做什么高级的操作(比如IO完成端口等等). 1 #pragma once 2 ...
- Ubuntu20.04连接WiFi
电脑安装了Ubuntu20.04后发现没办法连接WiFi,也找不到WiFi图标,一般来说是因为Ubuntu系统没有网卡驱动,安装一下即可 解决办法如下: 先用网线或者手机开热点连接到到电脑,让电脑有网 ...
- 全套Project版本安装教程及下载地址
1:Project 2007 安装教程及下载地址 https://mp.weixin.qq.com/s/8iI7x1qjon0yAdo3bStjzw 2:Project 2010 安装教程及下载地址 ...
- DWVA--File Inclusion
文件包含漏洞 先来了解一下什么是文件包含 因为程序开放人员通常会把可重复使用的函数写到单个文件中,在需要使用到这些函数时候,就可以 直接调用这个文件,这种对文件的调用过程就被称为文件包含. 文件包含漏 ...