+ All Categories
Home > Documents > Matlab (Advanced) - Otto von Guericke University · PDF filePost-processing using Matlab...

Matlab (Advanced) - Otto von Guericke University · PDF filePost-processing using Matlab...

Date post: 08-Mar-2018
Category:
Upload: phungdat
View: 221 times
Download: 2 times
Share this document with a friend
34
1 Dominique Thévenin Lehrstuhl für Strömungsmechanik und Strömungstechnik (LSS) [email protected] OvGU Vorlesung « Messtechnik » Post-processing using Matlab (Advanced)
Transcript
Page 1: Matlab (Advanced) - Otto von Guericke University · PDF filePost-processing using Matlab (Advanced)! 2 ... Random noise is generated under Matlab using rand ... we use a pre-defined

1

Dominique Thévenin!Lehrstuhl für Strömungsmechanik und

Strömungstechnik (LSS)[email protected]!

OvGU!Vorlesung « Messtechnik »!

Post-processing using Matlab (Advanced)!

Page 2: Matlab (Advanced) - Otto von Guericke University · PDF filePost-processing using Matlab (Advanced)! 2 ... Random noise is generated under Matlab using rand ... we use a pre-defined

2

Noise filtering (1/2)! We have discussed the last time how to filter (random) noise!

 Execute again filternoise_demo.m!

 Considering a signal composed of the superposition of a sinus wave at frequency f1=1 Hz with amplitude A1, plus random noise with amplitude A2!

 Random noise is generated under Matlab using rand (value between 0 and 1)!

Page 3: Matlab (Advanced) - Otto von Guericke University · PDF filePost-processing using Matlab (Advanced)! 2 ... Random noise is generated under Matlab using rand ... we use a pre-defined

3

Noise filtering (2/2)! For random noise, something like h=h+A2*(rand(size(h))-0.5);

 Test different cut-off frequencies for your filter, from 50 down to 2 Hz for example!

 Test different amplitudes, for example!

 A1=2, A2=1: signal to noise amplitude = 4!

 A1=1, A2=2: signal to noise amplitude = 1

 Observations?!

Page 4: Matlab (Advanced) - Otto von Guericke University · PDF filePost-processing using Matlab (Advanced)! 2 ... Random noise is generated under Matlab using rand ... we use a pre-defined

4

Understanding better filtering! Download and execute filter_demo.m Check the script to superpose signals with frequency of 1 Hz (f1) and 100 Hz (f2):  Both frequencies are well separated (factor 100)!  The signal looks like that:

Page 5: Matlab (Advanced) - Otto von Guericke University · PDF filePost-processing using Matlab (Advanced)! 2 ... Random noise is generated under Matlab using rand ... we use a pre-defined

5

Filtering (1/3)! One of the most useful application of FFT is filtering!

 You can decide freely which frequency domain should be filtered out!! Typically, you will use a low-pass filter, in order to remove « experimental noise ». Noise is normally always located at high frequencies...!

 In our present example, we consider that « noise » is the signal at 100 Hz, while the signal at 1 Hz is the « information » that should be acquired... !

Page 6: Matlab (Advanced) - Otto von Guericke University · PDF filePost-processing using Matlab (Advanced)! 2 ... Random noise is generated under Matlab using rand ... we use a pre-defined

6

Filtering (2/3)! In order to filter the signal at a given frequency, it is necessary to set the corresponding part of the DFT H(f) to 0!

 But the DFT is imaginary...! Therefore, we must of course set to 0 both the real and the imaginary component!!

 Either separately (working on HR and HI)!

 or directly (working on H)!

Page 7: Matlab (Advanced) - Otto von Guericke University · PDF filePost-processing using Matlab (Advanced)! 2 ... Random noise is generated under Matlab using rand ... we use a pre-defined

7

Filtering (3/3)!

high frequency!

suppress by filtering !

low frequency!

keep!!

Page 8: Matlab (Advanced) - Otto von Guericke University · PDF filePost-processing using Matlab (Advanced)! 2 ... Random noise is generated under Matlab using rand ... we use a pre-defined

8

