T=1 sec sinc function 3 angle(f(w)) T=2 sec angle(f(w)) 1
A quick script to plot mag & phase in MATLAB w=0:0.2:50; Real exponential func b=5; Fourier transform (filter) F=1.0./(b+j*w); subplot(211), plot(w, abs(f)); title( Real Exp *Step ); xlabel( frequency (rad/sec) ); ylabel( F(w) ); subplot(212), plot(w, angle(f)); title( Real Exp *Step ); xlabel( frequency (rad/sec) ); ylabel( phase angle ); 2
2D Fourier Transform (2DFT) Wave Equation (2D) 2 u(x,t) x 2 = 1 v 2 2 u(x,t) t 2 A particularly useful class of solutions: u(x,t) = Ae i(ωt ±kx) = A[cos(ωt ± kx) + isin(ωt ± kx)] k=wavenumber, v=speed, ω=angular frequency In fact, k could be a vector k in 3D, then we have several dimensions! v = w k (k expressed in radians/sec) This cons)tute a func)on of both wave number and frequency. To analyze the spectral characteris)cs we need to use a 2D Fourier Transform. Defini:on: The 2DFT of a func:on f(x,y) is defined as F(k x,k y ) = f (x, y) = 1 (2π) 2 Then inverse 2DFT is f (x, y)e j(k x x +k y y ) dxdy F(k x,k y )e j(k xx +k yy ) dk x dk y 3
Back to 1D seismic wave solution (assume propagating in +x direction): F(k,ω) = Ae j(ωt kx ) e j(ωt kx ) dxdt k=spatial frequency, ω=angular frequency=2π/t Other examples: Image compression or blurring/deblurring Image decompression: For a digital image, it is usually much simpler to save the coefs of number of discrete frequencies rather than the whole image. If need to reconstruct image, do Inv FT. As simple as doing these: (1) Load the image into a 2D matrix (2) Perform fft (2D) on this matrix (3) Multiplying frequencies with a function (of frequency), or simply remove small coefficients (4) Fft back to the space-time domain 4
2D FT seismic example: Velocity filter (I.e. F-k filter or dip filter) A seismic line contains 24 receivers, with 25 m spacing between two adjacent stations. The time shift is 15 ms/ trace. The total length of each seismogram is 1 sec, with sampling rate of 0.001 sec. Find the seismic velocity (or propagation speed) of the medium using 12 Hz wavelet. f k = v = 12 cycles/s 7.2 cycles/km =1.67 km/sec (phase vel)
2D fft Numerical example (dip filter) 25 m (see program fkdip.m) 15 ms w = 3.14159*2.0*12.0; % w=2*pi*freq Sample code: delta = 0.001; % sampling interval ss = -0.015; % phase delay between adjacent seismographs Y=[]; time=(0:delta:1.0); m=length(time); % number of time points for i=1:24 Computes w*(t-phi) ss = ss+0.015; xx=w*time-ss*w; y = cos(xx); Fill matrix columns by 6 Y = [Y y']; sinusoids end
2D FFT Algorithm: 1D FT a column of Y Save the coef in the same column Once columns all become coefs, do 1D transform a row at a time, replace old coefs with new coefs Matlab function: fft2() Spatial wavenumber (cycles/km) Now, to compute velocity, do f/k = (12 cycles/sec) / (7.2 cycles/km) = 1.67 km/s = phase vel Why the artifact? 7
Discretization and Discrete Signals So far, we have talked about continuous functions and Fourier Series/Transforms for them. Realistically, observations are better stored and operated on as discrete sample points. An infinite discrete signal f s (t) is obtained by sampling f(t) every Δt seconds, f s (t) = f (t) k= δ(t kδt) Where Δt is called the sampling interval (or sample rate). Time series: Discrete time function discrete step function 8
t=-4:6; % time axis, discrete at 1 sec per sample ft=[0-3 1 0 1 2 1 0-1 0 0]; % make a function f(t) figure; % start figure environment subplot(2,2,1); % make a figure with 4 subfigs, % 2 rows, 2 columns, plot 1st. stem(t,ft, 'filled'); % make a stem plot with filled circles title('any discrete function'); xlabel('t(sec)'); ylabel('f(t)'); subplot(2,2,2); % set up second panel delta=[]; % declare delta to be an array for i=1: length(t) if(t(i)<0) discrete_sig.m delta(i)=0.0; else delta(i)=1; end end stem(t,delta, 'filled'); % make a stem plot with filled circles title('discrete delta function'); xlabel('t(sec)'); ylabel('f(t)'); subplot(2,2,3); % set up 3rd panel for i=1: length(t) if(t(i)<0) delta(i)=0.0; else delta(i)=t(i); end end stem(t,delta, 'filled'); % make a stem plot with filled circles title('discrete unit ramp function'); xlabel('t(sec)'); ylabel('f(t)'); subplot(2,2,4); % set up 4th panel delta=cos(t); 9 stem(t,delta, 'filled'); % make a stem plot with filled circles title('discrete unit cosine function'); xlabel('t(sec)'); ylabel('f(t)');
Idea of Nyquist Frequency: A continuous signal can be well restored by a discrete signal with sampling interval Δt --->0. For a given time series with sampling interval Δt, the highest frequency that can be restored is 1/(2Δt) which is the Nyquist Frequency of the time series. f Nyquist = 1 2Δt ; Δt = sampling interval = f s /2; f s = 1/Δt = sampling frequency To be authentic f Nyquist f max f max = max frequency of a bandlimitted signal f s 2 f max f s 2 f max i.e.: f s must be greater or equal to twice the f max of the signal! What happens otherwise? ALIASING! Aliasing Problem 10
See provided matlab code nyquist_spec.m P 0.1 sec sampling S Rayleigh 0.2 sec sampling 0.8 sec sampling 11
Folding Frequency and Aliasing Example of sampling without aliasing: (see adached Matlab code nyquist_gt_fmax_4panels.m) Experiment Setup: Sinosoidal, signal frequency = 25 Hz Fn =1/(2*0.002)=250 Hz Fn =125 Hz Example of sampling causing aliasing: (see adached Matlab code nyquist_150hz. m). Signal freq=150 Hz 12
Effect of Undersampling: (1) Bandlimit the spectrum of a con:nuous signal, with the highest frequency equals the Nyquist frequency. (2) Introduce aliasing, I.e., frequencies above the Nyquist are lost ater sampling, but reappears at frequencies below the Nyquist. The high frequencies are not lost per say, but actually folded back onto the spectrum as low frequencies. --> contamina:on of low frequencies. Computa:on of Alias frequency f a = 2mf N f s f a is the folding (aliasing) frequency, f s is the signal (or input) frequency, m is the smallest integer such that f a < f N Example: Suppose f s =65 Hz, f N =62.5 Hz, find alias frequency. Graphically, Guess m=0, f a = 65 Hz > f N, no Guess m=1, f a = 60 Hz < f N, yes f a =60 f n =62.5 f s =65 FREQ (Hz) Solu)on to undersampling: (1) Nothing can be done about effect (1) (2) People typically use some type of filter to remove high 13 frequency signals above Nyquist. Then do Fourier spectrum.
Non-Matlab issues: A few important points Input is a real function, so symmetric amp spectrum (why? As proved before F(-w)=F*(w), which yields same F(w) ) As demonstrated, nonzero average --> 0 frequency (this is one of the reasons that seismologists detrend the data before doing fft or filter, see nyquist_spec_const.m, see next page). Nonzero frequencies seem to shift to lower end (close to 0) when under-sampled due to Aliasing. F(k) = N Matlab issues: FFT(x) returns the discrete Fourier transform (DFT) of vector x. For length N input vector x, the DFT is a length N vector F, with elements x(n) e j*2π *(k 1)*(n 1)/ N where 1 k N n=1 n is t in the discrete sense, 2π(k-1)/N is related to frequency ω.! Examples: dft_simple.m, dft_simple_odd.m, dft_fftshift.m f (n) = 1 N N X(k) e j*2π *(k 1)*(n 1)/ N where 1 n N k=1 Do you see a potential problem in this formulation?
The code is different from the earlier version by this line: ff=load('regional_eq.v'); t=ff(:,1); ft=ff(:,2); ft=ft+2e-6; Adds a constant shift to the original time series. Gets back an average (actually, Matlab gives SUM, I divided by the number of data to get the average) at the zero freq! 15
Ins and Outs of Discrete Fourier Transform (DFT) 1. In mathematics, the Discrete Fourier Transform (DFT) is a specific kind of Fourier transform. 2. Requires a continuous function being Sampled at specific time/spatial points. 3. Only evaluates enough frequency samples to reconstruct the time-segmented finite samples 4. Assumes the limited time samples are from 1 period (hence the range is limited from 0à2 PI (or PI to PI) and this periodicity repeats forever. A window function is often added to remove high-freq contamination (recall: time limited signal cannot be band-limited)-à a little bit of artifacts Not too big since the frequencies at super high freq usually have small amps. 5. For the same reason as 4, inverse DFT (IFFT) will not be able to reconstruct the infinite time series from a non-infinite time series. 16
The DFT maps a discrete signal into the frequency domain where the limit of ω is [0, 2π). π N=8 Suppose: time series has N points, then the ω axis can be discretised as ω 0 2π ω k = k 2π N, k = 0, 1,..., N -1 N= length of Fourier Transform, and X(ω k ) = N 1 x n e jω kn, n= 0 k = 0, 1, 2,.., (N -1) So the DFT maps the N-point time series to N-point coefficients X k = X(ω k ) in frequency domain! Nyquist at ω=π complex coefficient ordering in Matlab. Matlab considers frequencies from 0 ---> 2π π/2 after fftshift, move 0 freq to center π 0 (-π) 0 π-df (-π) (2π) 1 N/2+1 N 3π/2 (-π/2) Check program dft_simple.m for unshifted frequency storage, useful for visualization (careful here!). 17 Questions: (1) What does it say about the coefficients (complex vs. real)? (2) What can I say about the time series?
Unshifted DFT storage in matlab >> type dft_simple.m % this little code finds DFT of a simple time series. z=[1, 2, 3, 4, 5, 6]; w=fft(z) >> dft_simple w = Columns 1 through 3 21.0000-3.0000 + 5.1962i -3.0000 + 1.7321i Columns 4 through 6-3.0000-3.0000-1.7321i -3.0000-5.1962i shifted DFT storage in matlab >> type dft_simple_shift.m % this little code finds shifted DFT of a simple time series. z=[1, 2, 3, 4, 5, 6]; w=fft(z); w=fftshift(w) >> dft_simple_shift w = Columns 1 through 3-3.0000-3.0000-1.7321i -3.0000-5.1962i Columns 4 through 6 21.0000-3.0000 + 5.1962i -3.0000 + 1.7321i 18
Symmetric function input/fourier symmetry (see code symmetry_fft.m) % this program demonstrates the input pattern for matlab, % as well as symmetry of Fourier transforms for real even and real odd functions z=[4 1 0 1 4] fft(z) Output: (Not symmetric due to MATLAB corkiness, this input is actually regarded as a shifted symmetric func, which is multiplication of F(w) by a complex exponential 10.0000 4.7361 + 3.4410i 0.2639 + 0.8123i 0.2639-0.8123i 4.7361-3.4410i Replace the input by z=[0 1 4 4 1] fft(z) Output: 10.0000-5.8541 0.8541 0.8541-5.8541 (which is real symmetric spectrum!!) Real Odd func z=[0 1 4-4 -1] fft(z) Output: 0 0-6.6044i 0 + 6.4329i 0-6.4329i 0 + 6.6044i (Complex Odd Spectrum!!) 19