Presentation is loading. Please wait.

Presentation is loading. Please wait.

Spectra of random processes Signal, noise, smoothing and filters.

Similar presentations


Presentation on theme: "Spectra of random processes Signal, noise, smoothing and filters."— Presentation transcript:

1 Spectra of random processes Signal, noise, smoothing and filters

2 Gaussian processes are defined by… Their mean at each time, m(t) Their covariance matrix, Cm(t,s)

3 Stationary Gaussian processes are defined by… Their mean at each time, m Their covariance function, C(  ) –Note that t is now a time interval, not an absolute time –Cm(t,s)=C(t-s)

4 Stationary processes are defined by… Mean and covariance are not sufficient in general Let’s keep that in mind for a while…

5 The covariance function We assume that the process is Gaussian and stationary, and that its mean is 0

6 MATLAB

7 Spectral representation of a random process We have our samples of the random process We can transform each of them into the frequency domain We can collect now all the values of the frequency components at a specific frequency These are samples of a random variable whose distribution can be computed

8 Spectral representation of a random process We do it because the spectral representation may be often simpler than the time representation Frequency components may be far less correlated than time samples

9 Go to Matlab

10 Spectral representations What we saw is that the process can be rather nicely described in the following way: –Select real and imaginary parts, independently and normally, with variance that is frequency-dependent –Synthesize the appropriate time sequence

11 Spectral representations It turns out that all Gaussian processes follow this prescription The function that gives the variance as a function of frequency is called the spectral density function of the process

12 Spectral representations And if the process is stationary but non- gaussian? The frequency components are still uncorrelated, but they are not normal any more Therefore, there may dependence between them (but no correlation!)

13 Spectral representations Non-stationary processes –Correlations between frequency components, non- zero means Stationary processes –No correlations between frequency components, zero means –Dependences between frequency components Gaussian processes –Independence and normality in the frequency domain

14 Spectral density functions and autocorrelations The spectral density function of a stationary process is the Fourier transform of its (non-normalized) autocorrelation function –Autocorrelations are very special: they have a real positive Fourier transform

15 Go To Matlab

16 Spectral density functions and autocorrelations Why use spectral density rather than autocorrelation? –Because Fourier components of stationary processes are uncorrelated and even independent (in the gaussian case) –Because of dynamic range issues –Because the spectral density function is a variance decomposition, good for any stationary process…

17 Spectral density functions and autocorrelations The spectral density function can be seen as a variance decomposition of the total energy of the process Proof: –The energy of the process is the (non-normalized) autocorrelation at lag 0 –This is the 0-th component of the inverse Fourier transform of the spectral density –Which is the DC of the spectral density, i.e. the sum of the variance of all spectral components

18 Additive models Usually, the signal is not stationary/Gaussian because there is a special shape in it (an action potential, evoked potential in the LFP, a cross- correlation peak, …) We will usually assume that the shape is exactly the same every time, and that whatever is not shape is gaussian noise

19 Additive models The independence of frequency components in Gaussian processes is the frequency domain expression of their lack of structure Generally, we will consider Gaussian contributions to our signal as noise Sometimes this is not true – it’s the variance that is the signal –EMG

20 Getting rid of noise If we know that our signal doesn’t have much energy in a certain frequency range, we can filter out that range of frequencies without hurting much the signal By this process, we reduce the energy of the noise more than we reduce the energy of the signal, improving signal to noise ratio

21 Filtering in the frequency domain What we would like to do is to set all frequency components outside the interesting range to 0 We will see that this is not necessarily the best way of doing it, but let’s proceed…

22 Go To Matlab

23 Filtering in the frequency domain Two problems: –Large fluctuations (when signal is transient) –Non-causality Partial solution to non-causality – zero-padding

24 Filtering in the frequency domain Fluctuations are due to the introduction of sharp discontinuities into the Fourier domain Time domain then becomes wide (high ‘frequencies’) We can try smoother cutoffs

25 Go To Matlab

26 Filtering in the frequency domain Decide which frequencies should be suppressed (‘stop band’) The other frequencies are called the pass band Build a window that is 1 inside the pass band, 0 inside the stop band, and interpolates between 0 and 1 gradually Do it! Beware of edge effects…

27 Filtering in the frequency domain The fine point here is the selection of the window to use for multiplying the spectra

28 Filtering in the frequency domain Additive model: –s(t)=x(t)+n(t) –x(t), n(t) are stationary processes and independent of each other with known autocorrelation functions In that case, the constraint of making s(t) as similar as possible to x(t) can be formalized to get an optimal filter (Wiener filtering) The multiplier is roughly When X(f)>>N(f), this is about 1 (passband) When X(f)<<N(f), this is about 0 (stopband) Smooth interpolation between the two extremes The same formula works for constant x(t)

29 Go To Matlab

30 Filtering in the time domain We already did this to remove high- frequency noise: –Select a short window –Take a short piece of signal, average, replace the middle point of the piece of signal by the new point –This is non-causal!

31 Filtering in the time domain Causality: –We want to implement such filtering on-line –This means that at each point in time, we know the current sample and all past ones, but not future ones

32 Filtering in the time domain Causal time-domain filtering: –Select a short window –Take a short piece of signal, average, replace the last(!) point of the piece of signal by the new point The choice of the window will determine what we do –Lowpass filtering (weighted averages) –Highpass filtering (highly fluctuating weights) –Bandpass filtering (MATLAB)

