[关闭]
@2014301020054 2016-12-19T11:51:37.000000Z 字数 6256 阅读 401

Exercise_13 : Waves

python physics 2014301020054


Abstract

In physics, a wave is an oscillation accompanied by a transfer of energy that travels through a medium (space or mass). Frequency refers to the addition of time. Wave motion transfers energy from one point to another, which displace particles of the transmission medium–that is, with little or no associated mass transport. Waves consist, instead, of oscillations or vibrations (of a physical quantity), around almost fixed locations.


Background

Ideal case

From the figure6.1, if we assume the string displacement is small, so that the angles are also small,we can write the equation of motion of segment as:

Then we use a finite difference approximation for the angles:

We obtain:

By taking time and x into finite setps and . In the numerical approach, we rewrite the equation into this form:

We can express in terms of at previous time steps, with result:

Gaussian pluck (semirealistic)

That is, we have taken the initial string profile to be:

Realistic case

Where is a dimisionless stiffness parameter.

Using the same approach that we used to obtain that second partial derivation in C hapter 5. The result is:

Also, in the case of realistic string, the numerical equation becomes:

Where is the number of spatial units along the string.


Main Body

Problem 6.12(6.16)

Gaussian intial string displacements are convnient for the calculations of this section, but are not very realistic. When a real string, such as a guitar string, is plucked, the initial string displacement is more accurately described by two straight lines that start at the ends of the string(we assume fixed ends) and end at the excitation point, as illustration in Figure6.4. Compare the power spectrum for a string excited in this manner with the results found above for a Guassian initial wavepacket.

Codes

  1. import matplotlib.pyplot as plt
  2. from matplotlib import animation
  3. import numpy as np
  4. from scipy.fftpack import rfft, irfft, fftfreq
  5. class Guass_seidel:
  6. def __init__(self,L,dx,T,e):
  7. self.L = L
  8. self.dx = dx
  9. self.r = 0.25
  10. self.c = 300
  11. self.T = T
  12. self.dt = self.dx/(4*self.c)
  13. self.e = e
  14. pass
  15. def initialization(self):
  16. self.string = []
  17. for i in range(int(self.T/self.dt)):
  18. self.string.append([])
  19. for j in range(int(self.L/self.dx)):
  20. self.string[i].append(0)
  21. for l in range(1,int(int(self.L/self.dx) - 1)):
  22. self.string[0][l] = np.e**(-0.1*(l - 30)**2)
  23. self.string[0][1] = 0
  24. self.string[0][-2] = 0
  25. self.string[0][0] = - self.string[0][2]
  26. self.string[0][-1] = - self.string[0][-3]
  27. self.string[1] = self.string[0][:]
  28. #plt.plot(self.string[1])
  29. def calculation(self):
  30. M = int(self.L/self.dx)
  31. for i in range(2,int(self.T/self.dt)):
  32. for j in range(2,M-2):
  33. self.string[i][j] = (2 - 2*self.r**2 - 6*self.e*self.r**2*M**2)*self.string[i - 1][j] - self.string[i - 2][j] + self.r**2*(1 + 4*self.e*M**2)*(self.string[i-1][j+1]+self.string[i-1][j-1]) - self.e*self.r**2*M**2*(self.string[i-1][j+2]+self.string[i-1][j-2])
  34. #self.string[i][j] = 2*(1-self.r**2)*self.string[i - 1][j] - self.string[i - 2][j] + self.r**2*(self.string[i - 1][j + 1] +self.string[i - 1][j - 1])
  35. self.string[i][0] = -self.string[i][2]
  36. self.string[i][-1] = -self.string[i][-3]
  37. #plt.plot(self.string[-1])
  38. return self.string
  39. def fft(self):
  40. t_plot = np.arange(0,self.T,self.dt)
  41. amplitude_record = []
  42. for i in range(int(self.T/self.dt)):
  43. amplitude_record.append(self.string[i][20])
  44. freq = fftfreq(len(amplitude_record), d=self.dt)
  45. freq = np.array(abs(freq))
  46. f_signal = rfft(amplitude_record)
  47. f_signal = np.array(f_signal**2)
  48. #plt.subplot(122)
  49. plt.title('Power spectra')
  50. plt.ylabel('Power (arbitrary units)')
  51. plt.xlabel('Frequency (Hz)')
  52. plt.xlim(2000,8000)
  53. plt.plot(freq,f_signal,label = 'epsilon = '+str(self.e))
  54. return 0
  55. A = Guass_seidel(1,0.01,0.05,0)
  56. A.initialization()
  57. A.calculation()
  58. A.fft()
  59. # ---- animation ---------------------------------
  60. fig = plt.figure(figsize = (8,6))
  61. ax = plt.axes(xlim=(0, 1),ylim = (-1,1))
  62. line, = ax.plot([], [], 'k')
  63. def init():
  64. line.set_data([], [])
  65. return line,
  66. def animate(i):
  67. x_plot = np.arange(0.01,0.99,0.01)
  68. y_plot = []
  69. for j in range(1, int(A.L/A.dx) - 1):
  70. y_plot.append(data_record[i][j])
  71. line.set_data(x_plot,y_plot)
  72. return line,
  73. anim = animation.FuncAnimation(fig, animate, init_func=init, frames=100, interval=50, blit=True)
  74. anim.save('chapter6_string_guass_e.gif', fps=20, writer='Feng_Chen')
  75. plt.show()

First we can investigate the wave on a string, and chose the condition used in figure 6.2 that and and string runs from to 1m.

Then we want to find the result that give two Gaussian pluck, one is at , and the other at .

From the results above, we can draw the conclusion that when there are two Gaussian wave packets located at different places on the string, the wave packets may then propagate and collide but the wave packets are unaffected by the collisions.

Also I want to find the result that frequency spectrum of waves on a Gaussian-excited string.
Suppose the initial wavepacket is

And the total length of the string is 1 unit.
When and
We have:

We can polt the power spectrum figure:

When the point deviation , we chose , to find the power spectrum figure.

Because we have the possible frequencies as . This explains why the peaks in the spectral analysis in the above figures occur at regularly spaced frequencies. Each of the peaks correspond to one value of interger m. But some frequancies are missing and this can be traced to the operation of Fourier Transformation. So when is the times of 150, there will be a wave crest.

When the intial wave packet was a real one.

We can polt the power spectrum figure:

when When the point deviation from the center of spring,
We can polt the power spectrum figure:

Because of the loss of symmetry, there be more wave crest.


Conclusion

In realistic case, the friction of the string will cause a frequency shift especially for the high frequency. Also, the frequencies which excited in a guitar are always low frequencies.


Acknowledgement

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注