Plot periodic function with Fourier coefficients

In summary, the author plotted the function for ##T=15## and ##\tau=T/30## using Python and found that the function has a periodic component with a frequency of ##\tau/2##.
  • #1
schniefen
178
4
Homework Statement
Consider the function ##p(t)=\sin{(t/\tau)}## for ##0\leq t <2\pi \tau## and ##p(t)=0## for ##2\pi \tau \leq t < T##, which is periodically repeated outside the interval ##[0,T)## with period ##T##. Plot this function for ##\tau=T/30## using a restricted set of Fourier coefficients.
Relevant Equations
The complex Fourier series: ##\sum_{j=-\infty}^{\infty} a_j e^{i2\pi jt/T}##. Since the ##p(t)## is real-valued, we have ##a_{-j}=\overline{a_j}##.
I have plotted the function for ##T=15## and ##\tau=T/30## below with the following code in Python:

Code:
import numpy as np
import matplotlib.pyplot as plt

def p(t,T,tau):
    n=np.floor(t/T)
    t=t-n*T
    if t<(2*np.pi*tau):
        p=np.sin(t/tau)
    else:
        p=0
    return p
tdata=np.linspace(-5*np.pi,5*np.pi,500)
pdata=[]
for i in tdata:
  pdata.append(p(i,15,1/2))

plt.plot(tdata,np.array(pdata),label='$T=15$, $\u03C4=1/2$')
plt.legend(loc='lower right')
tick_pos= [-5*np.pi,-4*np.pi,-3*np.pi, -2*np.pi , -np.pi, 0, np.pi , 2*np.pi,3*np.pi,4*np.pi,5*np.pi]
labels = ['$-5\pi$','$-4\pi$','$-3\pi$','$-2\pi$','$-\pi$','0', '$\pi$', '$2\pi$','$3\pi$','$4\pi$','$5\pi$']
plt.xticks(tick_pos, labels)
plt.xlabel('$t$')
plt.ylabel('$p(t)$');

Output:
1668101019939.png

I would now like to plot an approximation to this function using a restricted set of Fourier coefficients. How can I do that in python?
 
Physics news on Phys.org
  • #2
Perform an FFT to identify the amplitude and phase of the harmonics present in the signal.
 
  • Like
Likes schniefen
  • #3
Baluncore said:
Perform an FFT to identify the amplitude and phase of the harmonics present in the signal.
Yes, I was thinking along those lines, that is, to find the coefficients through FFT. I am very new to this, so I have had little experience with FFT.
 
  • #4
Take a data record that includes an integer number of full cycles, or exactly one full cycle of the waveform.
Avoid a step where the ends of the waveform wrap around.
An FFT works best on 2^n samples, so generate the function with a sampling rate that results in maybe 64, 256 or 1024 samples.
Calibrate your analyser with some known sine and cosine waves.
 
  • Like
Likes schniefen

1. What is a periodic function?

A periodic function is a function that repeats its values at regular intervals. This means that the function will have the same output for certain input values, and will continue to repeat this pattern indefinitely.

2. What are Fourier coefficients?

Fourier coefficients are a set of complex numbers that represent the amplitudes and phases of the individual sine and cosine functions that make up a periodic function. These coefficients are used to construct a Fourier series, which is a mathematical representation of a periodic function.

3. How do you plot a periodic function with Fourier coefficients?

To plot a periodic function with Fourier coefficients, you first need to determine the values of the coefficients using mathematical formulas or algorithms. Once you have the coefficients, you can use them to construct a Fourier series and plot the function by graphing the series over a certain interval.

4. What is the significance of Fourier coefficients in plotting periodic functions?

The Fourier coefficients are important in plotting periodic functions because they allow us to break down a complex function into simpler components, making it easier to analyze and understand. They also provide a more accurate representation of the function, as the Fourier series can be made up of an infinite number of terms.

5. Can Fourier coefficients be used to plot non-periodic functions?

No, Fourier coefficients are specifically designed for periodic functions and cannot be used to plot non-periodic functions. However, there are other mathematical techniques and algorithms that can be used to plot non-periodic functions.

Similar threads

  • Advanced Physics Homework Help
Replies
6
Views
171
  • Programming and Computer Science
Replies
6
Views
1K
  • Calculus and Beyond Homework Help
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
6
Views
3K
Replies
5
Views
362
  • Programming and Computer Science
Replies
1
Views
2K
Replies
4
Views
369
  • Calculus and Beyond Homework Help
Replies
3
Views
290
  • Programming and Computer Science
Replies
3
Views
931
Replies
13
Views
2K
Back
Top