Script for filtering! Identify in your script the correct frequency domain (we decide: filtering everything from 50 Hz up to the Nyquist frequency)!

 Code the cut-off frequency in a flexible manner using a variable...!

 Set the corresponding part of the DFT to 0 (complex value)!

 Compute the inverse FFT using ifft, and look at the result, by comparison with the original signal!!

Page 9: Matlab (Advanced) - Otto von Guericke University · PDF filePost-processing using Matlab (Advanced)! 2 ... Random noise is generated under Matlab using rand ... we use a pre-defined

9

Energy Spectral Density (ESD)! The energy spectral density describes how the energy of a signal is distributed with frequency. It is nothing else than the square of the magnitude of the Fourier transform!

Page 10: Matlab (Advanced) - Otto von Guericke University · PDF filePost-processing using Matlab (Advanced)! 2 ... Random noise is generated under Matlab using rand ... we use a pre-defined

10

Power Spectral Density (PSD)! If the global mean value of a signal is not 0 and has not been removed, the ESD tends toward infinity for long sequences!

 Indeed, for such a case, it will become at some point even impossible to compute the DFT! As an alternative, it is still possible to compute the Power Spectral Density (PSD)! Physically, the computation of the PSD uses an overlapping segmentation of the original signal, followed by corresponding DFT computations and final re-assembling by averaging!

1! N!

Page 11: Matlab (Advanced) - Otto von Guericke University · PDF filePost-processing using Matlab (Advanced)! 2 ... Random noise is generated under Matlab using rand ... we use a pre-defined

11

Practical ESD/PSD computation! Relies on the complex script structure spectrum

 See help spectrum for more information!

 Several different methods have been coded to compute numerically a PSD!

 It will first be necessary to define an appropriate handle to receive the information, for example through ! HWelch=spectrum.welch;

 Afterwards, the PSD of the time signal h(t) can be computed as! HPSD=psd(HWelch,h,’Fs’,f)

 PSD are only necessary for very long signals with a high level of noise: you should not encounter this too often at first...!

Page 12: Matlab (Advanced) - Otto von Guericke University · PDF filePost-processing using Matlab (Advanced)! 2 ... Random noise is generated under Matlab using rand ... we use a pre-defined

12

Practical PSD computation!

sampling h(t) h(kΔt) hi(kΔt)

segmentation DFT

Hi(kΔf) 2

averaging PSD!

Page 13: Matlab (Advanced) - Otto von Guericke University · PDF filePost-processing using Matlab (Advanced)! 2 ... Random noise is generated under Matlab using rand ... we use a pre-defined

13

Script for PSD! Download and execute psd_demo.m!

 Considering a signal with a frequency of 10 Hz, plus noise!

 Code the cut-off frequency in a flexible manner using a variable. Choose then first for example 50 Hz.!

 Compare the efficiency of both methods (basic filtering, PSD determination)!

 Solution: psd_demo.m!

Page 14: Matlab (Advanced) - Otto von Guericke University · PDF filePost-processing using Matlab (Advanced)! 2 ... Random noise is generated under Matlab using rand ... we use a pre-defined

14

Where do we stand?! We know how to carry out frequency analysis and filtering

  Using DFT! Wavelet will be soon an alternative...

  But DFT can do even more!

Page 15: Matlab (Advanced) - Otto von Guericke University · PDF filePost-processing using Matlab (Advanced)! 2 ... Random noise is generated under Matlab using rand ... we use a pre-defined

15

Correlation! It is often essential to determine the correlation between two signals!

 This means: « how similar are the two signals, determined in a quantitative manner ?»!

 The DFT can be used in an extremely efficient manner to determine this correlation based on a frequency analysis!

 This is in particular due to the mathematical property:!

 DFT(correlation between h(t) and g(t))=N H*(f) G(f)! Means: the DFT of the correlation is the “product” of the DFTs of the two signals, multiplied by the signal length (N)!

 As a consequence, it is sufficient to compute the individual DFTs to quantify the correlation!!

Page 16: Matlab (Advanced) - Otto von Guericke University · PDF filePost-processing using Matlab (Advanced)! 2 ... Random noise is generated under Matlab using rand ... we use a pre-defined

16

