updates/Maple17/SignalProcessing - Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : updates/Maple17/SignalProcessing

Signal Processing

 

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

data:= 1 .. 8227 ArrayData Type: float8Storage: rectangularOrder: C_order

(2.1.2)

samplingRate:=attributesdata1 

samplingRate:=11025

(2.1.3)

len:=evalfnumelemsdatasamplingRate

len:=0.7462131519

(2.1.4)

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.5)

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

sample:= 256 x 63 MatrixData Type: float8Storage: rectangularOrder: Fortran_order

(2.1.6)

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;

simScaled:= 63 x 129 MatrixData Type: anythingStorage: rectangularOrder: Fortran_order

(2.2.5)

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

originalSpeech:= 1 .. 49664 ArrayData Type: float8Storage: rectangularOrder: C_order

(3.1.2)

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

taps:= 1 .. 20 ArrayData Type: float8Storage: rectangularOrder: Fortran_order

(3.3.1.1)

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


Download Help Document

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam