moonman239 said:
Here's what I want to do: take a few "snapshots" of the accelerometer data then find the median value of the said data. (That part I can do.) I will then calculate the magnitude of an assumed earthquake on the Richter scale. Then I will subtract any measurement error (ie, if the typical error in measurement is .5, and I calculate a magnitude of .7, I will just subtract .5 from .7, so according to my calculations the actual magnitude of a theoretical earthquake should be .2).
But, how do I calculate the magnitude of the earthquake?
It's not as simple as you think. The determination of the magnitude is dependent on a number of factors, not least the distance from the hypoentre. Generally the classification is worked out by comparing readings from a number of different locations and presumably by computers which triangulate the position of the earthquake; i say triangulate, it's not quite the same, but the principle is there.
Think about it, if you're at the centre of a small earthquake, it will feel to you the same as if you were on the outskirts of a large earthquake. Astronomers face similar difficulties when determining stellar parameters - is it a big star far away, or a small star close up? Indeed, the Richter scale was supposedly inspired by the absolute magnitudes astrophysicists refer to when discussing brightness.
So that's it really, you need to know where the quake is in order to define how big it is - the primary purpose of a proper seismograph is location finding, magnitudes are secondary. What you need to do is measure the P and S waves as they arrive (and also determine that they are indeed P and/or S waves) - with very precise timing. From that you can work out a circle of points where the earthquake could be.
Once you know where the quake happened, or at least how far away it happened, you can then work out the corrected magnitude. On paper-based seismographs that you can buy in stores, one works out the timing by hand and then compares the amplitude of the trace to a lookup table with distance-amplitude-magnitude readings. The original Richter scale is defined using the amplitude of the trace on a particular seismograph so all other instruments must be calibrated accordingly.
To do this electronically, you'll need a minimum of two amplitude readings, ideally as many as you can, including a zero reading which you can compare to known magnitudes. After you have a few such measurements, you can plot graph of them to interpolate your live results. Remember that the Richter scale is log-10 based, so when you work out your calibration equation, it will be logarithmic, not a linear or polynomial fit.
http://www.geo.mtu.edu/UPSeis/locating.html
If you want to simulate an earthquake, then you could cheat a little and hard code an earthquake distance so that all your amplitudes are corrected for that distance. You'll still need to calibrate the accelerometer, however, to know how your shaking correlates to actual earthquakes.
Also, with regards to errors, you shouldn't simply subtract. Measurement errors are generally quoted as ± so if you measured magnitude 0.7 with a measurement error of 0.2, your actual quake would be 0.7±0.2. If, with your example your error was 0.5, and that was an upper bound, you could say that your magnitude was somewhere between 0.2 and 1.3. What you should be aiming towards is a statistical statement like "I am 95% confident that this Earthquake was between 0.5 and 0.9". If, however, you had a systematic error of magnitude +0.5 then you could subtract it; this is the case, for instance, with CCD cameras that add a bias level to the number of photons they count. In this case, you're more likely to be removing background vibrations so it makes more sense to work out the maximum "no earthquake" magnitude and then ± that from your final calculation.