Python Signal Analysis Package GUI

Here is a signal analysis package GUI written using Tkinter: vibrationdata_gui_python.zip

It is compatible with Python versions 2.7 to 3.3, and hopefully future 3.x versions.

vibrationdata.py is the main script.

The remaining scripts are supporting functions.

These scripts demonstrate the use of multiple windows.

* * *

The following signal analysis functions are currently available:

Statistics
Trend Removal & Scaling
Butterworth Filter
Bessel Filter
Fourier Transform
Fast Fourier Transform (FFT)
Waterfall FFT
Power Spectral Density (PSD)
SDOF Response to Base Input
Shock Response Spectrum (SRS)
Rainflow Cycle Counting
Differentiate Time History
Integrate Time History
Autocorrelation
Cross-correlation
Cepstrum & Auto Cepstrum
Sound Pressure Level (SPL)

The following PSD functions are also available:

Overall GRMS
SDOF Response to Base Input PSD
Vibration Response Spectrum (VRS)

The following miscellaneous functions are also available:

Sine Amplitude Conversion
SDOF Response: Peak Sigma for Random Base Input
SDOF Response to Classical Pulse Base Input

More will be added in future revisions…

See also Vibrationdata Python Blog

* * *

Python Tip from Brian Hawkins for numpy arrays.

a = b merely creates a new reference to b. a[:] = b means “set all elements of a equal to those of b”. The difference is important because numpy arrays are mutable types.

* * *

– Tom Irvine

Webinar 8 – Waterfall FFT

PowerPoint File: Webinar_8_Waterfall_FFT.ppt

Audio/Visual File:  NESC Academy Waterfall FFT – Recommend viewing in Firefox with Sliverlight plugin

* * *

Data

Each of the following has two columns: time(sec) & accel(G)

terrier_black_brant_2KHz_lpf_x.zip

solid_motor_flight.txt

Fwd_Dome_ignition.txt

Orion_PA1_LS51v.txt

* * *

Terrier Black Brant Video

* * *

Matlab script: Vibrationdata Signal Analysis Package

* * *

Python Version:
Webinar_8_Waterfall_FFT_python.ppt

Python Script

* * *

See also: Vibrationdata Webinars

* * *

– Tom Irvine

Webinar Unit 1 – Natural Frequencies

We held our first Shock & Vibration Webinar on January 17, 2014. This presentation was sponsored by the NASA Engineering and Safety Center, to which I express gratitude.

A link to the audio/visual recording will be posted here in the near future.

In addition, here are some files from the January 17, 24 and 31 webinars.

PowerPoint File:  webinar_natural_frequencies.ppt

PowerPoint File:  webinar_testing.ppt

Sound File: Tuning Fork sound file

Data

Tuning Fork – time(sec) & unscaled sound pressure

Drop Transient – time(sec) & accel (G)

Videos

Slinky Demonstration

Tuning Fork mode 1
Tuning Fork mode 2
Tuning Fork mode 3

Two-degree-of-freedom System mode 1
Two-degree-of-freedom System mode 2

Chinook Ground Resonance 1
Chinook Ground Resonance 2

Flutter Videos Webpage

PDFs

Piano Key Fundamental Frequencies

Matlab scripts

Vibrationdata Signal Analysis Package

Sine & Damped Sine Curve-fitting

* * *

See also:

Vibrationdata Webinars

Rice Characteristic Frequency

SRS Educational Animation

* * *

Here are the links to the audio/visual files for the first, three webinars – Recommend viewing in Firefox with Sliverlight plugin:

NESC Academy Natural Frequencies part 1

NESC Academy Natural Frequencies part 2

NESC Academy Natural Frequencies part 3

Once you click on each link, then you can download the file to your hard drive, using File > Download > Save As

These files are about 90 Mb each, so please be patient with the downloads.

We are working on improving the audio quality…

* * *

Python Versions

PowerPoint File: webinar_1_Natural_Frequencies_python.ppt

PowerPoint File: webinar_testing.ppt

