Returning to Fourier Transformations with Maxima

The last time that I worked with Fourier Transformations was in Linear Analysis, nearly 3 years ago. Now I am taking a class in Mechanical Vibrations, and we are returning to this theory. The other week, while learning to use a spectral analyzer, we had to derive the first 3 Fourier coefficients for a sine wave, square wave, and triangle wave. All of that aside, after lab I played around with some fourier theory in Maxima.

Maxima

Maxima is a symbolic math program (similar to Mathematica) that I ran into last quarter in order to supplement Octave (Matlab equivalent). Like Octave (which does only numerical analysis) Maxima is completely free. I like the version of Maxima called wxMaxima, and I have that installed on Ubuntu.
You can define an equation in maxima such as:
s: a^2 + 7 = b*4 + a/3
Then you can solve for b in one step:
solve(s,b)
And it simply returns b = a^2/4 + a/12 + 7/4. You can do other cool things such as summation, integration, and differentiation, of course, as you will see below.

Fourier Transforms

Another cool thing you can do with Maxima is define a symbolc function with one or multiple inputs. For example:
f(a) := a^2 + a
Typing in f(3) after this will return 12.

I used this fact to construct some functions that use summations to return the first several orders of a Fourier transform for a square wave, triangle wave, and a few others. I'll just get to the images of what happened when I graphed those functions.

Figure 1 is a square wave approximation. I entered the formula and the plotted it in Maxima:
square(x,n,omega) := expand((4/%pi)*sum(1/(m*2-1)*sin((m*2-1)*x*omega),m,1,n));
plot2d(square(x,50,2),[x,0,2*%pi]);
Figure 1: Square Wave Fourier Approximation (50 terms)

This triangle wave approximation in Figure 2 was made with the commands:
triangle(x,n,omega) := expand((8/(%pi^2))*sum((((-1)^((2*m-2)/2))/((2*m-1)^2)*sin((2*m-1)*omega*x)),m,1,n));plot2d(triangle(x,50,2),[x,0,2*%pi]);
Figure 2: Triangle Wave Fourier Approximation (50 terms)
This saw-tooth wave approximation in Figure 3 was made with the commands:
sawsymmetric(x,n,omega) := expand(2/%pi*sum(((-1)^(m+1))/m*sin(m*omega*x),m,1,n));
plot2d(sawsymmetric(x,50,2),[x,0,2*%pi]);
Figure 3: Saw-tooth Wave Fourier Approximation (50 terms)
You'll notice just how approximate these functions are, especially on the square and saw-tooth waves, around where there are the greatest discontinuities. The triangle wave looks nearly perfect because while it has a sharp peak, it is changing rate from the same point rather than jumping from 0 to 1.

Comments

Popular posts from this blog

Arduino & Tri-Colored LEDs

Nerd-Code Snippets 3: Bash Minecraft Install Scripts

Alta Devices Internship