Fourier Series examples

Contents

square wave

x = linspace(-0.5,0.5,101);
M = 70;
duty = 0.5;
[y coeff] = square_wave(x,M,duty);
idx = find(abs(coeff)>1e-10);
disp([idx(1:9) 2.0./(pi*coeff(idx(1:9)))]);
plot(x,y);
    1.0000    1.0000
    3.0000   -3.0000
    5.0000    5.0000
    7.0000   -7.0000
    9.0000    9.0000
   11.0000  -11.0000
   13.0000   13.0000
   15.0000  -15.0000
   17.0000   17.0000

sawtooth

x = linspace(-0.5,0.5,101);
M = 90;
[y coeff] = sawtooth(x,M);
1.0./(pi*coeff(1:9))
plot(x,y);
ans =

     1
    -2
     3
    -4
     5
    -6
     7
    -8
     9

triangle wave

x = linspace(-0.5,0.5,101);
M = 90;
duty = 0.5;
[y coeff] = triwave(x,M,duty);
idx = find(abs(coeff)>1e-10);
% (2/(pi*k))^2
disp([idx(1:9) 2.0./(pi*sqrt(coeff(idx(1:9))))]);
plot(x,y);
    1.0000    0.7071
    2.0000    1.0000
    3.0000    2.1213
    5.0000    3.5355
    6.0000    3.0000
    7.0000    4.9497
    9.0000    6.3640
   10.0000    5.0000
   11.0000    7.7782