Software: Python Signal Analysis Package GUI

* * *

Please send me an Email if you would like to be on the distribution list for the webinar login information.

Tom Irvine
Email: tom@irvinemail.org

Data Curve-Fitting

Here is a good website for curve-fitting:  zunzun

From the website…

Here you can curve fit and surface fit your 2D and 3D data online with a rich set of error histograms, error plots, curve plots, surface plots, contour plots, VRML, auto-generated source code, and PDF file output.

– Tom Irvine

Cython

Cython is a compiler which compiles Python-like code files to C code. The resulting functions can then be imported into other Python scripts.

This method can be used to increase the execution speed of a Python script, particularly if the script uses for-loops.

I have added a Cython page to:  Vibrationdata Python Wiki

The page includes examples and source code for shock & vibration analysis.

* * *
Tom Irvine

Generalized Eigenvalue Problem

The goal of this project is to solve a “very large” generalized eigenvalue problem in a “reasonable” amount of time using library functions. The mass and stiffness matrices may be either dense or sparse. Optimum routines are desired for each case.

Here is description of the libraries and packages

gcc – GNU Compiler Collection for C/C++

BLAS – Basic Linear Algebra Subprograms

CBLAS – C interface to the BLAS

LAPACK – Linear Algebra PACKage. LAPACK is a software library for numerical linear algebra including the generalized eigenvalue problem. It uses BLAS.

PETSc – Portable, Extensible Toolkit for Scientific Computation. PETSc is a suite of data structures and routines for the scalable (parallel) solution of scientific applications modeled by partial differential equations. It includes a large suite of parallel linear and nonlinear equation solvers that are easily used in application codes written in C, C++, Fortran and now Python.

SLEPc – a software library for the parallel computation of eigenvalues and eigenvectors of large, sparse matrices. It can be seen as a module of PETSc that provides solvers for different types of eigenproblems, including linear (standard and generalized) and quadratic, as well as the SVD.

Note that PETSc/SLEPc requires BLAS/LAPACK.

*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *

Installation Steps:

I have a PC with Ubuntu 11.10 running with the gnome-classic shell.

I have installed the following:

Code::Blocks with the gcc compiler from the Ubuntu Software Center

*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *

BLAS

Step 1: download

$ wget http://www.netlib.org/blas/blas.tgz

Step 2: extraction

$ tar zxf blas.tgz    this will create a directory BLAS

Step 3: compilation

$ cd BLAS

$ make all

If everything was correct in the previous step, your library is in the BLAS directory, called blas_LINUX.a

*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *

CBLAS

Installation instructions:

BLAS must be installed first.

Next,

wget http://www.netlib.org/blas/blast-forum/cblas.tgz

tar zxf cblas.tgz

Go to CBLAS folder.

Open Makefiles.in in a text editor.

Modify this line in Makefiles.in

BLLIB = (specify path)/BLAS/blas_LINUX.a

make all

*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *

LAPACK

Step 1: download

$ wget http://www.netlib.org/lapack/lapack.tgz

Step 2: extraction

$ tar zxf lapack.tgz        this will create a directory lapack.

Step 3: compilation

$ cd lapack-3.3.1

The configuration can be done in the make.inc.example file:

modify:  BLASLIB      = /directory/where/to/find/BLAS/blas$(PLAT).a

The LaPack library uses the BLAS library, so you need to tell where to find it. The result is a library lapack_LINUX.a: this can be copied in a place of your choice.

Save file as:  make.inc

$ sudo apt-get install cmake      (if not installed already)

$ cmake

$ make

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

BLAS/LAPACK

The following step may also be needed:
$ sudo apt-get install libblas-dev liblapack-dev

*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *

The C++ source code for the generalized eigenvalue program is given at:
gen_eigen.cpp    (right mouse click & save target or link)

The header files are:   dsygv.h     dsyev.h     cblas.h

The source code uses BLAS, CBLAS & LAPACK.

The following linker options are required:

-lgfortran
-lblas
-llapack

