Presentation is loading. Please wait.

Presentation is loading. Please wait.

BME452 Biomedical Signal Processing

Similar presentations


Presentation on theme: "BME452 Biomedical Signal Processing"— Presentation transcript:

1 BME452 Biomedical Signal Processing
Lecture 4 Fourier analysis and spectral estimation Lecture 4 BME452 Biomedical Signal Processing 2013 (copyright Ali Işın, 2013) Copyright 2013 A. IŞIN. All rights reserved.

2 Lecture 4 Outline In this lecture, we’ll study the frequency domain analysis methods for signals Discrete Fourier transform Classical spectral estimation Some examples of spectral estimation of signals Lecture 4 BME452 Biomedical Signal Processing 2013 (copyright Ali Işın, 2013) Copyright 2013 A. IŞIN. All rights reserved.

3 Introduction Knowledge of cyclic or oscillating activity in signals is very important Fourier transform is the oldest method for analysing the cycles, i.e. obtaining frequency information Eg: analysing the cycle of variable stars is the oldest application of analysing cycles Variable stars are, quite simply, stars that change brightness An example is given below: What is the approximate period? Figure from R.Shiavi, Introduction to applied statistical signal analysis Lecture 4 BME452 Biomedical Signal Processing 2013 (copyright Ali Işın, 2013) Copyright 2013 A. IŞIN. All rights reserved.

4 Discrete Fourier Transform
Since we are dealing with discrete-time signals, we will skip continuous Fourier transform and move into discrete Fourier transform (DFT) Discrete time and frequency We have discrete time, similarly, we can have only discrete frequencies Discrete frequency Assume N is the number of sampled points Define the duration of the signal, P=NT, where T is the sampling interval We have the discrete frequency variable (frequency number), m The frequency number of m will run from 1 to N The actual frequency will run from 0 to fs/2 with fd intervals So, the frequency spacing, fd=1/NT or fd=fs/N Lecture 4 BME452 Biomedical Signal Processing 2013 (copyright Ali Işın, 2013) Copyright 2013 A. IŞIN. All rights reserved.

5 Discrete Fourier Transform (cont)
Some important points The actual frequency =m*fd=m*fs/N from 0 to fs Frequency number, m=0,1,2,3,…..N points Due to symmetry, we normally plot the values from 0 to fs/2 only Lecture 4 BME452 Biomedical Signal Processing 2013 (copyright Ali Işın, 2013)

6 Actual frequency vs frequency number
Consider the following example Time = 2s, N=12 => fs = 6 Hz Frequency plot is from 0 to 3 Hz m=0,1.....N/2 (the rest of N/2 points rejected due to symmetry in freq domain) So, m = 0,1,2,3,4,5,6 Actual frequency => (m*fs)/N So, actual frequency => 0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0 Lecture 4 BME452 Biomedical Signal Processing 2013 (copyright Ali Işın, 2013)

7 Discrete Fourier Transform (cont)
DFT is used computationally to perform Fourier analysis of discrete-time signals DFT is defined as Inverse DFT (IDFT) is defined as Note: i and j will be used to represent Lecture 4 BME452 Biomedical Signal Processing 2013 (copyright Ali Işın, 2013) Copyright 2013 A. IŞIN. All rights reserved.

8 Discrete Fourier Transform (cont)
Using Euler’s relation, So (why?) Now, DFT is Lecture 4 BME452 Biomedical Signal Processing 2013 (copyright Ali Işın, 2013) Copyright 2013 A. IŞIN. All rights reserved.

9 Discrete Fourier Transform (cont)
As you can see, DFT now consist of a real part and an imaginary for every frequency number m The magnitude spectra And phase spectra where Normally, we are interested in this for signals Lecture 4 BME452 Biomedical Signal Processing 2013 (copyright Ali Işın, 2013) Copyright 2013 A. IŞIN. All rights reserved.

10 Discrete Fourier Transform using MATLAB
for m=1:N, sumn=0; for n=1:N, sumn=sumn + x(n)*(cos (2*pi*(m-1)*(n-1)/N)); end dftreal(m)=T*sumn; sumn=sumn + x(n)*(sin (2*pi*(m-1)*(n-1)/N)); dftimag(m)=-T*sumn; dftmag(m)=sqrt(dftreal(m)*dftreal(m)+dftimag(m)*dftimag(m)); dftphase(m)=atan(dftimag(m)/dftreal(m)); You can also use fft function in MATLAB, do you know what is fft? Lecture 4 BME452 Biomedical Signal Processing 2013 (copyright Ali Işın, 2013) Copyright 2013 A. IŞIN. All rights reserved.

