Kurt's Octave Assignment
Jump to navigation
Jump to search
Useful Octave Templates
Fourier Series
clf; %Clear Figure t=0:.01:10; %Limits of the graph T=2*pi %Definition of the period M=1000 %Number of iterations to undergo sum1=0; %Initialize the sum to 0
%----------FOURIER SERIES----------% for m=1:1:M, %For m=1, increment by 1 until you get to M if(m!=0) sum1 = sum1 + ((2/(pi*m))-(2/(pi*m))*cos(m*pi))*sin(m*2*pi/T*t); end end
%---------------PLOT---------------% plot(t,real(sum1),'b-') title('Fourier Series Representation of a Wave') xlabel('time (seconds)') ylabel('Function') grid on;
legend(num2str(M) ' terms ') print("squarewave.png","-dpng") % Prints the plot to a png file called squarewave.png