Why Doesn't My Fourier Series Expansion Look Like a Square Wave?

In summary, the conversation discusses the use of Fourier series to represent a square wave function and the importance of defining the function on a finite domain. The issue with the plots is due to an order of operations error which can be corrected by adding extra parentheses.
  • #1
back2square1
13
0
for a square wave function,

f(x)= { -1, -∞ ≤ x ≤ 0; +1, 0 ≤ x ≤ ∞

Expanding it in Fourier series gives a function like,

f(x) = (4/π) * Ʃn=0( (sin ((2n+1)x) / (2n+) )

Plotting a graph of the equation gives something like this, http://goo.gl/vFJhL
which obviously doesn't look like a square wave. Can anyone tell me where have I gone wrong? What am I missing?

P.S
Fourier co-efficients
an=0
a0=0
 
Mathematics news on Phys.org
  • #2
back2square1 said:
for a square wave function,

f(x)= { -1, -∞ ≤ x ≤ 0; +1, 0 ≤ x ≤ ∞

The way you have written this, f(x) is not a square wave. It's a signum function.

A Fourier series is a series representation of a periodic function. If you take the Fourier series of a non-periodic function on a finite interval [a,b], then the Fourier series matches your function on that domain, but repeats the function shape with period b-a.

What you have written, however, has an infinite domain, so a Fourier series cannot be used - you would have to use a Fourier transform instead. However, because you mention a square wave, what you probably want to do is define your function on a finite domain, such as

$$f(x) = \left\{\begin{array}{c}{-1,~-1 \leq x < 0 \\ +1,~0 < x \leq 1}\end{array}\right.$$

Then, calculate the Fourier series for that function on the domain [-1,1]. The resulting Fourier series should be a square wave. Note also that it is odd about x = 0, so I would expect only sine terms in the series, and in fact you should get the series you quoted.

As for why your plots aren't working, it looks to me like an order of operations issue. When you write the sum you are writing terms like "4sin(5x)/5pi". The plotter is interpreting this as "(4*sin(5x)/5)*pi". Write it like "4sin(5x)/5/pi" or "4sin(5x)/(5pi)" and you will get the result you want.
 
Last edited:
  • #3
Thank you very much, Mute. It worked really nice. You're a wonderful guy. As you said, I added some extra parenthesis to my function and I can see a nice square wave, like this: http://goo.gl/9nu8V
Thank you once again. And yeah, I meant to write it like this,
f(x)= { -1, -π ≤ x ≤ 0; +1, 0 ≤ x ≤ π
I wrongly clicked on ∞ instead of π on the side bar.
And hey, please tell me how did you write that function in such a nice layout?
 
  • #4
back2square1 said:
Thank you very much, Mute. It worked really nice. You're a wonderful guy. As you said, I added some extra parenthesis to my function and I can see a nice square wave, like this: http://goo.gl/9nu8V
Thank you once again. And yeah, I meant to write it like this,
f(x)= { -1, -π ≤ x ≤ 0; +1, 0 ≤ x ≤ π
I wrongly clicked on ∞ instead of π on the side bar.
And hey, please tell me how did you write that function in such a nice layout?


Use the 'Quote' button on Mute's post, and it will show you the formatting used.
 
  • #5


First of all, it is important to note that the Fourier series expansion of a square wave is an infinite sum of sine functions. This means that the graph of the equation will only be an approximation of a square wave, as it is impossible to have an infinite number of terms in a real-life scenario.

One possible explanation for the discrepancy in the graph could be the number of terms used in the Fourier series expansion. The more terms that are included in the series, the closer the graph will be to a square wave. However, as mentioned earlier, it is impossible to have an infinite number of terms, so there will always be some level of approximation.

Another factor that could affect the accuracy of the graph is the range of values used for x. In the given equation, the range is from -∞ to ∞, which is not practical in real-life situations. It is more common to use a finite range of values, which could also contribute to the discrepancy in the graph.

Additionally, there could be errors in the calculations of the Fourier coefficients, which could also affect the accuracy of the graph. It is important to double-check the calculations and make sure they are accurate.

In conclusion, while the Fourier series expansion is a useful tool for approximating a square wave, it is not a perfect representation. Factors such as the number of terms used, the range of values, and potential errors in calculations can all contribute to discrepancies in the resulting graph. It is important to keep these limitations in mind when using Fourier series to model real-life phenomena.
 

1. What is a Square Wave function?

A Square Wave function is a type of mathematical function that alternates between two constant values. It is characterized by sudden changes in amplitude between the two values, with no gradual transition in between.

2. What is the equation for a Square Wave function?

The equation for a Square Wave function is typically written as y = A * sign(sin(x)), where A is the amplitude and x is the input variable.

3. How is a Square Wave function different from a Sinusoidal function?

A Square Wave function differs from a Sinusoidal function in that it has sudden changes in amplitude, whereas a Sinusoidal function has a smooth and continuous curve. Additionally, the frequency of a Square Wave function is constant, while the frequency of a Sinusoidal function can vary.

4. What are some real-world applications of Square Wave functions?

Square Wave functions have many practical applications, including in electronics, where they are used to generate signals for digital circuits and for data transmission. They are also used in audio synthesis, where they can create unique sounds and effects.

5. Can Square Wave functions be modified or combined with other functions?

Yes, Square Wave functions can be modified and combined with other functions to create more complex waveforms. For example, a Square Wave function can be combined with a Sinusoidal function to create a Pulse Wave function, which is commonly used in music synthesis.

Similar threads

Replies
10
Views
1K
Replies
4
Views
405
Replies
2
Views
143
Replies
139
Views
4K
  • Calculus and Beyond Homework Help
Replies
3
Views
278
  • Calculus and Beyond Homework Help
Replies
4
Views
351
  • Introductory Physics Homework Help
Replies
8
Views
566
  • Advanced Physics Homework Help
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
Back
Top