1. Introduction
This exercise show cases the digital signal processing toolbox of MATLAB. A Fourier series is an expansion of any periodic function in terms of an infinite weighted sum of sine waves. Here the Fourier series is been approximated from a finite weighted sum of sine waves instead of infinite sum.
2. Procedure
2.1. Introductory example
In this part we would form a square wave using a sum of odd harmonics.
As we can see, adding more weighted odd harmonics waves the result would approach to a square wave.
The heard square wave is more bright then the sine wave and the sine wave is more smooth to hear.
2.2. Approximation of a square wave using the Fourier series
CODE 2
implements the Fourier
series by computing the coefficients of the series via symbolic
integrator of MATLAB, then using a for-loop to approach the
infinite sum.
Observing the plot we can see the N_TERMS
= 7
approximation has the greatest error.
Number of terms | Overshoot |
---|---|
7 | 0.0921 |
20 | 0.0899 |
30 | 0.0897 |
50 | 0.0896 |
Number of terms | Computational time |
---|---|
7 | 0.055059 |
20 | 0.097536 |
30 | 0.160673 |
50 | 0.260833 |
100 | 0.529958 |
Basically, the balance between the precision and computational cost for using Fourier series is determined by the sample rate used for the problem. With a higher sample rate there needs more computational power for better result, with lower sample rate the precision can be sacrificed.
2.3. Approximation of a triangular wave using the Fourier series
To produce the triangular wave:
|t=-10:0.0001:10;
|x=(t/(2*pi) - floor(t/(2*pi)));
|plot(t,x)
3. Feedback
This lab shows how to use the symbolic integrator of MATLAB combined with array computation to implement Fourier series, it also demonstrates how to produce common signals from a sum of harmonic waves.
For Part B, the code used to compute the coefficient is
unnecessarily inefficient, since it would not only cause computes
the integration for an
and
bn
each N_TERMS
times, it is also using fractions and
symbolic terms instead of floating point numbers which makes the
computation slow, and the result is symbolic which makes computing
the overshoot with code much slower if not taking a different
approach.
I used the following program to computer the overshoot, note
that an
is essentially zero:
|L = pi; N_TERMS = 50; n = 1:N_TERMS;
|t = -10:0.0001:10;;
|a0 = 1.0;
|% an = (1/L)*int;
5 |% bn = (1/L)*int(1*sin(n*x), x, 0, pi);
|f = 0;
|for n = 1:N_TERMS
|f = f+0+(1/L)*((2*sin((pi*n)/2)^2)/n)*sin(n*t));
|end
10 |f_approx = (a0/2)+ f;
|err = max(f_approx) - 1