Normalizing the correlation! Obviously, the best possible correlation should be obtained for two identical signals!

 The general equation delivers in this case:! DFT(correlation between h(t) and h(t))=N H*(f) H(f)!

! ! ! != N ||H(f)||2!

 As a consequence, the definition of the normalized correlation (value between -1 and 1, with 0=no correlation at all) between a known, reference function h(t) and a test function g(t) becomes:! Cor(h(t),g(t))=iDFT(H*(f) G(f) / (||H(f)|| ||G(f)||))!

Page 17: Matlab (Advanced) - Otto von Guericke University · PDF filePost-processing using Matlab (Advanced)! 2 ... Random noise is generated under Matlab using rand ... we use a pre-defined

17

Script to compute correlation! Download and execute correl_demo.m!

 We will now introduce a second time signal g, identical in length and discretization to h, but containing different information!

Page 18: Matlab (Advanced) - Otto von Guericke University · PDF filePost-processing using Matlab (Advanced)! 2 ... Random noise is generated under Matlab using rand ... we use a pre-defined

18

Script to compute correlation! Test in particular:!  g = h   g = -h   g = 2*h   g = 2*h + 13   g = (5-2*h).^2   g = 1   g = h+A2*(rand(size(h))-0.5) with A2 from 0.005 to 0.5! Observations?! Solution: correl_demo.m!

Page 19: Matlab (Advanced) - Otto von Guericke University · PDF filePost-processing using Matlab (Advanced)! 2 ... Random noise is generated under Matlab using rand ... we use a pre-defined

19

Compute correlation in Matlab! As a direct alternative, Matlab allows also the computation of correlations using the function! corrcoef  The information we need is contained outside of the diagonal!

C(h1,h1) !C(h1,h2)!

C(h2,h1) !C(h2,h2)!

 Implemented for comparison in your script (see help corrcoef for more information)!

Page 20: Matlab (Advanced) - Otto von Guericke University · PDF filePost-processing using Matlab (Advanced)! 2 ... Random noise is generated under Matlab using rand ... we use a pre-defined

20

Introducing Wavelets (1/2)! Wavelets have been defined in the 50s!

 as a complement to classical Fourier analysis!

 Why extend the Fourier analysis at all?!

 Drawback of FFT: by transformation, the time information is completely lost when obtaining the frequency spectrum!

 It is thus impossible to know at which time an event took place!

 A choice is needed: either time or frequency, not both!!

Page 21: Matlab (Advanced) - Otto von Guericke University · PDF filePost-processing using Matlab (Advanced)! 2 ... Random noise is generated under Matlab using rand ... we use a pre-defined

21

Introducing Wavelets (2/2)! If the signal does not change (in a statistical sense) with time, this is not a problem!!

 This was the case in all our examples up to now.! This covers also most simple applications, and 50% of more complex applications.!

 But when considering signals with drift, monotonous increase/decrease, abrupt changes, and near the boundaries of the time signal, changes in time become significant, and cannot be analyzed with FFT.!

 Time variations must then be taken into account!!

Page 22: Matlab (Advanced) - Otto von Guericke University · PDF filePost-processing using Matlab (Advanced)! 2 ... Random noise is generated under Matlab using rand ... we use a pre-defined

22

Short-time Fourier analysis! To solve this problem, D. Gabor introduced the short-time Fourier analysis!

 It is simply a DFT relying on windowing the signal! The window has a constant, user-defined size!

 We now have an analysis both in time and frequency!

 But using a constant-size window limits the possible resolution in both dimensions %

Page 23: Matlab (Advanced) - Otto von Guericke University · PDF filePost-processing using Matlab (Advanced)! 2 ... Random noise is generated under Matlab using rand ... we use a pre-defined

23

Wavelet analysis! As a final evolution, the wavelet analysis introduces windowing on variable-sized regions!

 Long window sizes are employed where accurate low-frequency information is required, shorter windows are used where high-frequency information is important.!

 We now have an analysis both in time and frequency (or scale)!

 With an optimally-adapted window size!

Page 24: Matlab (Advanced) - Otto von Guericke University · PDF filePost-processing using Matlab (Advanced)! 2 ... Random noise is generated under Matlab using rand ... we use a pre-defined

24

wavelet

