Signal Processing
Introduction
Application: Imaging a Speech Spectrogram
Application: Filtering Audio
See Also
The new Signal Processing package in Maple 17 offers a suite of tools for frequency domain analysis, windowing, signal generation & analysis, and more. This document explores several applications of some of the functionality.
with⁡SignalProcessingEngine
AutoCorrelation,BartlettWindow,BlackmanWindow,Conjugate,ConjugateFlip,Convolution,CrossCorrelation,DCT,DFT,DWT,DotProduct,DownSample,FFT,FiniteImpulseResponseFilter,GenerateButterworthTaps,GenerateChebyshev1Taps,GenerateFiniteImpulseResponseFilterTaps,GenerateGaussian,GenerateJaehne,GenerateSlope,GenerateTone,GenerateTriangle,GenerateUniform,HammingWindow,HannWindow,InfiniteImpulseResponseFilter,InverseDCT,InverseDFT,InverseDWT,InverseFFT,KaiserWindow,Magnitude,Maximum,MaximumEvery,Mean,MeanStandardDeviation,Minimum,MinimumEvery,MinimumMaximum,Norm,NormDifference,Phase,PowerSpectrum,StandardDeviation,Sum,Threshold,UpSample
Import Wave File and Manipulate Data into Overlapping Slices
withplots:
filename≔FileTools:-JoinPathkerneloptsdatadir,audio,maplesim.wav
filename:=C:\Program Files\Maple 18\data\audio\maplesim.wav
data:=AudioTools:-Read⁡filename
samplingRate:=attributes⁡data1
samplingRate:=11025
len:=evalf⁡numelems⁡datasamplingRate
len:=0.7462131519
Slice the data into segments with 256 samples. Each slice has a 50% overlap with the previous slice (that is, each slice starts at the half-way point of the previous slice).
samps:=256:
nTimes:=floor⁡2⁢numelems⁡datasamps−1
nTimes:=63
sample≔Matrixsamps,nTimes, i,j→datai+j−1*samps/2,datatype=float8;
Calculate the Spectrogram Data
Filter the data, slice by slice.
a≔seqHannWindowsample..,i,i=1..nTimes:
Calculate FFT of time segment consecutively.
FFTa≔seqFFTai,..,i=1..nTimes:
Calculate Power Spectrum of each slice consecutively.
spectra≔seqsqrt~PowerSpectrumFFTai,..,i=1..nTimes:
Convert spectrum into decibels.
dB:=x→20⁢log10⁡x:
spectra:=map⁡dB,spectra:
Strip out the repeated data.
sim:=LinearAlgebra:-SubMatrix⁡ℜ⁡spectra,1..nTimes,1..samps2+1:
nFreqs:=LinearAlgebra:-ColumnDimension⁡sim
nFreqs:=129
The frequencies go from 0 to half the sampling rate. Hence the frequencies are in steps of (in Hz):
samplingRate2.⁢nFreqs
42.73255814
Scale the spectra so that the values are between 0 and 255.
minSim:=min⁡sim
minSim:=−111.188885238739
maxSim:=max⁡sim
maxSim:=4.43801796851939
scale:=i→i−minSim⋅255maxSim−minSim:
Consecutive rows represent slices in time, while columns contain the spectra at each time.
simScaled≔scale~sim;
Plot the Spectrogram and Waveform
commonPlotOpts1≔labelfont=Helvetica,labeldirections=horizontal,vertical:
p1:=listdensityplot⁡−simScaled,style=patchnogrid,smooth=true,tickmarks=,seq⁡i=round⁡samplingRate⁢i⋅102000.⁢nFreqs10.,i=0..nFreqs,25,labels=,Frequency (kHz),commonPlotOpts1:
p2:=listplot⁡seq⁡isamplingRate,datai,i=1..numelems⁡data,thickness=0,gridlines,axes=boxed,labels=Time (s),Amplitude,commonPlotOpts1:
display⁡Array⁡p1,p2,aligncolumns=1
Import Speech Sample
filename2≔FileTools:-JoinPathkerneloptsdatadir,audio,MapleSimMono11025.wav
filename2:=C:\Program Files\Maple 18\data\audio\MapleSimMono11025.wav
originalSpeech:=AudioTools:-Read⁡filename2
Plot Waveform and Power Spectrum
commonPlotOpts2≔titlefont=Helvetica,12,labelfont=Helvetica,labeldirections=horizontal,vertical,axis=gridlines=color=SteelBlue:
samplingRate≔attributesoriginalSpeech1
duration:=evalf⁡AudioTools:-Duration⁡originalSpeech
duration:=4.504671202
p1:=plots:-listplot⁡seq⁡isamplingRate,originalSpeechi,i=1..numelems⁡originalSpeech,thickness=0,gridlines,axes=boxed,title=Original Speech,labels=Time (s),Waveform,commonPlotOpts2:
plots:-display⁡p1
fq:=FFT⁡originalSpeech1..215:
psq:=PowerSpectrum⁡fq:
ps1:=plots:-pointplot⁡seq⁡i⁢samplingRate215,psqi,i=1..2152,thickness=0,color=black,gridlines,connect=true,title=Power Spectrum of Original Speech, labels=Frequency (Hz),Power,view=100..2000,0..1.6,axis1=mode=log,commonPlotOpts2:
plots:-display⁡ps1
Apply IIR Butterworth or Chebyshev Filter
Apply Filter
fc:=800:
taps:=GenerateButterworthTaps⁡9,fcsamplingRate,'filtertype'='lowpass','normalize'=true
filteredSpeech:=InfiniteImpulseResponseFilter⁡originalSpeech,taps:
View Before and After Power Spectrum and Waveform
FFTfilteredSpeech:=FFT⁡filteredSpeech1..215:
PSfilteredSpeech:=PowerSpectrum⁡FFTfilteredSpeech:
ps2:=plots:-pointplot⁡seq⁡i⁢samplingRate215,PSfilteredSpeechi,i=1..2152,thickness=0,color=black,gridlines,connect=true,title=Power Spectrum of Filtered Speech,labels=Frequency (Hz),Power,view=100..2000,0..1.6,axis1=mode=log,commonPlotOpts2:
plots:-display⁡Array⁡ps1|ps2
p2:=plots:-listplot⁡seq⁡isamplingRate,filteredSpeechi,i=1..numelems⁡originalSpeech,thickness=0,gridlines,axes=boxed,color=black,title=Filtered Speech,labels=Time (s),Waveform,commonPlotOpts2:
plots:-display⁡Array⁡p1|p2,view=0..duration,−1..1
Apply FIR Filter
flow:=200:
fhigh≔700: # Critical frequency
taps:=GenerateFiniteImpulseResponseFilterTaps⁡50,flowsamplingRate,fhighsamplingRate,filtertype=bandpass:
filteredSpeech:=FiniteImpulseResponseFilter⁡originalSpeech,taps:
Signal Processing Package Overview
Download Help Document