MATLAB SignalProcessing ToolboxGreg Reese, Ph.DResearch Computing Support GroupAcademic Technology ServicesMiami UniversityOctober 2013
MATLAB SignalProcessing Toolbox 2013 Greg Reese. All rights reserved2
ToolboxToolbox Collection of code devoted to solvingproblems in one field of research Can be purchased from MATLAB Can be purchased from third parties Can be obtained for free from third parties3
ToolboxMATLAB Signal Processing Toolbox Code for solving problems in signalprocessing (!) Sold by MATLAB Part of both Miami’s student andfaculty license4
OverviewMATLAB divides Signal ProcessingToolbox as follows Waveforms– Pulses, modulated signals, peak-to-peak and RMSamplitude, rise time/fall time, overshoot/undershoot Convolution and Correlation– Linear and circular convolution, autocorrelation,autocovariance, cross-correlation, cross-covariance Transforms– Fourier transform, chirp z-transform, DCT, Hilberttransform, cepstrum, Walsh-Hadamard transform5
Overview Analog and Digital Filters– Analog filter design, frequency transformations, FIR and IIRfilters, filter analysis, filter structures Spectral Analysis– Nonparametric and parametric spectral estimation, highresolution spectral estimation Parametric Modeling and LinearPrediction– Autoregressive (AR) models, linear predictive coding (LPC),Levinson-Durbin recursion Multirate Signal Processing– Downsampling, upsampling, resampling, anti-aliasing filter,interpolation, decimation6
OverviewWill look very briefly at Analog and Digital Filters Spectral Analysis Parametric Modeling and Linear Prediction Multirate Signal ProcessingWill look in more depth at Waveforms Convolution and Correlation7
Analog and Digital FiltersToolbox especially good for those seriousabout their filter design!Analog filters Standard filters– Bessel, Butterworth, Chebyshev, Elliptic Filter transforms– Low pass to: bandpass, bandstop, or highpass– Change cutoff frequency of lowpass Analog to digital filter conversion– Bilinear transformation8
Analog and Digital FiltersDigital Filter Design with functions Standard filters– Butterworth, Chebyshev, Elliptic FIR and IIR design– Low pass to: bandpass, bandstop, or highpass– Change cutoff frequency of lowpass Objects for specification of filters– Arbitrary, lowpass, highpass, bandpass, Hilbert9
Analog and Digital FiltersDigital Filter Design interactively (GUI) Filterbuilder – specify desiredcharacteristics first, then choose filter type– Butterworth, Chebyshev, Elliptic FDATool (Filter Design and Analysis Tool)– Quickly design digital FIR or IIR filters– Quickly analyze filters, e.g., magnitude/phaseresponse, pole-zero plots10
Analog and Digital FiltersSPTool – composite of four tools1. Signal Browser – analyze signals2. FDATool3. FVTool (Filter Visualization Tool) –analyze filter characteristics4. Spectrum Viewer – spectral analysis11
Analog and Digital FiltersDigital Filter Analysis Magnitude and phase response, impulseresponse, group delay, pole-zero plotDigital Filter Implementation Filtering, direct form, lattice, biquad, statespace structures12
Spectral AnalysisNonparametric Methods– Periodogram, Welch's overlapped segmentaveraging, multitaper, cross-spectrum,coherence, spectrogramParametric Methods– Yule-Walker, Burg, covariance, modifiedcovarianceSubspace Methods– Multiple signal classification (MUSIC),eigenvectorestimator, pseudospectrum Windows– Hamming, Blackman, Bartlett, Chebyshev,Taylor, Kaiser13
Parametric Modeling andLinear PredictionParametric Modeling AR, ARMA, frequency responsemodelingLinear Predictive Waveforms Linear predictive coefficients (LPC), linespectral frequencies (LSF), reflectioncoefficients (RC), Levinson-Durbinrecursion14
Multirate Signal ProcessingMultirate signal processing– Downsampling, upsampling, resampling,anti-aliasing filter, interpolation, decimation15
WaveformsWaveforms part of toolbox lets you createmany commonly used signals, which youcan use to study models programmed inMATLABUses of waveforms Testing– E.g., have simple waveform and can analyticallydetermine model’s output. Use toolbox to create thatwaveform, run it through MATLAB model, confirmresult16
WaveformsUses of waveforms Simulation– Most of time can’t get analytical output– Make waveform of known characteristicsand study model’s response Modeling of real signals– Create waveform that looks like the realsignal17
WaveformsTime vectorsDigital signals usually sampled fromanalog at fixed intervals Δt . Want timeaxis with N points01Δt2Δt (N-2)Δt (N-1)Δt18
WaveformsFor––––tStart: starting timetEnd: ending timeN: number of pointsdeltaT: sampling interval If have starting time, number of points,interval, (tStart, N, deltaT): deltaT 0.1; N 10; t0 5; t t0 deltaT * (0:N-1)t 5.0 5.1 5.2 5.3 5.4 5.55.65.75.85.919
Waveforms If have starting time, ending time, interval(tStart, tEnd, deltaT) tStart 5; tEnd 5.9; deltaT 0.1; t tStart:deltaT:tEndt 5.0 5.1 5.2 5.3 5.45.55.65.75.85.9 If have starting time, ending time, number ofpoints (tStart, tEnd, N) tStart 5; tEnd 5.9; N 10; t linspace( tStart, tEnd, N )t 5.0 5.1 5.2 5.3 5.4 5.5 5.65.75.85.920
WaveformsIn multichannel processing, a number ofsignals are gathered at the same time Will assume all sampled at same time andsame rateSignal processing toolbox, and MATLABin general, treats each column of amatrix (2D array) as an independentcolumn vector21
WaveformsExample M [ 1:3; 4:6; 7:9; 10:12 ]M 123456789101112 mean( M )ans 5.50006.50007.5000Result is mean of each column22
WaveformsTIPMake time vector be a column vector Any vectors created from time vectorwill also be column vectors and socan be processed more easily t tt 123456 y abs( t - 3 )y 2101Column vector begeteth column vector2323
TIPWaveformsrepmat (replicate matrix) is generalpurpose function to make large matrix byreplicating small oneTrick - quick way to replicate column vector,i.e., to make an m x n matrix T out of an m x1 column vector v, isT v(:,ones(1,n)) v (1:5)v 12345 v(:,ones(1,3))ans 11122233344455524
WaveformsTIPTrick - quick way to replicate row vector,i.e., to make an m x n matrix T out of an 1 xn row vector v, isT v(ones(m,1),:) v 1:3v 1 2 32345 T v( ones(6,1), : )ans 12312312312312312325
WaveformsTIPCan use preceding two tips to makemultichannel signal, e.g.,Simulate the multichannel signalsin(2πt), sin(2πt/2), sin(2πt/3),sin(2πt/4) sampled for one secondat one-tenth second per sample26
WaveformsTIP t (0:0.1:1)'t .90001.000027
TIPWaveforms T t(:,ones(1,4))T 000.40000.50000.60000.70000.80000.90001.000028
TIPWaveforms M T ./ CM 500.10000.12500.15000.17500.20000.22500.250029
TIPWaveforms signal sin( 2*pi*Msignal 30
WaveformsImpulse Use to compute impulse responseof linear, time-invariant system t (0:0.1:1.9)'; impulse zeros( size(t) ); impulse( 1 ) 811.21.41.61.8231
WaveformsStep Use to model switch turning on t (-1:0.1:0.9)'; step [ zeros(10,1); ones(10,1) 0.200.20.40.60.8132
WaveformsRamp Use to model something gradually turning on t (0:0.1:1.9)'; ramp 1.41.61.8233
AutocorrelationAutocorrelation – the detection of a delayedversion of a signal In temporal signal, delay often called “lag” In spatial signal, delay often called“translation” or “offset” Delayed signal may also be scaledCan also think of autocorrelation assimilarity of a signal to itself as a function oflag34
AutocorrelationAutocorrelation and cross-correlation Common in both signal processingand statistics Definitions and uses are different When looking for help on thesetopics, make sure you’re looking ata signal-processing source35
AutocorrelationExamples of autocorrelation of digital signals Radar – determine distance to object Sonar – determine distance to object Music– Determine tempo– Detect and estimate pitch Astronomy – Find rotation frequency of pulsars36
AutocorrelationExamples of spatial autocorrelation Optical Character Recognition (OCR) – readingtext from images of writing/printing X-ray diffraction – helps recover the "Fourierphase information" on atom positions Statistics – helps estimate mean valueuncertainties when sampling a heterogeneouspopulation Astrophysics – used to study and characterizethe spatial distribution of galaxies37
AutocorrelationExamples of optical autocorrelation Measurement of optical spectra and of veryshort-duration light pulses produced by lasers Analysis of dynamic light scattering data todetermine particle size distributions The small-angle X-ray scattering intensity ofsome systems related to the spatialautocorrelation function of the electron density In optics, normalized autocorrelations andcross-correlations give the degree ofcoherence of an electromagnetic field38
AutocorrelationTypical use Blip sent to object Small blip reflected fromobject back to sender Use autocorrelation to detectsmall blip at some lag Know velocity of blip in medium so totaldistance blip traveled isdistance velocity * lag Distance is round trip, soobject distance/2 away39
AutocorrelationAutocorrelation Multiply and sum. Result is autocorrelation atthat point Slide over one, multiply and sum10101010xxxx000001110010 0 10 0 10 0 10 00 040
AutocorrelationAutocorrelation Repeat, sliding in both directions until havecovered all positions What happens when gopast end?10101000000111xxx00?10 0 10 0 ?41
AutocorrelationWhen go past end, have two optionsZero – padding – put zeros on both end of bothsignals. Can either imagine they are there oractually extend arrays in memory and put inzeros00000000111101010xxx0000010 0 10 0 10 0 0Will discuss second option later42
AutocorrelationSuppose the real discrete-time signal x[n] hasL points and the real discrete-time signal y[n]has N points, with L N. The autocorrelation ofx and y is𝐿 𝑚 1𝑅𝑥𝑦 𝑚 𝑥 𝑛 𝑚 𝑦[𝑛]𝑛 0for m -(N-1), -(N-2), , -1, 0, 1, 2, , L-143
AutocorrelationAside For p 0, x[n-p] is x[n]shifted to the right by p For p 0, x[n p] is x[n]shifted to the left by pExample Unit impulse1x[n]x[n 5]x[n-2]0.80.60.40.20-6-5-4-3-2-10123n1 for 𝑛 0𝑥𝑛 0 for 𝑛 044
AutocorrelationTRY ITAt time n 0 a transmitter sends out apulse of amplitude ten and duration 3.At time time n 5 it gets back thereflected pulse with the same durationbut one tenth the amplitude. What is theautocorrelation?45
AutocorrelationTRY Rxy(0) ?0011100Rxy(0) 01100Rxy(1) 01100Rxy(2) 0Rxy(1) ?0001Rxy(2) ?10000000146
AutocorrelationTRY ITRxy(-1) 0010101000001101010Rxy(-2) ?00011101010Rxy(-3) ?00111010100111101010111Rxy(-2) 000Rxy(-3) 10000Rxy(-4) 200000Rxy(-1) ?Rxy(-5) 30000001101100000Rxy(-4) ?00Rxy(-5) ?0047
AutocorrelationTRY ITRxy(-6) 20000Rxy(-6) ?101010011001010101001010000Rxy(-7) 100001Rxy(-7) ?00Rxy(-8) 00011Rxy(-8) ?0001Rxy(-9) 000000111Rxy(-9) ?10101010101048
AutocorrelationTRY ITPut it together m 2:-1:-9; R [ 0 0 0 0 0 10 20 30 20 10 0 0 ]; [ ,maxIndex] max( R )maxIndex 8 m(maxIndex)ans -5 % max when shifted right by 50000011101234567080949
AutocorrelationTRY IT plot( -m, R, ‘o’ )Note shape is a triangle, not a rectangle,which is shape of pulse. Autocorrelationdetects signal of given shape – it does notreplicate signal3025Autocorrelation(m)20151050-2024Lag m681050
AutocorrelationMATLAB considers what we’re doingto be cross-correlation Concept is same as what describedhere for autocorrelation If one array shorter than another,MATLAB pads shorter one with zerosuntil both same length51
AutocorrelationTo compute cross-correlation ofvectors x and y in MATLAB, usec xcorr( x, y )where c is a vector with 2N-1 elements N is length of longer of x and yIf m is lag as previously defined, c(k)is autocorrelation for lag m k - N52
AutocorrelationTRY ITLet’s do previous graphicalautocorrelation with MATLAB1010100000011100 x [ 10 10 10 ]; y [ 0 0 0 0 0 1 1 1 0 0 ]; c xcorr( x, y ); [ ,maxCix] max( c )maxCix 5 m maxCix - length( y )m -5 % Move 5 to right from element 153
AutocorrelationTRY ITExample of finding signal buried in noise1. Make a sine wave with a period of 20 andamplitude of 100 wave 100 * sin( 2*pi*(0:19)/20 );2. Reset random number generator(so we all get the same random numbers) rng default3. Make 500 points of noise with randn andvariance 75% of wave amplitudenoisyWave 75 * randn( 1, 500 );54
AutocorrelationTRY IT4. Pick a random spot to place the wave,ensuring that the whole wave fits inix randi( [ 1, 481 ] );5. Add the wave to the noisenoisyWave(ix:ix 19) noisyWave(ix:ix 19) wave;Plot wave in noise. Is wave visible?plot( noisyWave )3002001000-100-2006. Compute autocorrelation-300050100 c xcorr( wave, noisyWave );15020025030035040045050055
AutocorrelationTRY IT7. Find max of autocorrelation andcalculate lag from that [ ,maxIx] max( c )maxIx 269 m maxIx – 500m -231 % shift 231 to right8. Show random spot where wave addedto noise. Match? ixix 231Very close match! m should be -23056
AutocorrelationTRY IT9. For grins, plot autocorrelation lags -499:499; plot( lags, c )Why is almostall of rightsize zero? Right sidecorresponds toshifting left and onceshift wave more than20, rest of waveis zeros48x 57
CorrelationQuestions?58
Convolutionconvolution Uses– Polynomial multiplication– LTI response– Joint PDF Linear and circular– Explain, show when equivalent (padding), good forcomputing convolution with fft. Do example withtic,toc, time-domain convolution vs. fft,ifft, see cconv59
ConvolutionApplications of convolution Acoustics – reverberation is the convolution ofthe original sound with echoes from objectssurrounding the sound source Computational fluid dynamics – the large eddysimulation (LES) turbulence model usesconvolution to lower the range of length scalesnecessary in computation and thereby reducingcomputational cost Probability – probability distribution of the sumof two independent random variables is theconvolution of their individual distributions60
ConvolutionApplications of convolution Spectroscopy – line broadening can be due tothe Doppler effect and/or collision broadening.The effect due to both is the convolution of thetwo effects Electronic music – imposition of a rhythmicstructure on a sound done by convolution Image processing – blurring, sharpening, andedge enhancement done by convolution Numerical computation – can multiplypolynomials quickly with convolution61
ConvolutionConvolution finds many applicationsbecause it is central to linear, timeinvariant systems and many thingscan be modeled by such systems62
ConvolutionLinear – a linear system obeys two principles– Principle of superposition – the output to a sum ofinputs is equal to the sum of the outputs to theindividual inputs– Scaling – the output to the product of an input and aconstant is the product of the constant and the outputto the input alone– In other words, for a linear system L,a L{ x(t) } bL{ x(t) } L{ ax(t) bx(t) }63
ConvolutionSuppose you put some input into asystem and get some output. If you putin the same input at a later time, if thesystem is time invariant, the output willbe the same as the original outputexcept it will occur at that later time– In other words, for a time-invariant system S,If y(t) S{ x(t) }, then y(t-t0) S{ x(t-t0) }Time-invariance and linearity are independent. Alinear system can be time-invariant or not. A timeinvariant system can be linear or not.64
ConvolutionExampleChange machine at a laundromat.Put in dollar bills, press button, get outquartersLinear?1. Put 1 in, press button, get 4 quarters out2. Put 2 in, press button, get 8 quarters out3. (output from 1) (output from 2) 12quarters4. Put 3, press button, get 12 quarters out5. Two outputs equal, so system linear65
ConvolutionExampleTime invariant?1. Put 1 in, press button, get 4 quarters out2. Put 2 in, press button, get 8 quarters outAn hour later1. Put 1 in, press button, get 4 quarters out2. Put 2 in, press button, get 8 quarters outOutputs identical except for same delay asinput, so system is time invariant66
Convolution1 for 𝑛 0(discrete) impulse: δ 𝑛 0 for 𝑛 0impulse response –response h[n] of asystem S when the input is an impulse,i.e.,h[n] S { δ 𝑛 }67
ConvolutionMajor factThe output of a linear, time-invariant(LTI) system to any input is theconvolution of that input with thesystem’s impulse responseOther words: The impulse response of an LTI systemcompletely characterizes that system The impulse response of an LTI systemspecifies that system68
ConvolutionGraphical view of convolving two signals Pick one signal 3 2 1 Flip it 180 around left edge321123 Position right element of flipped signalover left element of unflipped signal12310225-2-200169
ConvolutionGraphical view Multiply corresponding elements and sum123x10225-2-20013 1370
ConvolutionGraphical view Slide right, multiply, sum123xx10225-2-20012 1 3 03271
ConvolutionGraphical view Repeat until “fall off” right side123xxx10225-2-20011 1 2 0 3 232772
ConvolutionGraphical view1123xxx0225-2-20011 0 2 2 3 23271073
ConvolutionGraphical view10123xxx225-2-20011 2 2 2 3 5327102174
ConvolutionGraphical view102123xxx25-2-20011 2 2 5 3 (-2)3271021675
ConvolutionGraphical view1022123xxx5-2-20011 5 2 (-2) 3 (-2)32710216-576
ConvolutionGraphical view10225123xxx-2-20011 (-2) 2 (-2) 3 032710216-5-677
ConvolutionGraphical view10225-2123xxx-20011 (-2) 2 0 3 032710216-5-6-278
ConvolutionGraphical view10225-2-2123xxx0011 0 2 0 3 132710216-5-6-2379
ConvolutionGraphical view As with correlation, ignore elements that havefallen off or pad bottom array with zeros10225-2-2012xx0131 0 2 132710216-5-6-23280
ConvolutionGraphical view12321x10225-2-20011 132710216-5-6-2381
ConvolutionSo convolution of321with10225-2-2001gives32710216-5-6-232182
ConvolutionNote that when we convolvedwith10225-2-2001 the shortersignal was not completely on top of the longerone for the first two and last two elements of thelonger. For these cases, the multiply-and-addconvolution computation was missing either oneor two terms, so those four calculations are notvalid and should be ignored. Bad values at theleft and right of a convolution are known as edgeeffects.32183
ConvolutionIn general, if the shorter of two signalsin a convolution has M elements, youshould ignore the first and last M-1elements in the result84
ConvolutionMathematical definitionSuppose we have two signals – x[n] has Mpoints and y[n] has N points, M N. Theconvolution of x[n] and y[n] is𝑛𝑥 𝑛 𝑘 𝑦 𝑘for 𝑛 0,1,2, 𝑀 1𝑘 0𝑛𝑤 𝑛 𝑥 𝑛 𝑘 𝑦[𝑘]for 𝑛 𝑀,
MATLAB Signal Processing Toolbox Greg Reese, Ph.D Research Computing Support Group Academic Technology Services Miami University October 2013 . MATLAB Signal . Analog and Digital Filters 10 Digital Filter De
MatConvNet library: MATLAB toolbox implementing Convolutional Neural Networks (CNNs) for computer vision applications MATLAB MATLAB Parallel Computing Toolbox , Computer Vision System Toolbox and Statistics and Machine Learning Toolbox A little bit of MATLAB code
Model-Based Calibration Toolbox 13, 21, 23, 24, 27 500 600 Control System Design and Analysis Control System Toolbox 200 200 System Identification Toolbox 200 200 Fuzzy Logic Toolbox 200 200 Robust Control Toolbox 4 200 200 Model Predictive Control Toolbox 4 200 23200 Aerospace Toolbox 200 200 Signal Processing and Communications
MATLAB Functionality for Digital Speech Processing MATLAB Speech Processing Code MATLAB GUI Implementations Lecture_3_2013 1. . MATLAB signal array is to be stored - for wavwrite the MATLAB array xoutneeds to be scaled to the range 1 xin 1 whereas for savewav the MATLAB array xoutneeds to be .
The toolbox is designed to work with both resting state scans and block designs. Installing the toolbox: 1. download conn.zip, unzip the file. 2. add ./conn/ directory to matlab path To start the toolbox: On the matlab prompt, type : conn (make sure your matlab path include the path to the connectivity toolbox)
Overview of Digital Signal Processing 3 using electrical networks containing active and passive circuit elements. This approach is known as analog signal processing (ASP)—for example, . basic MATLAB product, the Signal Processing toolbox (SP toolbox) is required for thi
MATLAB Signal Processing Toolbox Greg Reese, Ph.D Research Computing Support Group Academic Technology Services Miami University October 2013 . MATLAB Signal . Analog and Digital Filters 10 Digital Filter Design interactively (GUI) Filterbuilder - specify desired
Compiler MATLAB Production Server Standalone Application MATLAB Compiler SDK Apps Files Custom Toolbox Python With MATLAB Users With People Who Do Not Have MATLAB.lib/.dll .exe . Pricing Risk Analytics Portfolio Optimization MATLAB Production Server MATLAB CompilerSDK Web Application
Bartle - Introduction to Real Analysis - Chapter 6 Solutions Section 6.2 Problem 6.2-4. Let a 1;a 2;:::;a nbe real numbers and let fbe de ned on R by f(x) Xn i 0 (a i x)2 forx2R: Find the unique point of relative minimum for f. Solution: The rst derivative of fis: f0(x) 2 Xn i 1 (a i x): Equating f0to zero, we nd the relative extrema c2R as follows: f0(c) 2 Xn i 1 (a i c) 2 " nc Xn i .