33 Filtering in the time domain Problems: –Edge effects The implementation assume that the signal is 0 before it begins –Time shifts Impulses peak later (causality) –At the moment, we have only a rough idea what this is doing in the frequency domain

34 Time-domain filtering and sine waves We want to understand what time-domain filtering does to the frequency components of a signal We will start by testing the effect of a time- domain filter on sine waves (MATLAB)

35 Time-domain filtering and sine waves When putting in a sine wave, a time- domain filter will output a sine wave (up to edge effects) The output will have the same frequency as the input The output will differ in amplitude and phase

36 Time-domain filtering and sine waves The change in amplitude and the shift in phase depend only on the frequency of the input This can be concisely summarized by a complex number (‘gain’)

37 Time-domain filtering and sine waves The complex gain is in fact the Fourier transform of the time-domain window Proof: (whiteboard)

38 Time-domain filtering and general signals If we know what a time-domain filter does to sine waves, we know what it does to any other signal The reason is linearity

39 Time-domain filtering and general signals Linearity: For two signals, –First summing and then filtering –First filtering and then summing –Will give the same result

40 Time-domain filtering and general signals We know that Fourier synthesis (inverse Fourier transform) represents a stimulus as a sum of sine waves The effect of a time-domain filter is then the sum of the effects on each frequency component

41 Time-domain filtering and general signals Do a Fourier transform, to get amplitude and phases of each frequency component Change the amplitude and phase of each frequency component as implied from the Fourier transform of the filter Do an inverse Fourier transform

42 Time-domain filtering and general signals Note that the frequency domain step is equivalent to a multiplication by a (possibly complex) window

43 Comparing frequency domain and time domain filtering Time domain: Do an FT Multiply by a window (FT of time-domain window) Do an iFT Frequency domain: Do an FT Multiply by an (arbitrary) window Do an iFT

44 Comparing frequency domain and time domain filtering Frequency domain and time domain filtering are in fact the same thing (almost, up to edge effects – see soon) The time-domain window used for filtering and the frequency-domain window multiplying the frequency representation are Fourier-transform pairs (MATLAB)

45 Comparing frequency domain and time domain filtering Why do we have a difference? The reason is the assumptions about the edges

46 Comparing frequency domain and time domain filtering In the time-domain filter, we assumed that before stimulus start, there were zeros In the frequency-domain operation, it is implicitly assumed that the stimulus is periodic –Before stimulus start, the last samples come from the end of the stimulus Solution: increase stimulus duration, padding with 0’s (MATLAB)

47 Comparing frequency domain and time domain filtering The same equivalence occurs when starting with a frequency-domain window and going back to a time domain window Need to keep the right symmetry of the frequency-domain window in order to get a real-valued time-domain window! (MATLAB)

48 Comparing frequency domain and time domain filtering Why do our time-domain filters shift the signal whereas our frequency-domain filters keep peaks in place? The property of keeping peaks in place is called ‘zero phase’ –Because all frequency components ‘stay in place’ (the phase of the complex gain is 0) The result is a non-causal time-domain window, as we saw previously

49 Comparing frequency domain and time domain filtering We shifted the resulting time-domain windows in order to see their actual shape This is equivalent to shifting the location of filtered peaks

50 Non-causal time-domain filtering We can do non-causal filtering by first doing a causal filtering, then delaying back the signal to compensate for the time shift Or by filtering the signal twice: once going forward (introducing a delay) and then filtering the signal reversed in time (introducing an equivalent delay in the other direction) (MATLAB)

51 Nomenclature The time-domain window is called the impulse response The frequency-domain window is called the transfer function

52 Practical issues EDGE EFFECTS! –Know what you are assuming Time domain or frequency domain? –Causal vs. non-causal –Computational efficacy –Shape of time-domain filters –Shape of frequency-domain windows

53 Practical issues EDGE EFFECTS! –For frequency domain filtering, pad to double the size in order to avoid circular leaks –Don’t generate extra jumps – make sure the average of the padded region is the same as that of the true data –Keep only the relevant part (first half of the buffer)

54 Practical issues EDGE EFFECTS! –For time domain filtering, Matlab assumes zero initial conditions –This may not be appropriate when the stimulus has a non-zero average (DC) –The function filter has explicit control of initial conditions, see me for details

55 Practical issues Causal vs. non-causal The literature is biased towards causal filtering because of real-time applications We usually want non-causal filtering Either shift back the signal to compensate for delays, or use filtfilt that does back- and-forth filtering

56 Practical issues Computational efficiency Time-domain filtering is more efficient when the stimulus is much longer than the window length Issue for very long stimuli (e.g. filtering millions of samples)

57 Practical issues Shape of time-domain windows You usually want your time-domain window short –For computational efficiency (minor concern!) –For not mixing up far segments of the stimulus (Major concern) You usually want your time-domain windows symmetric –For keeping the general shape of peaks –These are called ‘linear phase filters’ –When using filtfilt, the window is always effectively symmetric

58 Practical issues Shape of frequency-domain windows You usually want your frequency-domain windows very sharp, 1-0 type –To reject as fully as possible the noise

59 Practical issues Incompatibility of time-domain constraints and frequency-domain constraints Short time-domain filters have gradual, non-zero frequency-domain windows Sharp, 1-0 frequency domain windows have very long time-domain windows Must compromise!

60 Practical issues Filter design tools –FDATool –Fir1 + kaiserord


Download ppt "Spectra of random processes Signal, noise, smoothing and filters."

Similar presentations


Ads by Google