11 A worked example of DFT The table shows the intensity of ionospheric reflections starting from midnight Assume fs=24 (i.e. hours in a day) T=1/24, N=12 plot(x); axis([ ]); title('Ionospheric data'); xlabel('Time (h) - note it should one less'); ylabel('Intensity'); Time(hrs) Intensity 6 1 20 2 28 3 8 4 5 -7 7 9 -14 10 -19 11 -12 Figure from R.Shiavi, Introduction to applied statistical signal analysis MATLAB indexes from 1, so 1 must be reduced from this index to push it back to 0 Figure from MATLAB Lecture 4 BME452 Biomedical Signal Processing 2013 (copyright Ali Işın, 2013) Copyright 2013 A. IŞIN. All rights reserved.

12 Ionospheric DFT Note the symmetry line.
plot(dftreal,'+-'); xlabel('Frequency number (m)'); ylabel('Magnitude'); hold on; plot(dftimag,'r*-'); axis([ ]); xlabel('Frequency number (m) - note it should one less'); title('Real and imaginary parts'); Figure from R.Shiavi, Introduction to applied statistical signal analysis Note the symmetry line. DFT phase is conjugate symmetry at this line. Y= a+jb Y*=a-jb Frequency number or actual frequency value?? If the frequency number is m, the actual frequency values are m*fs/N –more on this later Figure from MATLAB Lecture 4 BME452 Biomedical Signal Processing 2013 (copyright Ali Işın, 2013) Copyright 2013 A. IŞIN. All rights reserved.

13 Ionospheric Spectra Figure from R.Shiavi, Introduction to applied statistical signal analysis Figure from MATLAB For magnitude and phase spectra, the actual frequencies are m*fs/N So, actual freq => 2m, i.e. as m=0,1,2,3,4,5,….11 and 2m=0,2,4,6,8,10 cycles/day Lecture 4 BME452 Biomedical Signal Processing 2013 (copyright Ali Işın, 2013) Copyright 2013 A. IŞIN. All rights reserved.

14 Ionospheric Spectra (cont.)
Some points to note Normally the magnitude spectra is the output that we want from DFT Magnitude spectra measure the energy of the signal at the specific frequencies Magnitude spectra runs from f=0 to one point less than fs/2 with N/2 points, i.e. fs/N frequency spacing In the example, fs=24, N=12, so the actual frequency scale runs from 0,2,4,6,8,10 Hz But DFT is plotted in frequency numbers for N points, so frequency number runs from 0,1,2,3,4,….,11 Lecture 4 BME452 Biomedical Signal Processing 2013 (copyright Ali Işın, 2013) Copyright 2013 A. IŞIN. All rights reserved.

15 Picket fence effect One of the problem with DFT is that it provides values of X(m) only at a specific set of frequencies What if an important value exist at the frequency, f≠m? In our example, we have magnitude spectra values for freq=0,2,4,6,8,10 What if there was an important cycle with freq=1? We would have missed it! This problem is known as picket fence effect Lecture 4 BME452 Biomedical Signal Processing 2013 (copyright Ali Işın, 2013) Copyright 2013 A. IŞIN. All rights reserved.

16 Zero padding to increase the DFT resolution
The solution is to increase the signal size by zero padding This will increase N and hence reduce the frequency spacing And increase the resolution of DFT Example, assume we pad 12 zeros to the ionospheric signal and compute the magnitude spectra So, now N=24 Freq spacing =fs/N=24/24=1 And frequency scale has 12 points and has values for freq= 0,1,2,3,4,5,6,7,8,9,10,11 From the plot, we can see that there are values for freq=1,3,5,…. Figure from R.Shiavi, Introduction to applied statistical signal analysis Lecture 4 BME452 Biomedical Signal Processing 2013 (copyright Ali Işın, 2013) Copyright 2013 A. IŞIN. All rights reserved.

17 Effect of truncation When we compute DFT, we assume that the signal is one complete cycle extracted from a portion of a longer signal that is periodic This is a basic assumption of DFT That is, we have truncated the signal (though in reality we did not) If the signal was indeed periodic, it would the same starting and ending points after truncation But then for our signals, we have discontinuity, so this creates a lot of noise Technically this problem is known as spectral leakage but we won’t worry about this term In the ionospheric signal example: Ionospheric signal Truncate Discontinuity at truncation points We have this signal in reality We assume that we truncate a ‘longer periodic’ signal to computer DFT Lecture 4 BME452 Biomedical Signal Processing 2013 (copyright Ali Işın, 2013) Copyright 2013 A. IŞIN. All rights reserved.

