Some Matlab stuff
Notes on the Matlab Onramp course
Resources
STRUCTURAL GEOLOGY
by Stephen J. Martel
Department of Geology and Geophysics
School of Ocean and Earth Science and Technology
University of Hawai’i at Manoa
https://www.soest.hawaii.edu/martel/Courses/GG303/
Signal processing and earthquake triggering
Now i will post some of my experience with the Matlab Onramp course. I think it is a really cool course and totally would recommend it.
Project: Electricity Usage
Electricity data is stored in a file named electricity.mat
. Use load
to bring that data into MATLAB.
load electricity.mat %data sample price&usage
Enter usage
at the command prompt to see the values in usage
.
One of the elements in the usage
variable has a value of NaN
. Replace this value with the value 2.74
usage(2,end)=2.74
The residential data is stored in the first column. Create a variable res that contains the first column of usage.
res=usage(:,1)
The commercial data is stored in the second column. Create a variable comm
that contains the second column of usage
.
comm=usage(:,2)
The industrial data is stored in the third column. Create a variable ind that contains the third column of usage
ind=usage(:,3)
Create a column vector named yrs
that represents the years starting at 1991 and ending with 2013.
yrs=(1991:2013)’
Plot res
(y-axis) against yrs
(x-axis) with a blue (b
) dashed line (--
).
Issue the hold on
command so that you can add another line to the existing plot.
Plot comm
(y-axis) against yrs
(x-axis) with a black (k
) dotted line (:
)
plot(yrs,res,’b — ‘)
holdon
plot(yrs,comm,’k:’)
Plot ind
(y-axis) against yrs
(x-axis) with a magenta (m
) dash-dot line (-.
)
title(‘July Electricity Usage’)
legend(‘res’,’comm’,’ind’)
10.2 Project - Audio Frequency
fs = 10
t=0:1/fs:20
y=sin(1.8*2*pi*t)+sin(2.1*2*pi*t)
plot(t,y)
yfft=fft(y)
n=numel(y)
f=0:fs/n:fs*(n-1)/n
plot(f,abs(yfft))
Complete! Notice the two spikes on the left side of the plot which correspond to the frequencies of the two sine waves you created earlier. Since the spikes are close together, the signal exhibits the beat phenomenon.
Why are there four spikes? That relates to the Nyquist frequency, which in this case is 5
(or fs/2
). When the input vector consists of real numbers, the fft
function always returns data whose magnitude is symmetric about the Nyquist frequency. That is, the second half of the plot (after the Nyquist frequency) is just a mirror image of the first half.
FINAL PROJECT STELLAR MOTION
This is the final project of the course. I will upload my files later on.