Sunteți pe pagina 1din 58

Bandpass filters

and
HilbertTransform

SummaryofChapter14
In
AnalyzingNeuralTimeSeriesData:
TheoryandPractice
LauritzW.Dieckman
AquickmessagefromMikeX

I'vecreatedagooglegroups forthebook.If
youhaveotherquestionsaboutthebook,
analyses,orcode,feelfreetopostthem
there.

https://groups.google.com/forum/#!forum/a
nalyzingneuraltimeseriesdata
FiltersEverywhere
Music
analogrecordings
~44,100Hz
sampling
typicallybandpass
filteredtorange
ofhumanhearing
Or,purposefully
Usedinartisticcreation
Onepersonsdistortionisanotherpersonsart
Why?FilterHilbertMethod
vs
ComplexWaveletConvolution
Similarities
Usedtocreateacomplex(realandimaginary)
timeseries(analyticsignal)fromrealsignal
data
Analyticsignalusedtodeterminephaseand
power
MethodsdescribedinChapter13
Thesignalmustbebandpass filteredbefore
Why?FilterHilbertMethod
vs
ComplexWaveletConvolution
Differences
Signalmustfirstbebandpass filtered
Analyticsignalacquiredbycreatingthephasequadrature
component(onequartercycle)byrotatingsectionsofa
Fourierspectrum.

PRO:FilterHilbertprovidessuperiorcontroloverfrequency
filtering
notlimitedinshapewhereasbandpass filterscantake
manyshapes
CON:However,FilterHilbertrequiressignalprocessing
toolboxforkernelcreation(unlikeMorlet wavelets).
CON:Bandpass filteringisslowerthanwavelets
Bandpass Filtering
FirststepisBandpass filtering
DontworryHilbertfans,wellgetbackto
Hilberttransformsoon
Highlyrecommendedtoseparatefrequencies
beforethetransform
e.g.lowerfrequenciesmaydominate
combinedsignal
Filters:ToInfinityandmuchshorter
FiniteImpulseResponse(FIR)
SOONIwillreign
Theresponsetoanimpulseends
supremeand
atsomepoint. infiniteoveryour
Stability analyticsignal
Computationtime

Riskofphasedistortions
Youwillnevertriumph
InfiniteImpulseResponse(IIR)
Butterworth.
Theresponsetoanimpulse
Itmaytakemorethanjustmy
doesnotend.analyticskilltoprotectthe
ButterworthIIR filter helpme!
signal.Matlab
Filters:Types
Highpassfilter Allowsfrequencieshigher
thancutofftoremaininthesignal(lower
frequencysignalsareattenuated)
Simpleillustration Cutoff5
1 2 3 4 5 6 7 8
FLstudioexample
Filters:Types
Lowpassfilter Allowsfrequencieslower
thancutofftoremaininthesignal(higher
frequencysignalsareattenuated)
Simpleillustration Cutoff5
1 2 3 4 5 6 7 8
Filters:Types
BandStopfilter Attenuatesorremoves
frequencieswithinaspecificrange.
e.g.Notchfiltersat60Hz
Simpleillustration LowCutoff5&
HighCutoff2

1 2 3 4 5 6 7 8
Filters:Types
Bandpass filter Allowsfrequencieslower
thanlowerboundcutofftoremaininthe
signalandfrequencieshigherthanhigher
boundcutofftoremaininthesignal
Simpleillustration LowCutoff5&
HighCutoff2
1 2 3 4 5 6 7 8
Basicallyahighandlowpasscombo
LFO
ManyMusicFXusefiltersFilter
Phaser
Separatessignal
1.Unfiltered
2.Altersphase
Whenrecombined
thesignalsoutofphasenullify
Frequentlycombinedwithlowfrequency
ossiclator
Howto:FilterKernelConstruction
Likecomplexwaveletconvolution Theanalytic
signal
producedfrom
filtering
*weighted
combinationof
kernelandsignal
Howto:FilterKernelConstruction
NotedifferenceshapeGaussianvsPlateau
Plateau
shapes
allowfor
greater
frequency
specificity
FilterFunctions
Firls 3inputs
A.Order:Lengthoffilterkernel(+1)
*Importantforfrequencyprecision
Larger Frequencyprecision+processingtime
Foraparticularfrequencyofinterest:MUSTbelong
enoughforonecycle
*Recommended2 5timelongerthanfrequencyof
interest
*Usesamplepoints,nottime(i.e.mustknowsample
rate)
filter_order =round(3*(EEG.srate/lower_filter_bound));
FilterFunctions
Firls 3inputs
B.6numbersdefineshapeofresponse
1.Zerofrequency
FilterFunctions
Firls 3inputstodefineshapeofresponse
B.6numbersdefineshapeofresponse
1.Zerofrequency
ffrequencies =[0(1transition_width)
*lower_filter_bound lower_filter_bound
upper_filter_bound (1+transition_width)
*upper_filter_bound nyquist ]/nyquist;
FilterFunctions
Firls 3inputs
B.6numbersdefineshapeofresponse
2.Frequencyofstartlowertransitionzone
FilterFunctions
Firls 3inputs
B.6numbersdefineshapeofresponse
2.Frequencyofstartlowertransitionzone
transition_width =0.2;
lower_filter_bound =4;%Hz

