Signal Processing in Biologging or how to Fourier
Signal Processing in Biologging or how to Fourier transform yourself 1. What are signals? 2. Welcome to the frequency domain 3. Fourier analysis 4. Real signals and spectrograms 5. Filters and how to use them 6. Sampling continuous signals Mark Johnson markjohnson@st-andrews. ac. uk
Signals: time series of measurements (usually sampled at regular intervals) Pressure sensor on a diving animal Accelerometer on a swimming animal Sound recording
Real signals in biologging -- multiple measurement dimensions -- signal characteristics change rapidly with time -- average descriptions are not meaningful Goal is to break signals into blocks that represent single Trick is to break signals into blocks that we can dealbehaviours. with.
Describing signals: • By size: peak-to-peak, RMS, vector magnitude • By how they change with time Transient Random Periodic 1 2 1 2
Periodic or tonal signals Acceleration (m/s 2) - periodic signals have a repeating waveform. - the entire signal can be predicted from one cycle peak-to-peak = 3. 8 m/s 2 RMS = 0. 7 m/s 2 Time, ms Period = 1 s, Frequency = 1 / Period = 1 Hz
Periodicsignalswiththe thesamefrequencyand andamplitude canhave look very (anddifferent sound) different. . . can waveforms. . . For sounds, this difference is called timbre (think of the difference between a trumpet and a piano playing the same note). How can we describe it quantitatively?
Fourier analysis ANY periodic signal can be made by summing sinewaves with frequencies that are integer multiples of the fundamental frequency. These sinewaves are called harmonics. 1 st harmonic (fundamental) e. g. , 1 Hz 1 2 2 nd harmonic 2 Hz 1 3 rd harmonic 3 Hz 2 1 Different waveforms are produced by adding different amounts of each harmonic with different starting delays or ‘phase’. 2
Example: How to make a 1 Hz 'sawtooth' wave Fundamental (amplitude 1) 2 nd harmonic (amplitude 1/2) 3 rd harmonic (amplitude 1/3) 4 th harmonic (amplitude 1/4)
How do you find out how much of each harmonic there is in a waveform ? The Fourier Transform gives the Spectrum of a waveform Time (ms) Fourier Transform Magnitude and phase of each harmonic
Time domain: waveform Amplitude The waveform and spectrum are two different ways of looking at the same signal – if you change one, you change the other. Time (ms) Magnitude Frequency domain: spectrum Frequency (Hz)
Do you need exactly one period of a waveform to do the Fourier Transform ? Accelerometer on a running hyena No. You can compute the FT on many cycles. The FT will show you the average harmonic content of the data that you give it. But what if you don't have an integer number of cycles. . .
END EFFECTS and SPECTRAL LEAKAGE The FT assumes that the signal is exactly periodic with respect to the block length (i. e. , the piece of signal you give it). Jump in signal causes spectral leakage Spectral leakage Correct spectrum
Windowing to reduce leakage Waveform multiplied by a 'window' function Reduce signal at ends of block to minimise glitch Spectrum You want at least 10 cycles of signal in the window if possible.
Random signals No periodicity - the waveform is unpredictable Amplitudes are described by RMS level or a probability distribution. The equivalent of timbre for random signals is ‘colour’ ‘white’ noise ‘red’ noise
The spectrum of a random signal Random signals contain a continuous range of frequencies. Random signals are not periodic so there is no segment that represents the whole signal. We can estimate the spectrum by taking the Fourier transform of a piece of the signal. Fourier Transform Magnitude squared Estimate of the power spectrum
Improving the spectral estimate The Fourier transform of a random signal is also random. To get a better spectral estimate, average the FTs of multiple blocks of the signal. This is called a periodogram or power spectral density. Fourier Transform FT FT FT Magnitude squared Square and average Power spectrum estimate Better power spectrum estimate
Estimating the spectrum of a signal 1. Break into blocks of N samples 2. Window 3. Take N-sample Fourier transforms 4. Sum the squared magnitudes
Estimating the spectrum of a random signal Individual Fourier transforms Mean magnitude (150 averages) The more blocks you use, the better the estimate Tagtools: spectrum_level
Periodic signals Random signals Time domain (waveform) Time, ms Frequency domain (spectrum) Harmonic number Spectrum is DISCRETE – there is only energy at the harmonics. Spectrum is CONTINUOUS – there are no harmonics.
Transient signals Spectral analysis may be less useful for transient movement signals but can be done. For short transients, calculate the spectrum directly using a single Fourier Transform. Waveform Spectrum Fourier Transform of the full signal
The Fast Fourier Transform (FFT) The FFT is a fast way of computing the Fourier Transform. It works on a block of N samples. The spectrum is calculated at N frequencies: (0, 1, …N-1) / N * sampling rate. Example: sampling rate = 32 Hz, N = 512 Block length is 16 seconds (this is the averaging time of the FFT). Spectrum is computed at intervals of 0. 0625 Hz. The frequency resolution of an FFT is fs/N where fs is the sampling rate. The FFT algorithm works fastest if the number of samples is a power of 2, i. e. , N=512, 1024, …
Real signals Periodic and random signals are stationary - their characteristics never change. Real signals change over time. Spectral averages of changing signals are difficult to interpret and not usually useful. . . Accelerometer data from a collar tag on a hyena
Spectral averages Many animals move with a fairly constant propulsive rate. Long-term spectral averages of movement data can be useful to estimate the dominant stroke or stride frequency. mean stride rate 2. 1 Hz Tagtools: spectrum_level and dsf
Real signals often contain intervals in which the signal is roughly stationary. Spectrograms are used to visualize the frequency content of time-varying signals and to find 'stationary' pieces to analyze (i. e. , pieces with stable movement behaviour).
Spectrogram Fourier transform 1. 2. 3. 4. Break the signal into overlapping pieces, window each piece Compute the FT of each piece Represent the magnitude of the FT as a coloured strip Make a ‘stackplot’ out of the strips
Time and frequency resolution of a spectrogram Each strip of a spectrogram is an N-sample Fourier transform. Frequency resolution is therefore: fr = fs/N Time resolution is the length of the FT in seconds: tr = N/fs Example: fs = 50 Hz, N = 512 samples fr ≈ 0. 1 Hz, tr = 10 s Easy to remember: fr x t r = 1 The time resolution is the 'averaging time' of the spectrogram.
Filters We can easily clip out pieces of signals in the time domain. Waveform Tagtools: Aseg = crop(A); Filters do the same in the frequency domain. Spectrogram
Filters are used in signal processing to emphasise or reduce signal components input filter output High-pass filter Level Low-pass filter Frequency Band-pass filter Level Band-stop filter Frequency
What filters do. . . § Change the amount of power at each frequency. § Change the correlation between time points in a signal Waveform Time domain white noise Magnitude, V Frequency domain Magnitude, V Spectrum low-pass filter red noise
Filtering periodic signals Time domain Frequency domain low-pass filter Filters cannot create new harmonics. They just change the amount of each.
Filters operate in both domains at the same time Time domain convolution waveform Impulse response: the way the filter affects the waveform Frequency response: the way the filter affects the spectrum Frequency domain * new waveform filter impulse response filter frequency response X multiplication new spectrum
Specifying filters 1. Type Band-pass filter Level High-pass filter Level Low-pass filter Frequency 2. Frequency The cut-off or 'half-power' frequency 3. Design rule Butterworth, FIR, and many others. 4. Steepness The slope of the filter in the frequency domain - i. e. , how selective it is. Stopband Level Passband slope fc
Memory Filters work by computing the output from a number of input samples. The number of samples is the memory length of the filter. Two kinds of filters: Infinite memory (IIR) filters (e. g. , Butterworth) are used in processing sound. Finite memory (FIR) filters are more useful in processing movement data. Moving average (MA): output = mean of last n inputs Frequency response Memory is n-1 samples fs/n Differentiator: output = difference of last 2 inputs Frequency response Memory is 1 sample
Delay All filters delay the signal they are filtering. The amount of delay depends on the filter design. This means that signals that are filtered differently are no longer time aligned. This is important if you want to join or compare the signals, e. g. , computing heading from A and M. For some FIR filters, the delay is exactly 1/2 of the memory time. This delay can be removed by centering the filter on the output point: Normal MA output = mean of n past samples delay = (n-1)/2 'Delay-free' MA output = mean of n/2 past and n/2 future samples delay = 0
Complementary filters How to make a high-pass filter from a moving average low-pass filter: output = 1 - (output of 'delay-free' MA) Frequency response fs/n This is the 'ODBA' filter The delay-free MA and the delay-free MA HPF are complementary filters. They divide the frequency range into low frequency and high frequency parts without a gap. This is useful for comparing low frequency and high frequency behaviours. Note!! Making a HPF from 1 -MA (i. e. , the one with delay) gives a different response. MA and 1 -MA are NOT complementary.
Filters in Tagtools Many of the tagtools function use filters and all filters are delay-free. Filters are symmetric FIR filters based on window functions. These give steeper and flatter filters than the MA filter but have much longer memory. 1 -MAdelay-free FIR HPF In tagtools, odba uses a FIR high-pass filter with memory of 4/fc seconds. You can also use odba('wilson') to get the 1 -MA filter that Rory suggests. fir_nodelay performs general delay-free filtering. comp_filt performs complementary filtering using delay-free filters. decdc and decz perform delay-free decimation (more on this shortly).
Converting analogue signals into digital Acceleration, position, orientation. . . are continuous signals in the real world. They have to be digitized to get vectors of numbers in a computer. This happens deep in the tag electronics. What effect does digitizing have on signals? How fast should sensors be sampled?
Digitizing involves two steps: 1. Sampling: the signal is approximated by a series of numbers with regular sampling interval. 2. Quantization: computers use a limited range of numbers – the signal amplitude is represented by the closest number available. resolution sampling interval = 1 / sampling frequency
How fast should you sample ? High sampling rates generate a lot of data e. g. an accelerometer sampled at 100 Hz produces 50 MB/day Why not sample slowly? Sperm whale dive profile Nyquist rule: Sampling rate must be greater than 2 x the highest frequency in the signal This applies to ALL signals.
What sampling does to the spectrum 'Nyquist' rate Level propulsion signal Sampling rate accelerometer noise floor 2 nd harmonic Level 0 24 Frequency, Hz 48 Sampling FOLDS the spectrum at multiples of the Nyquist rate.
Level Aliasing 0 frequency, Hz 24 f 48 Level Spectra above the Nyquist rate (but less than the sampling rate) are REVERSED and appear at fs-f 0 fs-f frequency, Hz f. N The sampled signal is also noisier because high frequency energy is ALIASED to lower frequencies.
Anti-aliasing filters Sensor Low-pass filter Digitizer Aliasing can be avoided by building-in a low-pass filter before the digitizer. Some sensors include anti-alias filters, some do not. It is hard to find out. Safest practice is to sample fast enough so that aliasing won't occur for any expected signal. For magnetometers, this means sampling at > 4 x stride frequency. For accelerometers, much higher sampling rates may be needed to avoid aliasing abrupt movement transients.
Changing the sampling rate of signals Reducing the sampling rate of a signal after it has been recorded is decimation. To reduce the sampling rate by a factor of n, just pick one sample out of every n. But: this is re-sampling so an anti-alias low-pass filter is needed first. Example: Decimate acceleration by 25 to get 1 Hz sampling rate. Without an anti-alias filter, the result has jumps if there are transients in the original signal. With an anti-alias filter you get a resolution improvement of 5 x. Tagtools: decdc and decz
Interpolating - three ways you might need it 1. Increase the sampling rate of a signal after it has been recorded, e. g. , to match the sampling rate of another sensor. - Remember that the frequency range of the sensor doesn't increase! - Octave and Matlab functions: interp and resample 2. To time-align sensors that are sampled asynchronously, e. g. , in separate tags. - This is dangerous because you don't know how the clocks in each tag drift during the deployment. - Find time alignment opportunities in the data (e. g. , correlating features in a sensor that both tags have). - Tagtool for Lanczos interpolation in development. 3. To bridge outages. Some tags have occasional gaps in sampling. - Short outages can be bridged using e. g. , interp 1 in Octave/Matlab (polynomial or spline interpolator). - Longer outages: better to put Na. N in the data than fill with fake data.
Dynamic range and overloading Sensors use a fixed set of numbers to represent samples, e. g. , a 10 bit sensor digitizes the signal into numbers between 1 and 1024. This sets the biggest and smallest signal that can be acquired. The ratio of these is the dynamic range. Large signals will overload the sensor and appear clipped. Small signals will be lost in the granularity of the sampled data. BUT sampling at a high rate helps: decimating improves resolution.
SUMMARY 1. Periodic signals have harmonics. The Fourier transform tells you how much of each harmonic there is. 2. For random signals you estimate the power spectrum by averaging the squared magnitude of the FT of many pieces of the signal. 3. Real signals can be periodic, random or transient, for short times. Spectrograms are useful to visualize them. Each bar of a spectrogram is the FT of a piece of the signal. The FT length determines the frequency and time resolution. 4. Filters change the frequency content of a signal and its correlation in time. Low-pass filters smooth data. High-pass filters remove slow trends in data. Complementary filters do both at once. 5. Use delay-free filters to keep time-alignment between sensor channels. 6. Use a low-pass filter to avoid aliasing when changing the sampling rate of data (and in your sensors if possible).
- Slides: 46