numpy draw square spread infinite series representation of a square wave

Draw a square wave

Square wave can be approximated by a plurality of superposed sine waves

Any of a square wave signal can be represented by an infinite Fourier series

  # Fourier series is based on sine and cosine functions as the basis functions of infinite series

 

Code

import numpy as np
import matplotlib.pyplot as plt

t = np.linspace(-np.pi, np.pi, 201)
k = np.arange(1, 5)
k = 2 * k - 1
#k = 99
f = np.zeros_like(t)

for i in range(len(t)):
    f[i] = np.sum(np.sin(k * t[i])/k)

f = (4 / np.pi) * f
    
plt.plot(t, f)
plt.show()

 

Infinite series representation of a square wave

Euler's formula

first step:

Maclaurin formula above is more than omitted items

Step two:

In the development of the formula into the x ± ix

 

third step:

In the x = π, obtained

 

 Fourier series

Taylor expansion function is expanded into power function of the form

Fourier expansion is expanded to a trigonometric function, i.e., y = 1 + sinx + cosx + sin2x + cos2x + ... ..

  # Frequency is changed to reflect cycle speed

  Only # e ^ x and sinx, cosx is the second derivative of their own

1. periodic function to Fourier expansion is disassembled into the constant (DC component) + a frequency component of harmonic components + ... + 2

  # Different sine and cosine functions of different phases only

2. Calculate the projected periodic function at each frequency component

A projection function and another function, that is the product of a function and another function, the function is multiplied by two, then the integration is done in the region between the

3. Calculate the inner product at each frequency component according to the projection

4. The inner product sum of these

 

Mathematical definition:

 Given a period T of the function x (t), then it can be expressed as an infinite series:

among them,

j is an imaginary unit

2π / T represents the frequency component of the

It represents x (t) of each component

 

Denotes a function x (t) projected on the respective components

ak * fk (t) represents the periodic function x (t) at a certain inner product component

 

 

 

This is a square wave we can see, it is by sinx, sin3x, sin5x, sin7x composition. Wherein the frequency of the sine function is called red base frequency, the frequency of all other sine function is a multiple of it.

Fourier expansion is

1. According to the fundamental frequency, each component is calculated

2. Calculate the projected periodic function of these components

3. Calculate the inner product at periodic function of the respective components, and summed

 

Guess you like

Origin www.cnblogs.com/draven123/p/11403284.html