ffrequencies =[0 (1transition_width)


*lower_filter_bound lower_filter_bound
upper_filter_bound (1+transition_width)
*upper_filter_bound nyquist ]/nyquist;
FilterFunctions
Firls 3inputs
B.6numbersdefineshapeofresponse
3.Lowerboundofbandpass
FilterFunctions
Firls 3inputs
B.6numbersdefineshapeofresponse
3.Lowerboundofbandpass
ffrequencies =[0 (1transition_width)
*lower_filter_bound lower_filter_bound
upper_filter_bound (1+transition_width)
*upper_filter_bound nyquist ]/nyquist;
FilterFunctions
Firls 3inputs
B.6numbersdefineshapeofresponse
Sidenote:Transitionzones

Transitionzones
FilterFunctions
Firls 3inputs
B.6numbersdefineshapeofresponse
4.Upperboundofbandpass
FilterFunctions
Firls 3inputs
B.6numbersdefineshapeofresponse
4.Upperboundofbandpass

upper_filter_bound =10;%Hz

ffrequencies =[0 (1transition_width)


*lower_filter_bound lower_filter_bound
upper_filter_bound (1+transition_width)
*upper_filter_bound nyquist ]/nyquist;
FilterFunctions
Firls 3inputs
B.6numbersdefineshapeofresponse
5.Frequencyoftheendoftheuppertransition
zone
FilterFunctions
Firls 3inputs
B.6numbersdefineshapeofresponse
5.Frequencyoftheendoftheuppertransition
zone
ffrequencies =[0 (1transition_width)
*lower_filter_bound lower_filter_bound
upper_filter_bound (1+transition_width)
*upper_filter_bound nyquist ]/nyquist;
FilterFunctions
Firls 3inputs
B.6numbersdefineshapeofresponse
6.Nyquist frequency
FilterFunctions
Firls 3inputs
B.6numbersdefineshapeofresponse
6.Nyquist frequency

nyquist =EEG.srate/2;

ffrequencies =[0 (1transition_width)


*lower_filter_bound lower_filter_bound
upper_filter_bound (1+transition_width)
*upper_filter_bound nyquist ]/nyquist;
FilterFunctions
Firls 3inputs
B.6numbersdefineshapeofresponse
ThesenumbersarescaledsothatNyquist
frequencyis1.
OncefrequenciesaresetinHzwedivide
bythenyquist frequency
ffrequencies =[0 (1transition_width)
*lower_filter_bound lower_filter_bound
upper_filter_bound (1+transition_width)
*upper_filter_bound nyquist ]/nyquist;
FilterFunctions
Firls 3inputs
C.Idealresponseamplitude
Lengthofidealresponseshould=6numbersdefine
shapeofresponse
0s =attenuate.1s=keep.Canuserange01
[001100]

Lower Upper
Frequencybounds
FilterFunctions
Firls 3inputs
C.Idealresponseamplitude
Lengthofidealresponseshould=6numbersdefine
shapeofresponse
[001100]
DC Nyquist

Lower Upper
Frequencyboundsoftransitionzones
FrequencyWidth
ControlsTimeFrequencytradeoff
NarrowWidth
FrequencyPrecision
TemporalPrecision
WideWidth
TemporalPrecision
FrequencyPrecision Time
Freq
PrecisioninWidth
TimeFrequencyWrestling:
Funwithmixedmetaphors
Unlikecombataxiom smallerdoesnotmean
quicker
Narrowfilterkernelsarelong
andthusinfluencedbymore
numbers.Likeholdingup
sumomeat?
Widerwidthfiltershavesmaller
kernelsandarethuscreated
morequickly.Likesumoquickly
crushingakid?
PrecisioninWidth
TimeFrequency
SharpEdgesmakeRipplesinTime
< Artifact
witha
sharpedge