Advantage of Wavelet analysis! Wavelets can reveal aspects of data that DFT completely miss (trends, breakdown points, discontinuities, fractal nature...)!

fft

time point 100!

time point 100!

Page 25: Matlab (Advanced) - Otto von Guericke University · PDF filePost-processing using Matlab (Advanced)! 2 ... Random noise is generated under Matlab using rand ... we use a pre-defined

25

Fourier analysis vs. Wavelet (1/2)! The Fourier analysis breaks up a signal into sine waves of various frequencies!

 The function « sin » is the basis function for decomposition! This function extends from -∞ to +∞, and is thus not well suited for a local analysis!

Page 26: Matlab (Advanced) - Otto von Guericke University · PDF filePost-processing using Matlab (Advanced)! 2 ... Random noise is generated under Matlab using rand ... we use a pre-defined

26

Fourier analysis vs. Wavelet (2/2)! The Wavelet transform uses other basis functions, called wavelet functions!

 These wavelet functions are local in space! Different families of wavelet functions exist!

 The decomposition is then similar to FFT!

Page 27: Matlab (Advanced) - Otto von Guericke University · PDF filePost-processing using Matlab (Advanced)! 2 ... Random noise is generated under Matlab using rand ... we use a pre-defined

27

Scaling / shifting wavelet functions! Scaling!  Shifting!

Page 28: Matlab (Advanced) - Otto von Guericke University · PDF filePost-processing using Matlab (Advanced)! 2 ... Random noise is generated under Matlab using rand ... we use a pre-defined

28

Understanding wavelet output!

Time-information is not lost!!

Frequency=1/(time scale)!

low f !

high f !

Page 29: Matlab (Advanced) - Otto von Guericke University · PDF filePost-processing using Matlab (Advanced)! 2 ... Random noise is generated under Matlab using rand ... we use a pre-defined

29

First hands-on: noisy signal! For this basic example, we use a pre-defined noisy signal of Matlab, comprising 1000 points with a sampling period of 1 (« s »).! From Matlab, type! load noissin  plot noissin

Page 30: Matlab (Advanced) - Otto von Guericke University · PDF filePost-processing using Matlab (Advanced)! 2 ... Random noise is generated under Matlab using rand ... we use a pre-defined

30

Wavelet analysis (1/2)! The wavelet analysis is realized with the instruction cwt (for Continuous Wavelet Transform)!

 From Matlab, type! c = cwt(noissin,1:48,’db4’)

signal to process!scales to consider!

Wavelet basis function!(here Daubechies type 4)!

Page 31: Matlab (Advanced) - Otto von Guericke University · PDF filePost-processing using Matlab (Advanced)! 2 ... Random noise is generated under Matlab using rand ... we use a pre-defined

31

Wavelet analysis (2/2)! The variable c contains the output of the wavelet analysis.!

 For a direct graphical representation, add a last flag! c = cwt(noissin,1:48,’db4’,’plot’);

Page 32: Matlab (Advanced) - Otto von Guericke University · PDF filePost-processing using Matlab (Advanced)! 2 ... Random noise is generated under Matlab using rand ... we use a pre-defined

32

Choosing the scales! The choice of the scales is essential for the analysis!

 All scales must be real, positive, increasing and are bounded by the length of the signal. Try:! c = cwt(noissin,2:2:128,’db4’,’plot’)

 Periodicity is now visible!

(about 5 periods)!

Page 33: Matlab (Advanced) - Otto von Guericke University · PDF filePost-processing using Matlab (Advanced)! 2 ... Random noise is generated under Matlab using rand ... we use a pre-defined

33

Further 1D examples! Use the Wavelet GUI wavemenu

 Choose wavelet 1-D

 Load File/Example Analysis/Basic Signals  Frequency Breakdown (2 different frequencies in time)!

Page 34: Matlab (Advanced) - Otto von Guericke University · PDF filePost-processing using Matlab (Advanced)! 2 ... Random noise is generated under Matlab using rand ... we use a pre-defined

34

Image processing! Use the Wavelet GUI wavemenu

 Choose SWT Denoising 2-D

 Load File/Example Analysis/Indexed Images  Choose noisywoman

 Try to modify the parameters for a better result!


Recommended