18 Windowing Now, assume if we have the triangular signal as shown below
Will there be a problem with DFT? No, because the start and end points are the same Very often, we consider using windows other than rectangular window to ‘force’ the signal value at the beginning and end to the same value Normally, this value is zero, though not always But how we do this? We use spectral windows like those on the right Figure from R.Shiavi, Introduction to applied statistical signal analysis Triangular signal Lecture 4 BME452 Biomedical Signal Processing 2013 (copyright Ali Işın, 2013) Copyright 2013 A. IŞIN. All rights reserved.

19 Windowing (cont.) The simplest window is the rectangular window
Using this window, the value at beginning (n=0) and end of signal (n=N-1) is set to zero But this creates discontinuity at second and second last points, i.e. between points n=0 and n=1 and at points n=N-2 and n=N-1 So, if we continue to reduce discontinuity using this window, we land up with a zero signal! To solve this, we can use smoothed windows like Triangular, Blackman, Hamming, etc. The new windowed signal for every point n, y[n]=x[n]*w[n] Some window functions: Blackman: Hamming: Triangular: For these functions, n is the window size (i.e. N) These window equations will not be tested Lecture 4 BME452 Biomedical Signal Processing 2013 (copyright Ali Işın, 2013) Copyright 2013 A. IŞIN. All rights reserved.

20 Windowing (examples) The following show the magnitude spectra of an EEG signal: Windowing gives a smoother DFT The choice of windowing is too complex for this course, it involves analysis of ratios of magnitudes main lobes and side lobes So, we’ll skip them and choose any window (other than rectangular) Original, no windowing Do you know the sampling frequency of the EEG from the plot? Hamming windowing Rectangular windowing Lecture 4 BME452 Biomedical Signal Processing 2013 (copyright Ali Işın, 2013) Copyright 2013 A. IŞIN. All rights reserved.

21 Detrending Another aspect similar to windowing is the removal of polynomial time trends and average value The average value, which has energy around zero frequency can be removed simply by setting the mean to zero The polynomial time trends have energy at very low frequencies We’ll study some high pass filtering methods in the next lecture to remove this polynomial trend This is known as detrending. Look at the example below: After detrending Before detrending Figures from R.Shiavi, Introduction to applied statistical signal analysis Lecture 4 BME452 Biomedical Signal Processing 2013 (copyright Ali Işın, 2013) Copyright 2013 A. IŞIN. All rights reserved.

22 DFT applied to some artificial signals
Consider the sinusoidal wave with frequency=10 and fs=200 N=200; X=sin(2*pi*(1:N)*10/200); plot(X); The signal and magnitude spectra are shown below The same signal but length N=20 Theoretically, is there anything wrong with computing Fourier spectra for this signal this way if fs is known? Do you need windowing for this signal? What has happened – what is the actual frequency now? Since fd=fs/N=10, MATLAB indexes from 1, so 1 must be reduced from this index to push it back to 0 Freq(Hz) =(m-1)*fs/N =(2-1)*10 Hz = 10 Hz Lecture 4 BME452 Biomedical Signal Processing 2013 (copyright Ali Işın, 2013) Copyright 2013 A. IŞIN. All rights reserved.

23 DFT applied to some artificial signals (cont.)
Consider combination of sinusoidal waves with frequency=8 and 25 and fs=200 N=25;fs=200;f1=8;f2=25; X=sin(2*pi*(1:N)*f1/fs)+sin(2*pi*(1:N)*f2/fs); plot(X); The signal and magnitude spectra are shown below Theoretically, the minimum N for this signal must N=25. Why? The magnitude spectra does show two peaks but there is a problem – what is it? MATLAB indexes from 1, so 1 must be reduced from this index to push it back to 0 Remember: Freq (Hz)=(m-1)*fs/N The same signal but length N=200 - Peak at 9 and 26 =>Spectra at 8 and 25 Hz - Both have same magnitude In reality, DFT works properly only if there are multiple cycles and not just one cycle And there must enough resolution, i.e. N must be large Lecture 4 BME452 Biomedical Signal Processing 2013 (copyright Ali Işın, 2013) Copyright 2013 A. IŞIN. All rights reserved.

