Instructions for Reading Data files
these (ascii) files are created from binary SAC2000 files using the write alpha command
this example uses the file HECTORMINE_HEC.HLN.accn
1st 30 lines are header information from SAC. 1st row 1st column is
record sample speed (sps).
EDIT, RENAME FILE
SAC stores ASCII files with header information (station, location,
sample speed, max/min values etc) at the start of the file. Following
this are 5 columns of timeseries data until the end of the file (note
timeseries sequence is accross rows, not down columns)
download all files to the same directory you are going to run matlab
in
Using a text editor (wordpad, emacs etc), remove these 1st 30
lines.
Scroll to end of file - if last line does not have 5 rows, delete last
line
(matlab will not read a matrix if any columns do not have same number
of rows)
Save the resultant file under a new name, eg. HECN
USE MATLAB TO OBSERVE AND MODIFY TIMESERIES
I use matlab -nojvm on unix, so not all this may be applicable to you
Read the rest of the file into matlab:
load HECN
next type whos to get size of matrix:
whos
Name Size Bytes Class
HECN 1800x5 72000 double array
in this case, the matrix is 1800x5, so there are 9000 sample points in
the record (if sample rate is 0.01s, or 100Hz, or 100 samples per
second, this means our record is 1800x5/100s, or 90s long)
we want to reshape the matrix to single columns, we use the
reshape command, but this reads down columns, not accross rows
- so first transpose the matrix
HECNT=HECN';
HECN1=reshape(HECNT,1,9000);
now define the time interval (in this case , and plot data:
t=(0:.01:90-0.01);
plot(t,HECN1)
ylabel('accn, cm/s/s')
xlabel('time, secs')
title('Hector Mine Earthquake, recorded at Station HEC, HLN Comp')
can now print the fill to a postscript or jpeg for future reference
print -depsc2 HEC_N.ps
print -djpeg HEC_N.jpeg
General Matlab Tips
use subplot commands to present multiple plots on 1 figure page
loglog command plots data on log axes
detrend removes mean and linear trends from data
conv, deconv perfroms convolution and deconvolution of functions/timeseries
fft gives Fast Fourier Transform of data (note when plotting FFT, plot the absolute value, as values are typically complex numbers)
to integrate data: eg from accn to velocity - vel=cumsum(accn)*sps - note sps is the sample speed, eg 0.01 for 100 samples per second
to differentiate data: eg from velocity to accn - accn=diff(vel)/sps - sps is again sample speed. Also note this operation is the difference between successive sample points, so if there are n samples in vel, there will be n-1 samples in accn - THIS CAUSES PROBLEMS IN PLOTTING - one simple way to get around this is: plot(t(1:length(accn)),accn)
to create a big plot with accn, vel and displ:
subplot(3,1,1)
plot(t,HECN1); ylabel('cm/s/s'); title('Hector Mine Earthquake, recorded at Station HEC, HLN Comp, accn,vel and displ')
subplot(3,1,2)
plot(t,vel); ylabel('cm/s')
subplot(3,1,3)
plot(t,disp); ylabel('cm')
(I'm assuming vel, displ have been created using commands outlined above)
A Useful Matlab Tutorial
If you require a more comprehensive introduction to using Matlab, Prof Luis Suarez presents a Matlab Tutorial at UPRM Civil Engineering. He has allowed me to post his notes, which is a great background introduction to using Matlab (in Spanish)
Seminar Notes
Examples
John Clinton
Last modified: Fri Sep 9 17:21:16 GMT 2005