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 2019 : Signal Processing

Signal and Image Processing

 

Frequency Spectrum of Irregularly Sampled Data

FindPeakPoints

Spectrogram

Real and Complex Cepstrum

FFTShift

Edge Detect

ImagePeriodogram

More Updates

Frequency Spectrum of Irregularly Sampled Data

The new LSPeriodogram command uses the Lomb-Scargle technique to generate a periodogram of data sampled at irregular time intervals. This is in contrast to the standard Fourier approach (such as that used in Periodogram) which requires regularly sampled data.

withSignalProcessing:

Generate an irregularly spaced vector of times

tsortLinearAlgebra:-RandomVector210,generator=0..36.0, datatype=float8

Generate a signal using frequencies of 1 Hz and 8 Hz

f11.0:f28.0:

sVector210,i→sinf12πti+1.5sinf22πti,datatype=float8

Generate a periodogram assuming that the signal is sampled at each point in the irregularly spaced time vector

LSPeriodogramt,s,frequencyscale=Hz, size  = 800,300

Several options allow you to specify the frequencies over which the periodogram is generated, the normalization and more. Additionally, you can also generate the numerical data used to create this plot with the LSSpectrum command.

LSSpectrumt,s

 

FindPeakPoints

The new FindPeakPoints command finds the peaks and valleys of 1D data sets. This versatile command offers several options that let you filter out peaks or valleys that are too close, what defines a peak or valley, and more.

Here, we find the fundamental frequency and harmonics of a violin note by locating the peak points of its periodogram. This speaker component is needed to play audio:

First import, play the data, and view the power spectrum.

violinNote  AudioTools:-ReadFileTools:-JoinPathkerneloptsdatadir, audio, ViolinThreePosVibrato.wav..,1;AudioTools:-PlayviolinNote

violinNoteSample Rate44100Bit Depth16Channels1Points/Channel64724Duration1.47s

(2.1)

violinPeriodogramPeriodogramviolinNote,powerscale=dB:plots:-displayviolinPeriodogram,size=800,300,view=0..10000,default

Now isolate the peak points on the periodogram, while filtering out any spurious peaks.

periodogramDataplottools:-getdataviolinPeriodogram3:peakPointsFindPeakPointsperiodogramData,minimumheight=40,minimumprominence=40,includeendpoints=false

Overlay the peak points over the periodogram

peakPlotplotpeakPoints,style=point,symbol=solidcircle, symbolsize=15:plots:-displaypeakPlot,violinPeriodogram,view=1..10000,default,  size = 800,300

The fundamental frequency of the violin note is the first frequency in peakPoints (987.8 Hz). The other values are the harmonics (which are approximately integer multiples of the fundamental frequency)

peakPoints2..,1/~peakPoints1,1

Spectrogram

You can now specify the overlap when generating a spectrogram (in prior releases, the overlap was fixed at 50%).

Increasing overlap increases frequency resolution, but at the expense of lower time resolution. In other words, increasing overlap will reveal smaller time events, but will smear those events over time. Increasing overlap also increases computation time because there are more time slices to analyze.

 

Here, we import an audio file and generate a spectrogram with overlaps of 10% and 90%.

 

audAudioTools:-ReadFileTools:-JoinPathkerneloptsdatadir, audio,maplesim.wav

audSample Rate11025Bit Depth16Channels1Points/Channel8227Duration0.75s

(3.1)

Spectrogramaud,overlap=0.1,fftsize=256,size=800,300

Spectrogramaud,overlap=0.90,fftsize=256,size=800,300

 

Real and Complex Cepstrum

Maple 2019 features new commands for calculation the real cepstrum, complex cepstrum and inverse complex cepstrum of a signal. These have many applications in seismic analysis, the characterisation of explosions, speech analysis, homomorphic filtering, and more.

In this example, the location of an echo in an audio file is found using the RealCepstrum command; this information is used to remove the echo with an IIR filter.

echoAudioAudioTools:-ReadFileTools:-JoinPathkerneloptsdatadir, audio,ding_echo.wav;FsattributesechoAudio1

echoAudioSample Rate22050Bit Depth16Channels1Points/Channel29232Duration1.33s

Fs22050

