22
Biophysical Techniques (BPHS 4090/PHYS 5800) York University Winter 2017 Lec.12 Instructors: Prof. Christopher Bergevin ([email protected]) Schedule: MWF 1:30-2:30 (CB 122) Website: http://www.yorku.ca/cberge/4090W2017.html

Biophysical Techniques (BPHS 4090/PHYS 5800)

  • Upload
    others

  • View
    8

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Biophysical Techniques (BPHS 4090/PHYS 5800)

Biophysical Techniques (BPHS 4090/PHYS 5800)

York University Winter 2017 Lec.12

Instructors: Prof. Christopher Bergevin ([email protected])

Schedule: MWF 1:30-2:30 (CB 122)

Website: http://www.yorku.ca/cberge/4090W2017.html

Page 2: Biophysical Techniques (BPHS 4090/PHYS 5800)

ImpulseResponse

Buzug(2008)

Input:Incoming“signal”(arbitrary)

“Impulseresponse”(thisfullycharacterizesthe“system”)

Output:“filtered”signal(combinaConofthesystemandtheinput)

Page 3: Biophysical Techniques (BPHS 4090/PHYS 5800)

Ex.AcousCcImpulseResponse

Pulkki&Karjalainen(2015)

àAlltherelevantbitsoftheroom’sacousCcsarecontainedinh(whichwecaneasilymeasure!)

Roomresponse(g)“filters”aninputsound(s)

Roomresponse(g)isjust“convoluCon”betweensandroom’simpulseresponse(h)

Page 4: Biophysical Techniques (BPHS 4090/PHYS 5800)

hSp://www.audacityteam.org/

Page 5: Biophysical Techniques (BPHS 4090/PHYS 5800)

LTI(LinearTime-Invariant)Systems

Pulkki&Karjalainen(2015)

Page 6: Biophysical Techniques (BPHS 4090/PHYS 5800)

Recall:Why‘sample’withpulses?

Buzug(2008)

Page 7: Biophysical Techniques (BPHS 4090/PHYS 5800)

EXconvoluCon2.m% ### EXconvolution2.m ### 2014.11.07 CB (updated 2017.02.03)! !% Example code to perform convolution between a (discrete) sinusoid (wf1) and narrow!% digital pulse (wf2); should see that the convolved signal is just the!% original sinusoid! !% Note:!% o reqs. (custom-code) convolve1.m!% o allows user (via "method") to specify whether a (CB) custom-coded!% convolution code (convolve1.m) or Matlab's built-in conv.m is used!clear!% --------------------------------!SR= 44100; % sample rate [Hz]!Npoints= 100; % length of window (# of points) {8192}!f= 2580.0; % wf1 Frequency (for waveforms w/ tones) [Hz]!CLKbnd= [50 51]; % wf2: indicies at which pulse turns 'on' and then 'off' {[2900 2901]]!method= 0; % boolean to specify whether to use custom convolution code (0) or Matlab's (1) {0}!% --------------------------------!% +++!t=[0:1/SR:(Npoints-1)/SR]; % create an array of time points!% +++!% create two waveforms (same dimensions)!wf1= cos(2*pi*f*t);!clktemp1= zeros(1,Npoints);!clktemp2= ones(1,CLKbnd(2)-CLKbnd(1));!wf2= [clktemp1(1:CLKbnd(1)-1) clktemp2 clktemp1(CLKbnd(2):end)];!% +++!% Use custom code (convolve1.m) or Matlab's built-in function? [should return identical answers]!if (method==0), C= convolve1(wf1,wf2); % custom code!else C= conv(wf1,wf2); end % Matlab's built-in function!% +++!figure(1); clf;!subplot(211)!h1= plot(t,wf1,'b'); hold on; grid on;!h2= plot(t,wf2,'r.-'); !legend([h1 h2],'wf1 (sinusoid)','wf2 (impulse)');!xlabel('Time [s]'); ylabel('Amplitude'); title('Two waveforms (wf1 and wf2)');!subplot(212); plot(C,'k'); hold on;!xlabel('Sample index'); ylabel('Amplitude'); title('Convolution between wf1 and wf2');!

Page 8: Biophysical Techniques (BPHS 4090/PHYS 5800)

convolve1.m

