Fourier series matlab

865 Views Asked by At

I have examples of Fourier series and I would using the Matlab I know how calculate the coefficients of Fourier series in Matlab

but how calculate the summation ? do I use “For loop “ or what in Matlab

1

There are 1 best solutions below

1
On

let $P$ be the period of your original function $F(x)$. Let $F_N(x)$ be the function that is made from the first $N$ coefficients of the Fourier series. Then:

$$F_N(x) = a_0 + \sum_{n=1}^N\bigg[a_n\cos\bigg(\frac{2\pi n x}{P}\bigg)+b_n\sin\bigg(\frac{2\pi nx}{P}\bigg)\bigg]$$

Where $a_i$ and $b_i$ are your coefficients.

Let's say that you have two vectors in MATLAB named an and bn, and the period of the original function is stored in a variable P, and the point $x$ is stored in a variable x. Then this should work:

n = 1:length(bn);
S = sin(2*pi*n*x/P);
C = cos(2*pi*n*x/P); %these intermediate variables make things easier
FNx = an(1) + an(2:end).*S + bn.*C; %assume that bn's length is 1 less than an

If you are using a different definition of $F_N(x)$ then the above code can be modified accordingly. This should get you started.