24 DFT- a worked example Consider the following frequency spectra (the frequency axis should be up to 500 but is shown partially only) Given N=1000 and fs=200, find out the values for f1, f2, A1, A2 for MATLAB code : X=A1*sin(2*pi*(1:N)*f1/fs)+A2*sin(2*pi*(1:N)*f2/fs); The peaks are at 51 and 91 Answer Freq (Hz)=(m-1)*fs/N A1=1.0 A2=0.5 f1=10 f2=18 The ratio of A1/A2 has to be 2 but the exact values could be different Lecture 4 BME452 Biomedical Signal Processing 2013 (copyright Ali Işın, 2013) Copyright 2013 A. IŞIN. All rights reserved.

25 Power spectral density estimation, classical approaches
There are 3 common PSD estimation using classical approaches Periodogram Welch method Using autocorrelation function (but will not be studied here) There is a recent advanced parametric method on PSD estimation based on autoregressive modelling but this will not be studied here. Lecture 4 BME452 Biomedical Signal Processing 2013 (copyright Ali Işın, 2013) Copyright 2013 A. IŞIN. All rights reserved.

26 What is Power Spectral Density?
PSD is similar to the square of magnitude spectra Actually, the only difference is the scale factor So, PSD=power per unit frequency (in dB) If we compute magnitude spectra using DFT, convert it to PSD, then we have periodogram Sometimes known as Blackman-Tukey method You can use the codes below OR use psd(x) or periodogram(x) functions N=200;fs=100;f1=5; X=sin(2*pi*(1:N)*f1/fs); plot(X); Y=fft(X,N); Pyy = sqrt((Y.* conj(Y))) /(0.5*N); plot(Pyy(1:N/2)); PSD=10*log10(Pyy.*Pyy); plot(PSD(1:N/2)) Lecture 4 BME452 Biomedical Signal Processing 2013 (copyright Ali Işın, 2013) Copyright 2013 A. IŞIN. All rights reserved.

27 Computing PSD using Welch method
An improvement to periodogram Normally gives a smoother PSD The method Segmentation with overlap The sample data is divided into K segments each containing M sample points Initial data points in each segment are separated by D (i.e. non-overlap length is D) Segments overlap with M-D samples and K=(N-M)/D +1 segments are formed The percent overlap is 100*(M-D)/M Apply the conventional periodogram (i.e. DFT) to compute PSD In MATLAB, use pwelch(x) function where the percentage overlap is 50% and Hamming window is used Lecture 4 BME452 Biomedical Signal Processing 2013 (copyright Ali Işın, 2013) Copyright 2013 A. IŞIN. All rights reserved.

28 Computing PSD using Welch method (example)
Assume we have an EEG signal with N=125 The first plot is obtained by using psd, while the second is obtained by using pwelch with each segment, M=50 D=25 (since overlap percentage is 50%) So, overlap of M-D=25 points and K=(125-50)/25+1=4 From the plots, pwelch is more smoother and very often more accurate than psd/periodogram PSD frequency scale is normalised and in radian instead of cycles 0 to fs  0 to 2 in (Hz   rad/sample) So, 0 to fs/2  0 to  Lecture 4 BME452 Biomedical Signal Processing 2013 (copyright Ali Işın, 2013) Copyright 2013 A. IŞIN. All rights reserved.

29 Homework 1 - DFT (worked example)
Compute the DFT for the ionospheric data and see if you get the values as in the table Next compute the magnitude and phase spectra and see if you get the values in the plots as below Lecture 4 BME452 Biomedical Signal Processing 2013 (copyright Ali Işın, 2013) Copyright 2013 A. IŞIN. All rights reserved.

30 Homework 2 For the following noise corrupted signal, window the signal using triangular window, then compute the magnitude spectra (using MATLAB) Can you get similar plots as below? Use the codes below (fft is used) N=100;fs=200;f1=35; X=sin(2*pi*(1:N)*f1/fs)+rand(1,N); plot(X); Y=fft(X,N); Pyy = sqrt((Y.* conj(Y))) /(0.5*N); plot(Pyy(1:N/2)); W=triang(N); X=X'.*W; plot(X); Lecture 4 BME452 Biomedical Signal Processing 2013 (copyright Ali Işın, 2013) Copyright 2013 A. IŞIN. All rights reserved.

31 Study guide (Lecture 4) From this week’s lecture, you should know how to compute Discrete Fourier Transform PSD estimation using classical methods (periodogram, Welch) You will need to remember all the equations in this lecture Note: the use of MATLAB codes will never be tested in the exam. For example, you will never be tested on what is fft(x), what is psd(x), etc. or how to use them. End of lecture 4 Lecture 4 BME452 Biomedical Signal Processing 2013 (copyright Ali Işın, 2013) Copyright 2013 A. IŞIN. All rights reserved.


Download ppt "BME452 Biomedical Signal Processing"

Similar presentations


Ads by Google