function y= convolve1(wf1,wf2); % 2014.11.07 CB!% convolve two 1-D row vectors (should work similar to Matlab's conv.m) !% +++!error(nargchk(2, 2, nargin)), error(nargoutchk(0, 1, nargout))!if ~isvector(wf1) || ~isvector(wf2)! error('Parameters must be vectors.')!end!% ensure they are row vectors!if (~isrow(wf1)), wf1= wf1'; end!if (~isrow(wf2)), wf2= wf2'; end!m = length(wf1); n = length(wf2); % extract relevant dimensions!% create new arrays as needed for operation!g= fliplr(wf2); % flipped wf2!f= [zeros(1,n) wf1 zeros(1,n)];!NN= m+n-1;!for k=1:NN! % Note: It took me awhile to get this code right!! y(k)= sum(f.*[zeros(1,k) g zeros(1,m-k+n)]); % shifted wf2!end!return!

Page 9: Biophysical Techniques (BPHS 4090/PHYS 5800)

EXconvoluCon2.m

àSignalconvolvedw/animpulseis(moreorless)itself!

Page 10: Biophysical Techniques (BPHS 4090/PHYS 5800)

Canweslowdownforamoment?What(intuiCvely?)isa“convoluCon”?

Page 11: Biophysical Techniques (BPHS 4090/PHYS 5800)

Izhikevich(IEEE2003)

(Important)Tangent:CorrelaCons

Ø HowdowefindpaSernsinsignals?

ex.neuralrasterplot

Ø PeriodiciCes?

àLookfor‘correlaCons’

Page 12: Biophysical Techniques (BPHS 4090/PHYS 5800)

Cross-CorrelaCon

Hobbie&Roth

àCross-correlaCon(betweeny1andy2)isaCme-shi`edsumoftheiroverlapasafuncConofsaidshi`

Note:Wefocuson1-Dhereforclarity,buttheseideasgeneralizetohigherdimensions(e.g.,2-Dforimages)

Page 13: Biophysical Techniques (BPHS 4090/PHYS 5800)

àThinkabouthowacorrelaConmeasurewouldtellyousomethingalongthelinesof“reliability”

Page 14: Biophysical Techniques (BPHS 4090/PHYS 5800)

Hobbie&Roth

àForagivenvalueofτ,thecross-correlaContakesasingle(scalar)value[dashedlines]

11.7 Correlation Functions 299

begin to overlap. When the second pulse has been ad-vanced by 2 s the overlap is greatest; as it is advancedmore, the overlap falls to zero. The cross-correlation func-tion depends on τ and is plotted in Fig. 11.19(c). Themathematical statement of this procedure for a pulse is

φ12(τ) =∫ ∞

−∞y1(t)y2(t + τ) dt. (11.39)

The integrand makes a positive contribution to the inte-gral if y1(t) and y2(t + τ) are both positive at the sametime or both negative at the same time. It makes a neg-ative contribution if one function is positive while theother is negative.

11.7.2 Cross-Correlation of a Nonpulse Signal

If the signals are not pulses, then the cross-correlationintegral is defined as

φ12(τ) = ⟨y1(t)y2(t + τ)⟩ . (11.40)

As before, the average is the integral over a long timedivided by the time interval:

φ12(τ) = limT→∞

12T

∫ T

−Ty1(t)y2(t + τ) dt. (11.41)

If the signals have period T , the average can be taken byintegrating over a single period:

φ12(τ) =1T

∫ t′+T

t′y1(t)y2(t + τ) dt. (11.42)

Note the difference in units between φ12 as defined forpulses in Eq. 11.39 where the units of φ are the units ofy2 times time, and φ12 defined in Eqs. 11.40–11.42 wherethe units are those of y2.

The cross correlation depends only on the relative shiftof the two signals. It does not matter whether y2 is ad-vanced by an amount τ or y1 is delayed by the sameamount:

φ21(−τ) = φ12(τ). (11.43)

11.7.3 Cross-Correlation Example

As an example of the cross correlation, consider a squarewave that has value ±1 and a sine wave with the sameperiod (Fig. 11.20). When the square wave and sine waveare in phase, the product is always positive and the crosscorrelation has its maximum value. As the square waveis shifted the product is sometimes positive and some-times negative. When they are a quarter-period out ofphase, the average of the integrand is zero, as shown inFig. 11.20(b). Still more shift results in the correlationfunction becoming negative, then positive again, with ashift of one full period giving the same result as no shift.

y2(t+τ)

y1(t)y2(t+τ)(a) τ = 0; φ12 > 0

y2(t+τ)

y1(t)

y1(t)

y1(t)

y2(t+τ)

y1(t)y2(t+τ)

(b) τ = 3T/4 or -T/4; φ12 = 0

y1(t)y2(t+τ)

(c) τ = ± T/2; φ12 < 0

FIGURE 11.20. Cross correlation of a square wave and a sinewave of the same period.

11.7.4 Autocorrelation

The autocorrelation function is the correlation of the sig-nal with itself:

φ11(τ) =∫

y1(t)y1(t + τ) dt (pulse), (11.44)

φ11(τ) = ⟨y1(t)y1(t + τ)⟩ (nonpulse). (11.45)

Since the signal is correlated with itself, advancing onecopy of the signal is the same as delaying the other. Theautocorrelation is an even function of τ :

φ11(τ) = φ11(−τ). (11.46)

11.7.5 Autocorrelation Examples

The autocorrelation function for a sine wave can be cal-culated analytically. If the amplitude of the sine wave is

Usuallyusefultoconsideranaveragevalue(i.e.,changethelimitsofintegraCon):

Page 15: Biophysical Techniques (BPHS 4090/PHYS 5800)

Hobbie&Roth

Auto-CorrelaCon

Cross-correlateasignalwithitself:

àUsefulforreducingnoisewhenthereisaperiodic/phase-lockedsignal(temporalaveraging)

Page 16: Biophysical Techniques (BPHS 4090/PHYS 5800)

Hobbie&Roth

Auto-CorrelaCon

ex.puresinusoid

[keepthisinmindrethenextslide]

11.7 Correlation Functions 299

begin to overlap. When the second pulse has been ad-vanced by 2 s the overlap is greatest; as it is advancedmore, the overlap falls to zero. The cross-correlation func-tion depends on τ and is plotted in Fig. 11.19(c). Themathematical statement of this procedure for a pulse is

φ12(τ) =∫ ∞

−∞y1(t)y2(t + τ) dt. (11.39)

The integrand makes a positive contribution to the inte-gral if y1(t) and y2(t + τ) are both positive at the sametime or both negative at the same time. It makes a neg-ative contribution if one function is positive while theother is negative.

11.7.2 Cross-Correlation of a Nonpulse Signal

If the signals are not pulses, then the cross-correlationintegral is defined as

φ12(τ) = ⟨y1(t)y2(t + τ)⟩ . (11.40)

As before, the average is the integral over a long timedivided by the time interval:

φ12(τ) = limT→∞

12T

∫ T

−Ty1(t)y2(t + τ) dt. (11.41)

If the signals have period T , the average can be taken byintegrating over a single period:

φ12(τ) =1T

∫ t′+T

t′y1(t)y2(t + τ) dt. (11.42)

Note the difference in units between φ12 as defined forpulses in Eq. 11.39 where the units of φ are the units ofy2 times time, and φ12 defined in Eqs. 11.40–11.42 wherethe units are those of y2.

The cross correlation depends only on the relative shiftof the two signals. It does not matter whether y2 is ad-vanced by an amount τ or y1 is delayed by the sameamount:

φ21(−τ) = φ12(τ). (11.43)

11.7.3 Cross-Correlation Example

As an example of the cross correlation, consider a squarewave that has value ±1 and a sine wave with the sameperiod (Fig. 11.20). When the square wave and sine waveare in phase, the product is always positive and the crosscorrelation has its maximum value. As the square waveis shifted the product is sometimes positive and some-times negative. When they are a quarter-period out ofphase, the average of the integrand is zero, as shown inFig. 11.20(b). Still more shift results in the correlationfunction becoming negative, then positive again, with ashift of one full period giving the same result as no shift.

y2(t+τ)

y1(t)y2(t+τ)(a) τ = 0; φ12 > 0

y2(t+τ)

y1(t)

y1(t)

y1(t)

y2(t+τ)

y1(t)y2(t+τ)

(b) τ = 3T/4 or -T/4; φ12 = 0

y1(t)y2(t+τ)

(c) τ = ± T/2; φ12 < 0

FIGURE 11.20. Cross correlation of a square wave and a sinewave of the same period.

11.7.4 Autocorrelation

The autocorrelation function is the correlation of the sig-nal with itself:

φ11(τ) =∫

y1(t)y1(t + τ) dt (pulse), (11.44)

φ11(τ) = ⟨y1(t)y1(t + τ)⟩ (nonpulse). (11.45)

Since the signal is correlated with itself, advancing onecopy of the signal is the same as delaying the other. Theautocorrelation is an even function of τ :

φ11(τ) = φ11(−τ). (11.46)

11.7.5 Autocorrelation Examples

The autocorrelation function for a sine wave can be cal-culated analytically. If the amplitude of the sine wave is

Page 17: Biophysical Techniques (BPHS 4090/PHYS 5800)

Hobbie&Roth

Auto-CorrelaConßàFourierTransform

à DeepconnecConbetweenthetwopaths(thishasbigimplicaConsaswe’llseelateron)

Note:ThisinterrelaConshipCesintothe“CentralSecConTheorem”raisedbyNishimura(Sec.2.3.2;we’lllikelycomebacktothisoncewegettoMRI)

Page 18: Biophysical Techniques (BPHS 4090/PHYS 5800)

Recall:Two-DimensionalFourier-BasedReconstrucConMethods

Buzug(2008)

Similarflavorofidea(i.e.,interrelaConashipbetweenFourierdecomposiConandothersortsof“transforms”)

Page 19: Biophysical Techniques (BPHS 4090/PHYS 5800)

Hobbie&Roth

ConvoluCon

Similarinspirittoacross-correlaCon(withsomeaddiConalstringsaSached)

àAsampledsignalistheoriginal(conCnuous)signalconvolvedwithatrainofimpulses

g(t)–‘output’f(t)–‘input’h(t)–‘impulseresponse’

ThroughthelensofLTIsystems:

Page 20: Biophysical Techniques (BPHS 4090/PHYS 5800)

Recall:Why‘sample’withpulses?

Buzug(2008)

Page 21: Biophysical Techniques (BPHS 4090/PHYS 5800)

Wikipedia

VariousInterrelaConships

Note:InaddiContoFouriertransforms,Laplacetransformsalsocommonlyusedtogobackandforthbetweentemporalandspectraldomains

Page 22: Biophysical Techniques (BPHS 4090/PHYS 5800)

Hobbie&Roth

ConvoluConTheoremFourierTransform

Sine/CosineTransform

Alsoappliesto2-D(andhigher)

Theorem