Professional Documents
Culture Documents
x(t) = cos(
cos(x) = Real(ejx ) =
ejx + ejx 2
cos( 20 t) , 2
and,
t cos( 20 t) e /20 e 20 t + e = Real( )= 2 2 4 Finally the sum of the two results in:
j3 j3 j
j 20
e 20 t + e 20 t e 20 t + e 20 t + x(t) = 2 4 In order to nd the fundamental frequency, one must observe the lowest frequency in the signal. In the case for x(t), it is quite obvious that the fundamental frequency 0 = 20 . It can be gathered, from this that the fundamental period is: 2 2 T0 = = = 40 0 20
Please refer to the last page (hand-written) for the derivation of the coefcient Dn for signal x1 (t). II. Q UESTION 2
Fig. 1: Signal x2 (t) The signal in the gure is a periodic square wave with period 200. The coefcient Dn can be found as follows:
Dn = 1 T0
T0
x(t)ejn0 t
2 200 ,
if the limits between -100 to 100 are taken then it is easy to see from gure 1, that x(t) = 1
Dn = 1 200
100
x(t)e
100
jn2 200
dt =
1 200
50
1e
50
jn2 200
dt
2 50
=
50
jn jn 1 (e 2 e 2 ) 2jn
2j 2j
2j (e Dn = 2jn
e 2j
jn 2
1 (e = n
jn 2
e 2j
jn 2
ejx ejx 2j
1 200
50
e0 dt
50
D0 =
=
50
1 2
III. Q UESTION 3 Plotting the signal x3 (t) requires that the signal x2 (t) to be plotted. There are many methods to plotting this signal, even using the Fourier Series to approximate the signal. Since the question does not specify what method must be used to plot the signal, the method used to plot this signal was the square() function. The resulting signal is represented in gure 2. clf; figure(1); %Question 3 %The following code plots the original signal x2(t) using the square %function and then shifts the signal to the right by 50 units of time. This %results in the signal x3(t). t=-300:1:300; x2 = inline(0.5*(square((2*pi/200)*(t+50))+1),t); x3 = inline(x2(t-50),t,x2); subplot(211); plot(t,x2(t)); axis([-300 300 -.1 1.2]); grid; xlabel(Time (sec));ylabel(x2(t)); title(Original Signal x2(t)); subplot(212); plot(t,x3(t,x2)); axis([-300 300 -.1 1.2]) grid; xlabel(Time (sec));ylabel(x3(t)); title(Shifted Signal x3(t) = x2(t-50));
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
IV. Q UESTION 4 Using the same approach as question 2, the expression Dn can be derived for the signal x3 (t). The period of the signal remains the same, T0 = 200, but the signal shifts by 50 to the right. Using the limits between -50 to 150, it is obvious that the signal is at x3 (t) = 1 between 0 and 100.
Dn = 1 200
150 50
x(t)ejn 200 t dt =
1 200 =
100 0
1 ejn 200 t dt
Dn =
100
1 jn (e 1) 2jn
1 Dn = (1 ejn ) 2jn
ejx ejx 2j
V. Q UESTION 5 The function can be called by [dn 1, dn 2, dn 3] = genCoefcients(N) where N is the size of the interval. The return values (1xN matrices) are stored in their corresponding coefcient variables (i.e., dn 1, dn 2, dn 3). %Question 5 - A function that generates the coefficients for an arbitrary N %value. function [D_n1, D_n2, D_n3, x] = genCoefficients(N) %This function requires an input value N which corresponds to the size of %the interval (i.e., -1000 to 1000 has a size of 2001, -10 to 10 has a size %of 21). The function sets a variable "size" to the input argument N and %then calculates the floor of the size halved. This allows the function to %obtain the upper and lower limits of the size. The function then computes %the values of the coefficients for signals x(t), x2(t) and x3(t) based on %the interval. It finds the position of the 0 replaces it with the correct %coefficient for D0. The function finally returns each set of coefficients %in the form of a matrix of size 1xN. %Set size = N. This is not necessary, but it isolates the variables/memory. size = N; j = sqrt(-1); %Calculate the limit by dividing the size by 2 and flooring it. limit = floor(size/2); %Multiply the limit by -1 to obtain the lower limit, then create a vector %of size 1xN from -limit (lower limit) to limit (upper limit). x = (-limit:limit);
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
%The use of multiple variables makes the function easier to compute for the signal x1. a_p = (3*pi)/20; b_p = pi/20; A1 = (1./80).*(1./(j*a_p+j*x*b_p)).*((exp(j*a_p*20+j*x*b_p*20) -(exp(j*a_p*(-20)+j*x*b_p*(-20))))); A2 = (1./80).*(1./((-j)*a_p+j*x*b_p)).*((exp((-j)*a_p*20+j*x*b_p*20) -(exp((-j)*a_p*(-20)+j*x*b_p*(-20))))); B1 = (1./160).*(1./(j*b_p+j*x*b_p)).*((exp(j*b_p*20+j*x*b_p*20) -(exp(j*b_p*(-20)+j*x*b_p*(-20))))); B2 = (1./160).*(1./((-j)*b_p+j*x*b_p)).*((exp((-j)*b_p*20+j*x*b_p*20) -(exp((-j)*b_p*(-20)+j*x*b_p*(-20))))); %The sum of the above equations yields Dn for signal x1 D_n1 = A1 + A2 + B1 + B2; %These values cant be determined via the above method and must be %integrated to be found. D_n1(limit-2) = 1/2; D_n1(limit+4) = 1/2; D_n1(limit) = 1/4; D_n1(limit+2) = 1/4; %Coefficient equation for x2 D_n2 = (1./(x*pi)).*(sin(x*pi./2)); %The 0th coefficient value for x2
49 50 51 52 53 54 55 56 57 58
D_n2(limit+1) = 1/2; %Coefficient equation for x3 D_n3 = (1./(x*pi)).*(sin((x*pi)/2)).*(exp((-j*x*pi)/2)); %The 0th coefficient value for x2 D_n3(limit+1) = 1/2;
end
VI. Q UESTION 6 The gures below represent the phase and magnitude for each of the signals at various intervals of N. Note: a) 10 < n < 10 results in N = 21 b) 100 < n < 100 results in N = 201 c) 1000 < n < 1000 results in N = 2001 The phase and magnitude for the signal x1(t) to x3(t) are displayed below for the value of N= 21. The code used to generate the gures is below, the value of limSize is changed accordingly to obtain each of the N ranges.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
clf; %Question 5 %INCOMPLETE, This gets the values generated by the generate coefficients %function. Currently it works for the signal x2(t) and x3(t), needs work %for x1(t). limSize = 21; [d_n1, d_n2, d_n3, vectorSize] = genCoefficients(limSize); %Question 6 %The genCoefficients function can be used to generate the coefficients for %each function, then the stem function can be used to plot both the phase %and magnitude. %Plotting Magnitude and phase figure(1); %Signal x(t) subplot(2,1,1); stem(vectorSize, abs(d_n1), k); xlabel(n); ylabel(|D_n1|); title(Magnitude for x1(t) when -10<n<10); subplot(2,1,2); stem(vectorSize, angle(d_n1),k); xlabel(n); ylabel(\angle D_n1 [rad]); title(Phase for x1(t) when -10<n<10); %Signal x2(t) Magnitude figure(2); subplot(2,1,1); stem(vectorSize, abs(d_n2), k); xlabel(n); ylabel(|D_n2|); title(Magnitude for x2(t) when -10<n<10); %Signal x2(t) Phase subplot(2,1,2); stem(vectorSize, angle(d_n2),k); xlabel(n); ylabel(\angle D_n2 [rad]); title(Phase for x2(t) when -10<n<10); figure(3); %Signal x3(t) Magnitude subplot(2,1,1); stem(vectorSize, abs(d_n3), k); xlabel(n); ylabel(|D_n3|);
43 44 45 46 47 48 49
title(Magnitude for x3(t) when -10<n<10); %Phase for x3(t) subplot(2,1,2); stem(vectorSize, angle(d_n3),k); xlabel(n); ylabel(\angle D_n3 [rad]); title(Phase for x3(t) when -10<n<10);
10
11
12
VII. Q UESTION 7
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
The function created to rebuild a signal for any arbitrary N value is below: %Question 7 %This function requires that the user pass the parameters Dn, nVal and wo. %Dn is the coefficient matrix, nVal is the range of n (i.e., nVal=21 %for -10<n<10) and wo is the period of the function. %The function returns the signal x and the time interval. This return value %can be used to graph the function. function [x, t] = buildSignal(D_n, nVal, wo) j=sqrt(-1); N=nVal; %This is not necessary, but nVal is copied to the variable N t=-300:1:300; %The time interval is set from -300 to 300 %The lower limit of nVal is found (i.e., if nVal = 21 then n = -10) n = -floor(N/2); %The position for the 0th coefficient is found. d_0 = floor(N/2)+1; %The coefficient at the position d_0 of the vector D_n is copied to the %variable d0. d0 = D_n(d_0); %Using the above, the function x is initialized to the 0th coefficient d0. x = d0*ones(size(t)); %The program loops from 1 to nVal for a total of nVal counts and each time %it finds the fourier transform for the Dnth coefficient and sums it with %the current value of x. If the coefficient arrives at n = 0 then it does %nothing since the 0th coefficient was already set up previously. for column = 1:N, %Loops from 1 to N= nVal, it is also the column of the matrix if n==0 x = x; %Does nothing, just to avoid NaN errors. else x = x + (D_n(column)*exp(j*n*wo*(t))); % Fourier Series computation end n = n+1; %This is used to transform the column values to fourier series %coefficient counts (i.e., when column = 11, n = 0) end
end
13
VIII. Q UESTION 8 Using the above function, each signal can be rebuilt using the Fourier Series relationship, limSize is varied from N = 21 to 2001 for the specic ranges:
a
x(t) =
a
Dn ejn0 t
The function buildSignal and genCoefcients are used and then each signal is plotted: clf; % % % % % % Question 8 Using the function buildSignal and the function genCoefficients, the signal is rebuilt with the Fourier Series Exponential summing method. After the signal is generated it is then plotted. Please refer to the function buildSignal to understand the parameters that must be passed and arguments returned.
%Signals rebuilt for N = 21 limSize = 21; [d_n1, d_n2, d_n3, vectorSize] = genCoefficients(limSize); %Signal x1(t) rebuilt figure(1); [x,t] = buildSignal(d_n1, limSize, (pi/20)); plot(t,x); grid; xlabel(t (seconds)) ylabel(x1(t)); title(x1(t) generated via Fourier Series N=21); %Signal x2(t) rebuilt figure(2); [x,t] = buildSignal(d_n2, limSize, (2*pi/200)); plot(t,x); axis([-300 300 -.1 1.2]) grid; xlabel(t (seconds)) ylabel(x2(t)); title(x2(t) generated via Fourier Series N=21); %Signal x3(t) rebuilt figure(3); [x,t] = buildSignal(d_n3, limSize, (2*pi/200)); plot(t,x); axis([-300 300 -.1 1.2]) grid; xlabel(t (seconds)) ylabel(x3(t)); title(x3(t) generated via Fourier Series N=21);
14
15
16
17
18
IX. D ISCUSSION The question below discuss the observations and compare various results obtained from the above experiment. 1. The main difference between the coefcients Dn of signal x1 (t) and x2 (t) is that the coefcients for x1 (t) are at 0 till the points n = -3, -1, 1 and 3 (Fig. 3). For the signal x2 (t), the coefcients are close to zero, but increase slightly each time as they approach the points n = -3, -1, 1 and 3 (Fig.4). The 0th coefcient for x2 (t) reaches its maximum peak while the 0th coefcient for x1 (t) is at its minimum of 0. As the interval increases, the coefcients are less distinguishable. 2. The signal x1 (t) changes ever so slightly and the peaks become smoother while x2 (t) approximates the original signal better with more coefcients. Clearly, both these signals and even the third signal x3 (t) build a better approximation of their original signals as the amount of coefcients approach some large value such as innity. 3. Theoretically, to rebuild a signal perfectly, one would require an innite amount of Dn . Graphically, according to the experiment done, the signals x2 (t) and x3 (t) began to model their original signals at around N = 201, at N = 2001 there was no obvious difference between the signals and it would be difcult to graphically notice any aws. 4. It would seem to be a tedious task to store the coefcients of a signal on a computer. For a small interval of N, it is quite possible, but the signal would not approximate its original signal as accurately. Storing an innite amount of coefcients would require an innitely large amount of space, which is clearly not possible. It would be more practical in terms of storage to calculate each coefcient on the go and then sum it, but of course, this would take a much longer time to compute. There are downfalls to both methods, one will result in faster performance, but it would limit the interval of N, which would result in a less accurate signal approximation; the other would have slower performance, but increase the possible interval, increasing the accuracy of the approximation.