Signal Processing - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : System : Information : Updates : Maple 17 : Signal Processing

Signal Processing

 

 

Introduction

Application: Imaging a Speech Spectrogram

Application: Filtering Audio

See Also

Introduction

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.

withSignalProcessingEngine

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

(1.1)

Application: Imaging a Speech Spectrogram

Import Wave File and Manipulate Data into Overlapping Slices

withplots:

filenameFileTools:-JoinPathkerneloptsdatadir,audio,maplesim.wav

filename:=C:\Program Files\Maple 18\data\audio\maplesim.wav

(2.1.1)

data:=AudioTools:-Readfilename

samplingRate:=attributesdata1 

samplingRate:=11025

(2.1.2)

len:=evalfnumelemsdatasamplingRate

len:=0.7462131519

(2.1.3)

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:=floor2numelemsdatasamps1

nTimes:=63

(2.1.4)

sampleMatrixsamps,nTimes, i,jdatai+j1*samps/2,datatype=float8;

Calculate the Spectrogram Data

Filter the data, slice by slice.

aseqHannWindowsample..,i,i=1..nTimes:

 

Calculate FFT of time segment consecutively.

FFTaseqFFTai,..,i=1..nTimes:

 

Calculate Power Spectrum of each slice consecutively.

spectraseqsqrt~PowerSpectrumFFTai,..,i=1..nTimes:

 

Convert spectrum into decibels.

dB:=x→20log10x:

spectra:=mapdB,spectra:

 

Strip out the repeated data.

sim:=LinearAlgebra:-SubMatrixℜspectra,1..nTimes,1..samps2+1:

nFreqs:=LinearAlgebra:-ColumnDimensionsim

nFreqs:=129

(2.2.1)

The frequencies go from 0 to half the sampling rate. Hence the frequencies are in steps of (in Hz):

samplingRate2.nFreqs

42.73255814

(2.2.2)

Scale the spectra so that the values are between 0 and 255.

minSim:=minsim

minSim:=111.188885238739

(2.2.3)

maxSim:=maxsim

maxSim:=4.43801796851939

(2.2.4)

scale:=i→iminSim255maxSimminSim:

 

Consecutive rows represent slices in time, while columns contain the spectra at each time.

simScaledscale~sim;

Plot the Spectrogram and Waveform

commonPlotOpts1labelfont=Helvetica,labeldirections=horizontal,vertical:

p1:=listdensityplotsimScaled,style=patchnogrid,smooth=true,tickmarks=,seqi=roundsamplingRatei102000.nFreqs10.,i=0..nFreqs,25,labels=,Frequency (kHz),commonPlotOpts1:

p2:=listplotseqisamplingRate,datai,i=1..numelemsdata,thickness=0,gridlines,axes=boxed,labels=Time (s),Amplitude,commonPlotOpts1:

displayArrayp1,p2,aligncolumns=1

Application: Filtering Audio

Import Speech Sample

filename2FileTools:-JoinPathkerneloptsdatadir,audio,MapleSimMono11025.wav

filename2:=C:\Program Files\Maple 18\data\audio\MapleSimMono11025.wav

(3.1.1)

originalSpeech:=AudioTools:-Readfilename2

Plot Waveform and Power Spectrum

commonPlotOpts2titlefont=Helvetica,12,labelfont=Helvetica,labeldirections=horizontal,vertical,axis=gridlines=color=SteelBlue:

samplingRateattributesoriginalSpeech1

samplingRate:=11025

(3.2.1)

duration:=evalfAudioTools:-DurationoriginalSpeech

duration:=4.504671202

(3.2.2)

p1:=plots:-listplotseqisamplingRate,originalSpeechi,i=1..numelemsoriginalSpeech,thickness=0,gridlines,axes=boxed,title=Original Speech,labels=Time (s),Waveform,commonPlotOpts2:

plots:-displayp1

fq:=FFToriginalSpeech1..215:

psq:=PowerSpectrumfq:

ps1:=plots:-pointplotseqisamplingRate215,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:-displayps1

 

Apply IIR Butterworth or Chebyshev Filter

Apply Filter

fc:=800:

taps:=GenerateButterworthTaps9,fcsamplingRate,'filtertype'='lowpass','normalize'=true

filteredSpeech:=InfiniteImpulseResponseFilteroriginalSpeech,taps:

View Before and After Power Spectrum and Waveform

FFTfilteredSpeech:=FFTfilteredSpeech1..215:

PSfilteredSpeech:=PowerSpectrumFFTfilteredSpeech:

ps2:=plots:-pointplotseqisamplingRate215,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:-displayArrayps1|ps2

p2:=plots:-listplotseqisamplingRate,filteredSpeechi,i=1..numelemsoriginalSpeech,thickness=0,gridlines,axes=boxed,color=black,title=Filtered Speech,labels=Time (s),Waveform,commonPlotOpts2:

plots:-displayArrayp1|p2,view=0..duration,1..1

Apply FIR Filter

Apply Filter

flow:=200:

fhigh700: # Critical frequency

taps:=GenerateFiniteImpulseResponseFilterTaps50,flowsamplingRate,fhighsamplingRate,filtertype=bandpass:

filteredSpeech:=FiniteImpulseResponseFilteroriginalSpeech,taps:

View Before and After Power Spectrum and Waveform

FFTfilteredSpeech:=FFTfilteredSpeech1..215:

PSfilteredSpeech:=PowerSpectrumFFTfilteredSpeech:

ps2:=plots:-pointplotseqisamplingRate215,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:-displayArrayps1|ps2

p2:=plots:-listplotseqisamplingRate,filteredSpeechi,i=1..numelemsoriginalSpeech,thickness=0,gridlines,axes=boxed,color=black,title=Filtered Speech,labels=Time (s),Waveform,commonPlotOpts2:

plots:-displayArrayp1|p2,view=0..duration,1..1

 

See Also

 Signal Processing Package Overview