I tried using medfilt1 which removed isolated spikes. But, the "long" spiked region between 310 and 320 seconds wouldn't improve.
MATLAB: How to get rid of spikes in the data due to phase shift from 2pi to 0
spikes
Related Solutions
Your mindmap has your problem broken up into small chunks. That's the first step towards modularizing your code. As you correctly guessed I would make each of those chunks either scripts or functions, which would make your main script or function look something like:
while ~done getDataFromUser; startFitting; fitAllData; plotAllGraphs; setAxesRangesNamesEtc; done = askUserIfTheyWantToReset;end
Each of these pieces, if written as a script, could use all the data from the other pieces. But since they probably don't need all the data produced by the other pieces, I would design them as functions that accept only what they need to do their jobs and return only their "finished products." That compartmentalization of work means that ideally once you write one of these functions, if you need to change its internal implementation that function is the only thing you need to modify and if you need to change its inputs or outputs only those functions upstream that create or manipulate the inputs or only those functions downstream that use the outputs need to be changed. It also means they can be tested in isolation from one another, which for a complicated system can be a Very Good Thing.
This approach, particularly if you use functions, will require (or at least benefit if you do) some up-front design work. You've already done part of that, as I mentioned, with your mindmap. But I've written MATLAB code in the past that simulated goto (as part of investigating some old Fortran code) and it required some mental gymnastics and some whiteboard scribbling to keep straight what was going on and where I was going in which handbasket :) I strongly encourage you to go the script or function route.
hampel should get you started
plot(hampel(OutAIS.Data))
If you need something fancier, take a look at the diff of your signal:
plot(diff(OutAIS.Data),'.')
Your outliers seem to take a set of quantized values. That might help you replace the values with something more meaningful than a median.
Best Answer