* * * * * * * * *

Here is another C++ version: gen_eig.cpp

The program can be compiled via:

gcc -o gen_eig gen_eig.cpp -lblas -llapack -lstdc++

*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *

Here is a pure Fortran program for the generalized eigenvalue problem:  geigen.f

The program can be compiled via:

$ gfortran -o geigen geigen.f -lblas -llapack

* * *

Matlab scripts are given at:

Matlab Linear Algebra Page

* * *

A future generalized eigenvalue problem code will use PETSC & SLEPc.  These packages can be downloaded via:

PETSc
sudo apt-get install petsc-dev

SLEPc
sudo apt-get install slepc3.1-dev

* * *

Python is well-suited for the generalized eigenvalue problem.  It has functions derived from LAPACK.  It also has functions for sparse systems using ARPACK.  Sample scripts are posted at:

Vibrationdata Python  Generalized Eigenvalue

* * *

Tom Irvine

Python: reading two columns of numerical data with an arbitrary number of header & blank lines

Here is my current method. Please let me know if you have a better one.

The input data may be either space, tab, or comma delimited.

##########################################################################

import os
import re

from numpy import array,zeros,concatenate,linspace,std
from sys import stdin

import matplotlib.pyplot as plt

########################################################################

def start():
print(” “)
print(“Entpath =stdin.readline()
file_path = input_file_path.rstrip(‘\n’)
if os.path.exists(file_path):
print “This file exists”
print ” ”
infile = open(file_path,”rb”)
lines = infile.readlines()
infile.close()
if not os.path.exists(file_path):
print “This file doesn’t exist”
start()
return lines

########################################################################

def lines_two_columns():
#
# http://flockhart.virtualave.net/RBIF0100/regexp.html
#
lines=start()
a = []
b = []
num=0
for line in lines:
#
if re.search(r”(\d+)”, line): # matches a digit
iflag=0
else:
iflag=1 # did not find digit
#
if re.search(r”#”, line):
iflag=1
#
if iflag==0:
line=line.lower()
if re.search(r”([a-d])([f-z])”, line): # ignore header lines
iflag=1
else:
line = line.replace(“,”,” “)
col1,col2=line.split()
a.append(float(col1))
b.append(float(col2))
num=num+1
return a,b,num

##########################################################################

a,b,num =lines_two_columns()

* * *
Tom Irvine

Python on Linux

I have installed Linux Ubuntu on my 64-bit Windows PC, turning it into a dual boot configuration.

The link is:  http://www.ubuntu.com/download/ubuntu/windows-installer

* * *

I have also installed the Linux versions of Python & Spyder.

Here is a Python installation method from Nick Smith:

Part of the beauty of switching to Python is how cross-platform it is. While pythonxy hasn’t finished a linux build yet, installing spyder is pretty easy in Ubuntu:

sudo apt-get install python-sphinx python-scipy python-matplotlib spyder

Note: All you really need is spyder, but adding python-sphinx allows you to have rich text in your documentation which looks nice and in my opinion is easier to read. The packages python-scipy and python-matplotlib may be optional, but I use them in my tutorials, so I would recommend including those as well.

Reference: http://www.et.byu.edu/~nas52/blog/?p=24

Python Tip

Every Python book and website tutorial recommends the following command for prompting the user for input:

raw_input()

But I have found that this command is buggy and unreliable.

Specifically, I wrote a long, complex code that had several raw_input() commands.

The code ran successfully in Spyder. But I received the following error when I ran it in console mode: “Readline internal error” plus some other cryptic messages about console.py, hook_wrapper_23 & NoneType.

The error occurred when the code executed the second raw_input().

After hours of struggle, I found that I could use the following command instead:

sys.stdin.readline()

sys.stdin.readline() works in both Sypder and external command-line mode.

sys.stdin.readline() is a superior alternative.

Yes, my perceptions are colored by my inexperience, but I like commands that reliably work straight out-of-the-box.  So I will stick with sys.stdin.readline().