Fourier Series and Fourier Transform Jan Černocký and Petr Motlı́ček, FIT VUT Brno 1 Fourier series FS expresses arbitrary periodic signal as a sum of complex exponentials: +∞ X x(t) = ck ejkω1 t , (1) k=−∞ where ω1 = 2π T1 is fundamental frequency of signal and ck are coefficients of FS which are computed: 1 Z ck = x(t)e−jkω1 t dt. T1 T1 (2) We will deal with FS of very typical signals: sequences of periodic impulses. Such signals are defined as: x(t) = D 0 for − ϑ 2 for − T1 2 ≤t≤ ϑ 2 ≤ t < − ϑ2 a ϑ 2 <t≤ T1 2 with fundamental period T1 . Coefficients of FS can be analytically derived: à ! ϑ ϑ ck = D sinc kω1 . T1 2 (3) FS coefficients are going to be computed by 3 ways: 1. First, we will be plotting coefficients derived according to theoretical equation. 2. Second, let’s generate functions e−jkω1 t . The input signal will be multiplied by these exponentials. and integrated over one period (summed). 3. We will use function fft and we will show that coefficients of FS are computed, however with small difficulties. Exercise 1. Generate sequence of square pulses x(t) with parameters: D = 6, T1 = 1 µs, ϑ = 0.25 µs. Plot one period and several periods of the signal. As in case of processing any continuous time signals, we need to choose time-step. We can set it for example so that one period of signal will cover 200 samples: krok = T1/200; t = -T1/2:krok:T1/2; x = zeros(size(t)); x (find(t > -theta/2 & t < theta/2)) = D; plot (t,x); If we want to see several periods of input signal: x5 = [x x x x x]; t5 = [t-2*T1 t-T1 t t+T1 t+2*T1]; plot (t5,x5); We will work just with one period. 1 Exercise 2. Compute coefficients ck according to Eq. 3 for k ∈ [−20, 20]. Then plot magnitude and phase on corresponding angular frequencies: omega1 = 2*pi / T1; k = -20:20; ck = ... figure(1); subplot (211); stem (k*omega1,abs(ck)); subplot (212); stem (k*omega1,angle(ck)); !!! Attention: In case you use matlab function sinc, it is necessary to divide argument of this function byπ, because Matlab defines it as: sinc(x) = sinπxπx , we define: sinc(x) = sinx x . !!! ¯ à !¯ ¯ϑ ϑ ¯¯ ¯ ω ¯• You may also try to show in magnitude picture trajectory of the auxiliary function ¯¯ sinc T1 2 ¯ we can use functions e.g., hold on a hold off. • Check if first touch of auxiliary function with x-axis lies really on frequency ω a = 2π . ϑ Exercise 3. Compute coefficients ck “by hand” by generating complex exponentials e−jkω1 t . You may try to apply a scalar multiplication instead of cycle. Incase you manage to generate complex exponential on frequency kω1 to vector ee, the integral from Eq. 2 could be: c = 1 / T1 * x * ee’ * krok; All computed coefficients for k ∈ [−20, 20] need to be stored in vector, e.g., ckr. Then plot and compare ck a ckr. Exercise 4. Try to compute coefficients of FS using Fast Fourier Transform (FFT). FFT will be mentioned later in this course, now just a few Matlab-lines: X = fft(x); N = length(X); ckf = X / N; omegaf = (0:(N-1)) * omega1; figure(3) subplot (211); stem (omegaf,abs(ckf)); subplot (212); stem (omegaf,unwrap(angle(ckf))); grid; • Magnitudes look good, but in mid-part (zoom) we can find out that every 4th coefficients in non-zero. Try to explain what happened? • What happened with the phase ? • Why did we use function unwrap when plotting the phase, and what is going to plot without this function? Exercise 5. Show the composition of square signal from particular components ck ejkω1 t . Let’s begin with mean value c0 and then iteratively add ck ejkω1 t for k = ±1, k = ±2, . . .. For each iteration show complex exponentials, their addition and global sum Finally, we should obtain something similar to slides 25 and 26 in lecture about FS. The following box contains the solution, but try it first without looking at it!!! 2 % let’s start for mean gj0 = find (k==0); yy = ck(gj0) * ones(size(t)); figure(4); plot (t,yy); % now for k for ii=1:20, % let’s generate exponentials and draw them e = ck(gj0+ii) * exp(j*ii*omega1*t); me = ck(gj0-ii) * exp(-j*ii*omega1*t); subplot(311); plot3(t,real(e),imag(e),’r-’,t,real(me),imag(me),’b--’); % let’s addd them to get cos thiscos = e + me; subplot(312); plot(t,thiscos); % and add them to the composite signal yy = yy+thiscos; subplot(313); plot(t,yy); pause end Exercise 6. Compute coefficients of FS for the signal from Exercise 1, but delayed by τ = T1 . 16 You may try to use Eq.: ck,τ = ck e−jkω1 τ or to really generate the signal and compute the coefficients “by hand”. If you have time, do both and compare the results. 2 Fourier transform transforms continuous time signal x(t) to the spectral function X(jω). An input signal does not have to be periodic. Z +∞ X(jω) = x(t)e−jωt dt (4) −∞ On contrary to the coefficients of FS, X(jω) is a true function and is defined for all frequencies ω. However, it will cause some problems when computing it in Matlab, because we need to define also the step for ω Exercise 7. Compute FT of square signal (non periodic!!!): D x(t) = 0 for − ϑ 2 ≤t≤ ϑ 2 elsewhere for D = 0.001 a ϑ = 2 hours (example from numeric exercises). It won’t be so difficult to generate the signal in Matlab: D = 0.001; theta = 2*3600; % the step will be 1 second, that’s enough ... krok = 1; t = -7200:krok:7200; x = zeros(size(t)); x (find (t>-3600 & t<3600)) = 0.001; figure (6); plot (t,x); 3 We will have some problems with ω: How to choose bounds and the step? Let’s try to roughly estimate 2π . – if the signal was periodic with the period of 4 hours, the fundamental frequency would be: ω 1 = 4×3600 Let’s count from −5ω1 to 5ω1 and say that we require e.g., 1001 values in this interval to obtain nice picture: omega1 = 2*pi / (4 * 3600); omega = linspace(-5*omega1,5*omega1,1001); Why do we require 1001 values and not 1000? Then, we allocate a variable for the solution: X = zeros(size(omega)); and we need to write down the cycle, where in each step corresponding exponential will be generated e jωt , the signal will be multiplied by this exponential, and finally we will integrate (sum). The task for you is to write this cycle. At the end, the solutions will be visualized: figure(7); subplot (211); plot (omega,abs(X)) subplot (212); plot (omega,angle(X)) 4