(4.1)

Play the audio - note the echo

DocumentTools:-SetPropertySpeaker0,samplerate,Fs;AudioTools:-PlayechoAudio,Speaker0

 

Vector of times for each point in the audio signal

tVectornumelemsechoAudio,i→1.0iFs:

 

Use RealCepstrum to identify start of echo

cRealCepstrumechoAudio:plott,c,view=default,0.3..0.3,labels=Quefrency (s),,labeldirections=horizontal,vertical

 

 

The cepstrum plot shows a strong peak at a quefrency of just over 0.4 s - that's probably where the echo starts. Let's find the precise location of the peak.

thresholdmapx&rarr;piecewisex<0.1&comma;0&comma;1&comma;c&colon;indArrayTools:-SearchArraythreshold&comma;4

ind27299042

(4.2)

The peak occurs at an index of 9042. Use this information to attenuate the echo with an IIR filter

filterCoeffs  Array1&comma; 0&dollar;9040&comma; 0.5&colon;cleanAudioFilterechoAudio&comma; filterCoeffs&comma;Array1&colon; 

 

Playing the audio reveals that the echo has been attenuated

AudioTools:-PlaycleanAudio&comma;Speaker0


Visualize waveform of audio before and after filtering

pltEchoAudioplott&comma;echoAudio&comma;color=DarkOliveGreen&comma;legend=Audio with echo&colon;pltCleanAudioplott&comma;cleanAudio&comma;color=black&comma;legend=Audio with echo removed&colon;plots:-displaypltEchoAudio&comma;pltCleanAudio

FFTShift

FFTShift swaps data in a matrix or a vector into a different position. For a matrix swapped about both dimensions, the quadrants are moved like so.

The Fourier transform of an image places lower frequency data near all four corners, with higher frequency data near the center. In this instance, FFTShift is typically applied to move the lowest frequencies to the center and the highest frequencies to the corners.

This results in a more meaningful visualization of the power spectrum where the lowest frequency data is contiguous, and simplifies the manipulation of frequency data

 

First, we import an image.

withImageTools&colon;imgReadFileTools:-JoinPathkerneloptsdatadir&comma; images&comma;phone.jpg&colon; Embedimg

Now, we convert from the image domain to the spatial frequency domain, move the zero-frequency data to the center, and visualize the power spectrum (the square-root scaling simply rescales the frequencies for a more meaningful visualization).

img_fourierFFTShiftFFTimg&colon;EmbedCreatesqrt~abs~img_fourier

Multiply the spatial frequencies by a Gaussian mask (this is similar to a low pass filter that attenuates higher frequency data).

nRows,nColsLinearAlgebra:-Dimensionimg&colon;img_fourier_blur  img_fourier~MatrixnRows&comma;nCols&comma;i&comma;jevalf&ExponentialE;inRows22&plus;jnCols222.0102&comma;datatype&equals;float8&colon;EmbedCreatesqrt~abs~img_fourier_blur

Move the zero frequency data back to their original positions, and then invert the spatial frequency data back to the image domain.

img_low_passRe~InverseFFTFFTShiftimg_fourier_blur&colon;EmbedFitIntensityCreateimg_low_pass

 

Edge Detect

The new EdgeDetect command applies an edge detection convolution mask to an image. The command supports several masks including Sobel, Robert, Prewitt 3x3 and Prewitt 4x4.

edge1EdgeDetectimg&comma; method &equals; Sobel&colon;EmbedFitIntensityedge1

edge2EdgeDetectimg&comma; method &equals; Prewitt4&colon;EmbedFitIntensityedge2

 

ImagePeriodogram

ImagePeriodogram calculates the magnitude of the Fourier transform of an image; this data can then be embedded as an image to visualize the spatial frequencies of the image. By default the lowest frequencies are shifted to the center (this can, however, be modified). Moreover, you can also scale the data to better visualize spatial frequencies that would otherwise not be apparent).

imgReadcatkerneloptsdatadir&comma;/images/tree.jpg&colon;Embedimg

EmbedImagePeriodogramimg

More Updates

Detrend

A new option for the SignalPlot, Periodogram and Spectrogram lets you remove a linear trend from the data, prior to the primary analysis.