Vous êtes sur la page 1sur 4

Introduction: The coefficients of cos(nx) and sin(nx) in the Fourier series representing a particular function are called the

Fourier coefficients for that function. Fourier coefficients are found in periodic functions that are integrable on [-pi,pi].

and function f(x).

are the Fourier coefficients of a periodic

In MATLAB you can easily get the Fourier coefficients by using the fft command. MATLAB will automatically display the coefficients in the command window; just remember that you need to indicate how many coefficients you want to display. Objectives: After the laboratory experiment: We should be able to get six Fourier coefficients of the given functions. Plot the given functions. Plot the phase vs frequency and magnitude vs frequency of the Fourier transform from the given functions. Name the given functions.

Problems: 1.) The function is f(x) = 1 if 0<x<pi, 0 if pi<x<0 and f(x+pi). Name the function. Show up to 6 Fourier coefficients. 2.) f(x) = |x| -1<x<1 and f(x+2) = f(x). Name the function. Show up to 6 Fourier coefficients. 3.) f(x) = -1 if pi<x<-pi/2, 1 if p1/2<x<0, and 0 if 0<x<pi. Show up to 6 Fourier coefficients. Procedures: How to plot the given functions and get six Fourier coefficients:

1.) It is important to plot the function first before getting the Fourier coefficients because by plotting you can get the Fourier transform needed in getting the coefficients. 2.) First analyze the given conditions or behavior in each function. Lets say we take problem #1, having conditions of 1 if 0<x<pi and 0 if pi<x<0, with a graph that should likely result into a square wave since the values for f(x) will only be 1 or 0. 3.) Now plot the function using the conditions as your basis. Remember that you can plot the function by manually assigning values for f(x) at a specific period but I do not

recommend you to do that. The reason why you shouldnt plot the function by doing the manual method is because you cannot properly use it later for the Fourier transform. I recommend that you must use the while and if statements to create any function that you want. Using the while and if statements will make your codes shorter and precise compared to the manual method. 4.) We shall take the function in problem #1 as a sample in creating the while and if statements. The conditions are 1 if 0<x<pi and 0 if pi<x<0, so the range is within pi to pi but there was an additional condition f(x+pi), meaning the function will have a period of pi so we have to increase the range to -2*pi to 2*pi in order to fully see the behavior of the function. Add the command line a = -2*pi:0.00001*pi:2*pi to set the range. 5.) Now we shall set the while and if statements. First create a variable i = 1 which will be used for the while statement. Now add the command line while i<=length(a), this statement will always be true when i is less than or equal to the length of a which is the range of the function. Add the two command lines if a(i)>=-2*pi & a(i)<-pi and u(i)=1, this will find values from -2*pi to pi and will set the value of u to be 1 at that period. Next, add another two command lines elseif a(i)>=-pi & a(i)<0 and u(i)=0 which will find values from pi to 0 and within this period the value of u will be set to 0. The rest of the conditions will be up to you, just remember that the period is pi, so in every interval of pi the value of f(x) changes from 1 or 0 depending on the conditions. 6.) Assuming that you are now done plotting the function you can now get the Fourier transform of the function along with the six Fourier coefficients. Add the command line, coe = fft(u,6) where u is your function and 6 is the number of coefficients you want to get. Remember that the resulting coefficients are displayed at the command window.

How to plot the phase vs frequency and magnitude vs frequency of the Fourier transform from the given functions:

1.) Assuming that you are done plotting the functions, you can now use the abs and angle commands. The abs command will determine the magnitude while the angle command will determine the phase. 2.) Add the command line M=abs(fou) to get the magnitude of the Fourier transform which is fou. Add the command line P=angle(fou) to get the phase of the Fourier transform which is still fou. Remember that you have to declare that fou is your Fourier transform which is done by using the fft command. 3.) Now use the plot command by adding the command lines plot(M,u) for the magnitude vs frequency and plot(P,u) for the phase vs frequency. Remember that you can also make a graph for magnitude vs phase or phase vs magnitude, just change the elements inside the plot command.

Conclusion:

In this laboratory experiment I have learned to use the while and if statements properly. Using the while and if statements made the plotting of functions easier, which will be very helpful for future laboratory experiments. I have also learned to get the Fourier coefficients which is also done through the fft command. The rest of the commands, like abs and angle were being used during the previous experiment. Plotting the phase vs frequency and magnitude vs frequency of a Fourier transform was also done the same way with the previous experiment except that when you plot the magnitude vs phase or phase vs magnitude you will see graphs that are indescribable.

Overall the experiment was still a little difficult because if you dont know the purpose of the conditions like f(x+pi) you cannot plot the function properly. I was not also able to name the resulting functions because I do not know the specific names that I should use to call them. The only thing that I appreciate in the experiment is the use of while and if statements in plotting. JMJ

Marist Brothers Notre Dame of Dadiangas University Marist Avenue, General Santos City

Digital Signals

Laboratory Experiment #2(Finals)

Submitted By: Kurt Russel C. Chua Course & Year: BS-CpE-4 Date Submitted: Due Date: September 15, 2011 Submitted To: Engr. Feln Lily Famador Canonigo, MEP-ECE

Vous aimerez peut-être aussi