Complex Fourier Series using Matlab

In summary, you synthesized a periodic function in Matlab by combining terms with an exponential function. You mistakenly entered the period of the exponential function as the period of the periodic function, and when you tried to recreate the time domain signal in Matlab, you could not do so.
  • #1
Jag1972
40
0
Hello,
I have a problem synthesising the complex Fourier series using Matlab. The time domain periodic function is:

-1, -1.0 ≤ t < -0.5
1 , -0.5≤ t <0.5
-1, 0.5 ≤ t < 1

The single non zero coefficient is: Cn = [itex]\frac{2}{\pi n}[/itex], Co is 0 (average is 0).

f(t)= [itex]\sum Cn e^{jnwt}[/itex] (limits are -∞ to ∞, could not find the latex symbol)

This makes:

f(t) = ([itex]\frac{2}{\pi}[/itex] [itex]e^{jwt}[/itex] - [itex]\frac{2}{\pi*3}[/itex] [itex]e^{j3wt}[/itex] + [itex]\frac{2}{\pi*5}[/itex] [itex]e^{j5wt}[/itex] -... [itex]\frac{2}{\pi*∞}[/itex] [itex]e^{j∞wt}[/itex]) + ([itex]\frac{2}{\pi}[/itex] [itex]e^{-jwt}[/itex] - [itex]\frac{2}{\pi*3}[/itex] [itex]e^{-j3wt}[/itex] + [itex]\frac{2}{\pi*5}[/itex] [itex]e^{-j5wt}[/itex] -... [itex]\frac{2}{\pi*∞}[/itex] [itex]e^{j-∞wt}[/itex])

In order to enter this in Matlab I have combined the exponential terms to obtain cosine waves.
For example when n=1 and n=-1.

[itex]\frac{2}{\pi}[/itex] [itex]e^{jwt}[/itex] + [itex]\frac{2}{\pi}[/itex] [itex]e^{-jwt}[/itex]

[itex]\frac{2}{\pi}[/itex]( [itex]e^{jwt}[/itex] + [itex]e^{-jwt}[/itex])

[itex]\frac{4}{\pi}[/itex]( [itex]\frac{e^{jwt}+e^{-jwt}}{2}[/itex])

[itex]\frac{4}{\pi}[/itex]( [itex]cos wt[/itex])

when n=2 and n=-2.

[itex]\frac{-4}{\pi*3}[/itex]( [itex]cos 3wt[/itex])

So I end up with cosine terms which only exist for odd multiples of 'n' and the '+' and '-' sign alternates.
When I enter this in Matlab I can not recreate my time domain signal. Could someone please offer me some advice on where I have gone wrong.

Jag.
 
Physics news on Phys.org
  • #2
You are doing the right things, but the details went wrong somewhere. Your input square wave has a period of 2 seconds, but a term like ##\cos \omega t## in your Fourier series has a period of ##2\pi## seconds.

It looks like this was wrong from the start, when you said ##f(t) = \sum C_n e^{jn\omega t}##.

Note you will need several terms (say 10) before you get something that looks close to a square wave, and see http://en.wikipedia.org/wiki/Gibbs_phenomenon for why a finite number of terms in the series will never look "exactly" like a square wave.
 
  • #3
Alphazero: Thank you very much for your reply. Although I did not show itin my post I did actually enter ω = π into matlab.
However I did make a big mistake which was I entered t=linspace(0,2π), without realising that my domain is from -π to +π, doh!.
I have now got the right shape, thanks ever so much as I was doubting my working out.

Jag.
 

Related to Complex Fourier Series using Matlab

1. What is a Complex Fourier Series in Matlab?

A Complex Fourier Series in Matlab is a mathematical function that represents a periodic signal as a sum of complex exponential functions. It is used to analyze and manipulate signals in the frequency domain.

2. How can I use Matlab to compute a Complex Fourier Series?

To compute a Complex Fourier Series using Matlab, you can use the built-in function "fft" which stands for Fast Fourier Transform. This function takes in a signal as input and outputs the corresponding Complex Fourier Series coefficients.

3. Can I plot a Complex Fourier Series in Matlab?

Yes, you can plot a Complex Fourier Series in Matlab by using the "plot" function. First, you will need to compute the Complex Fourier Series coefficients using the "fft" function and then use the "plot" function to plot the coefficients against the frequency. This will give you a visualization of the signal in the frequency domain.

4. What is the difference between a Complex Fourier Series and a Fourier Transform?

A Complex Fourier Series is used to represent a periodic signal as a sum of complex exponential functions, while a Fourier Transform is used to represent a non-periodic signal as a continuous spectrum of frequencies. In other words, a Fourier Transform is the generalization of a Complex Fourier Series for non-periodic signals.

5. Can I use Complex Fourier Series to analyze real-world signals in Matlab?

Yes, you can use Complex Fourier Series to analyze real-world signals in Matlab. It is a powerful tool for signal processing and is commonly used in fields such as engineering, physics, and mathematics to analyze and manipulate signals in the frequency domain.

Similar threads

  • Calculus and Beyond Homework Help
Replies
1
Views
551
  • Calculus and Beyond Homework Help
Replies
1
Views
249
  • Calculus and Beyond Homework Help
Replies
3
Views
436
  • Calculus and Beyond Homework Help
Replies
16
Views
586
Replies
4
Views
319
Replies
4
Views
388
  • Calculus and Beyond Homework Help
Replies
1
Views
368
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
  • Math POTW for University Students
Replies
3
Views
813
  • Calculus and Beyond Homework Help
Replies
2
Views
389
Back
Top