 MaplePortal/SignalProcessing - Maple Help

 Signal Processing

Maple's SignalProcessing package offers tools for FFTs, DFTs, wavelet analysis, IIR and FIR filters, signal generation, spectrograms and more.

 Example - Identifying Signal Frequencies from a Spectrogram and Periodogram

 > $\mathrm{with}\left(\mathrm{SignalProcessing}\right):$

Here, we will identify the frequencies of an artificially generated signal. The signal will be a sum of two sinusoids with frequencies of 12 Hz and 24 Hz.

 > $N≔{2}^{10}:\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\mathrm{samplingRate}≔100:\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\mathrm{signal}≔\mathrm{Vector}\left(N,i↦\mathrm{sin}\left(\frac{12.\cdot 2\cdot \mathrm{π}\cdot i}{\mathrm{samplingRate}}\right)+1.5\mathrm{sin}\left(\frac{24.\cdot 2\cdot \mathrm{π}\cdot i}{\mathrm{samplingRate}}\right),\mathrm{datatype}={\mathrm{float}}_{8}\right):$

Plot the spectrogram and periodogram

 > $\mathrm{Spectrogram}\left(\mathrm{signal},\mathrm{samplerate}=\mathrm{samplingRate},\mathrm{size}=\left[1000,200\right]\right)$ > $\mathrm{Periodogram}\left(\mathrm{signal},\mathrm{samplerate}=\mathrm{samplingRate},\mathrm{size}=\left[1000,200\right]\right)$ The spectrogram and power spectrum correctly identifies the two frequencies used to generate the original data.

 Example - Filtering Audio

First import the audio

 > $\mathrm{file}≔\mathrm{cat}\left(\mathrm{kernelopts}\left(\mathrm{datadir}\right),"//audio//MapleSimMono11025.wav"\right):$
 > $\mathrm{originalSpeech}≔\mathrm{AudioTools}:-\mathrm{Read}\left(\mathrm{file}\right)$
 ${\mathrm{originalSpeech}}{≔}\left[\begin{array}{cc}{"Sample Rate"}& {11025}\\ {"Bit Depth"}& {16}\\ {"Channels"}& {1}\\ {"Points/Channel"}& {49664}\\ {"Duration"}& {4.50}{}{s}\end{array}\right]$ (1)

 > $\mathrm{samplingRate}≔\mathrm{attributes}\left(\mathrm{originalSpeech}\right)\left[1\right]$
 ${\mathrm{samplingRate}}{≔}{11025}$ (2)
 > $\mathrm{Spectrogram}\left(\mathrm{originalSpeech},\mathrm{size}=\left[1000,200\right],\mathrm{reduceplot}=1\right)$ > $\mathrm{Periodogram}\left(\mathrm{originalSpeech},\mathrm{size}=\left[1000,200\right],\mathrm{reduceplot}=4\right)$ Now let's apply a Butterworth filter to the audio. Define the critical frequency, generate the filter taps, and apply the filter.

 > $\mathrm{fc}≔800:$
 > $\mathrm{taps}≔\mathrm{GenerateButterworthTaps}\left(9,\frac{\mathrm{fc}}{\mathrm{samplingRate}},'\mathrm{filtertype}'='\mathrm{lowpass}',\right):\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\mathrm{filteredSpeech}≔\mathrm{InfiniteImpulseResponseFilter}\left(\mathrm{originalSpeech},\mathrm{taps}\right):\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}$

Then generate the spectrogram and periodogram

 > $\mathrm{Spectrogram}\left(\mathrm{filteredSpeech},\mathrm{samplerate}=\mathrm{samplingRate},\mathrm{size}=\left[1000,200\right],\mathrm{reduceplot}=1\right)$ > $\mathrm{Periodogram}\left(\mathrm{filteredSpeech},\mathrm{samplerate}=\mathrm{samplingRate},\mathrm{size}=\left[1000,200\right]\right)$ You can also export the filtered audio

 > $#\mathrm{A≔AudioTools:-Create}\left(\mathrm{filteredSpeech},\mathrm{rate}=11025\right);\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}#\mathrm{AudioTools:-Write}\left("IIRtest.wav",\mathrm{A}\right)$

 Applications   FIR and IIR Filters  Spectrogram Examples