Series de fourier

Solo disponible en BuenasTareas
  • Páginas : 3 (627 palabras )
  • Descarga(s) : 0
  • Publicado : 29 de noviembre de 2011
Leer documento completo
Vista previa del texto
EE 321

Electrical Circuits II Generating Fourier Series with Matlab

Fall 2004

Generating Fourier series with Mathematica is extremely simple provided, of course, that you are familiar withMathematica. For example, for an even, unit amplitude, square wave with unit period, the Fourier series is given by f (t) = 4 π (−1)n+1 cos((2n − 1)2πt) n=1 2n − 1


(1)

A Mathematica command todefine this function is
f[t_, nTerms_] := 4/Pi Sum[(-1)ˆ(n+1)Cos[(2 n - 1)2 Pi t]/(2 n - 1), {n, 1, nTerms}]

This command defines a function f with two arguments. The first, t, is the time and thesecond, nTerms, is the number of terms to be used when evaluating the series. After issuing this command one can plot the function f with, for example, a command such as
Plot[f[t, 20], {t, 0, 2}]This says to plot the function using the first twenty harmonics with time ranging from zero to two. Alternatively, one can evaluate the function at a point. For example, the statement f[0.123,15] wouldevaluate the series at the point 0.123 using the first 15 non-zero harmonics. However, how would one plot the series in Matlab? Unfortunately you have to work a bit harder (at least given my limitedknowledge of Matlab) but it is straightforward and generating such plots is a good way to check that you have the series correct. Here is a transcript, with comments, of a session which generates a plotof the series shown above. The first 20 non-zero harmonics are used.

% Set the number of harmonics in the series. nTerms=20; % n = a vector of integers of all the harmonic numbers
File:matlab-fourier-series.tex

1

n=1:nTerms; % an = coefficients of harmonics an=4*(-1).ˆ(n+1)./(pi*(2*n-1)); % t = time at which function is sampled t=linspace(0,2,401); % f = ultimately will contain theFourier series of the % desired function. Initialize to zero. Length % is the same as the number of time samples. f = zeros(1,length(t)); % Use a loop to add each harmonic to the series. for n=1:nTerms...
tracking img