Sharpfilteredgesinfrequencyincreaseresponse,
butalsoincreaseriskofartifactsintime
Shootfor1025%of
upperandlower
bond
firls vsfir1
Fir1hasautomatictransitionzonesthen
smooths
Firls canproduceasimilareffectifkernelis
smoothedwithHamming(orHann)window
Seethesameminustheham
Prof.Xsrecommendations
Tomakea
narrowband
filter,usefir1

Ifyouareworried
aboutrippleartifacts Patrick_Stewart =
firls canallowfor disp(Tomakea
narrowbandfilter,
gentletransitionzones usefir1.Ifyouare
worriedaboutripple
Gentlesloping artifacts,firls can
plateaus allowforgentle
gentlefilters transitionzones
gentle gentle.)
Check.Your.Filters:
SoWhatcha Want?
Goodnessquantified!

Idealforms:
Similaritybetween
actualfilterandthe
idealfilter

Sumofsquared
errors
Sumofsquarederrors(SSE)
center_freq =60;%inHz
filter_frequency_spread_wide =10;%Hz+/ thecenterfrequency

ffrequencies =[0(1transition_width)*(center_freq
filter_frequency_spread_wide)(center_freqfilter_frequency_spread_wide)
(center_freq+filter_frequency_spread_wide)
(1+transition_width)*(center_freq+filter_frequency_spread_wide)nyquist
]/nyquist;
idealresponse =[001100];
filterweightsW =zscore(firls(200,ffrequencies,idealresponse));

num2str(sum((idealresponsefft_filtkern(freqsidx)).^2))

SSE=num2str(sum((idealresponsefft_filtkern(freqsidx)).^2))
GoodFilter/BadFilter:FilterWidth
SSEshould
beclose
to0
Donotusea
filterwith
SSE>1
Goodat
10hz
Badat
15hz
Application:filtfilt
Aftercreatingtheperfectkernelandtestingit
Filtfilt usedtoapply
data2filter =squeeze(double(EEG.data(47,:,1)));
filterweights =
firls(200,ffrequencies,idealresponse);%recompute
withoutzscoring
filter_result =filtfilt(filterweights,1,data2filter);

FilterKernel Weightcoefficient Data


Filtfilt comparedtoconvolution
PhaseDelayandTimeTravel
Causalfilter:Filterisbasedoninformation
fromthepast(backintime)
Filterfunction:
Causesaphase
delay
PhaseDelayandTimeTravel
Luckilywecanfilterbackintimetocorrecttheerrors
ofthepast!
Forward_to_thepast=1(Back_to_the_Future)
Refiltering correctsthephasedelay
DamnitDOC,mymat
Ineedanuclear telepathydemands
reactionto GIGA!GIGAWATTS
generate1.21
JIGAwatts of
electricity.
Youthoughtyourpunymattelepathypowers
coulddefeatme?WithmyInfinityImpulse
ResponseFilteringdeathrayIwillsow(relative)
chaos,instabilityandnonlinearphase
distortionsacrossyoursignal!Bwahahaha

NOOOOO!
5th order
Butterworth

Hopeforanalyticsignalfadingmust
useHilbertpowerstotransform
RevengeoftheHilbertTransform
Rememberwayback beforetimetraveling
filters,sumoquicknarrowfilters,and(poor)
comicbookish fightscenes?
Concatenation
Analyticsignalproducedby powersactivate!
addingphasequadrature(1/4) Hilberttransform!

Createdbyrotatingaspectsofcomplex
frequencyspectrum(fromFourier)
HowtofilterHilbert
HilbertTransformer:WithAutobot Matrix
1. Fouriertransformfrom
bandpass filteredsignal
andcreateanimaginary
copy(i.e.Fourier*i)
2. Findthepositive(>0toNyquist)andnegative(>
Nyquist frequencies).
*Note:0&Nyquist arenotused
3. Convertfromcomplexcosinetocomplexsineby
rotatingpositive90degree(pi/2)counter
clockwise&negativefrequencies90degrees
clockwise
Positive Negative
2xpos Subtract
freq coeff fromself
Original =0
HowtoHilbert
Final:InverseFourier
Theseingredientsproducetheanalyticsignal
Doesnotinfluence
realsignal
Warning:Hilbert
commandwillrun
FFT onthefirst
dimensioninadata
matrix.
Mustbetimeinthe
firstdimension
Doublecheckyoursignal
Plotphaseangles!
Comemyallies,wehaveearnedgood
nightssleep

S-ar putea să vă placă și