Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

5 Commits

Repository files navigation

Vibrational System Simulation

PythonNumPySciPyMatplotlib

A Python simulation of a damped harmonic oscillator with forced vibration analysis using FFT.

Table of Contents

Description

This program simulates the behavior of a damped harmonic oscillator under forced vibration, then analyzes the displacement using Fast Fourier Transform (FFT). The simulation includes:

  • Time-domain analysis of displacement and force
  • Frequency-domain analysis via FFT
  • Visualization of both time and frequency responses

Mathematical Model

The system is modeled using the second-order differential equation: mẍ + cẋ + kx = F₀cos(ωt)

text

Converted to state-space representation: Aẋ + Bx = F

text where:

  • A = [[m, 0], [0, 1]]
  • B = [[c, k], [-1, 0]]
  • F = [F₀cos(ωt), 0]

Dependencies

  • Python 3.x
  • NumPy (>=1.20)
  • SciPy (>=1.7)
  • Matplotlib (>=3.4)

Installation

  1. Clone the repository:
git clone https://github.com/arturr0/python-simulator.git
cd vibration-simulation

Install required packages:

pip install numpy scipy matplotlib

Usage

Run the simulation:

python vibration_simulation.py

Parameters

ParameterDescriptionDefault Value
mMass (kg)2.0
kSpring constant (N/m)2.0
cDamping coefficient (Ns/m)0.2
omegaForcing frequency (rad/s)1.0
F0Force amplitude (N)1.0
delta_tTime step (s)0.001
timeSimulation duration (s)100

Output

The program generates two plots:

Time Domain:

  • Displacement (x) vs. Time
  • Force (F) vs. Time

Frequency Domain:

  • FFT magnitude of the displacement
  • Shows dominant frequency components

Customization

To modify the simulation:

Change system parameters at the top of the script:

m=2.0# Massk=2.0# Spring constantc=0.2# Damping

Adjust forcing function:

ift<=15: # Force durationF[0] =F0*np.cos(omega*t)
else:
F[0] =0.0# Force removal

Change simulation duration and time step:

delta_t=0.001# Time steptime=np.arange(0.0, 100.0, delta_t) # Simulation time

Theory

Numerical Integration

The state-space equations are solved using forward Euler integration:

x=x+delta_t*inv(A).dot(F-B.dot(x))

Fast Fourier Transform

The displacement data is analyzed using SciPy's FFT:

Y=fft(X)

License

Free for academic, personal, and research use.

About

Damped vibrations simulator

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages