CFTool: how to get output and use those data
Show older comments
I have a signal which I want to "flatten":

There are specific points I select (too complicated to explain why, just trust that I have to select these points):

so when they are superimposed you can see how the selected points mirror the original signal:

I then use CFTool and "smoothing spline" model to get the smoothed curve through the selected points:

My QUESTION is: how can I now get the x,y points from the CFTool so that I can go back to my original data (stored as an array) and subtract the smoothed curve from the original data and thereby "flatten" the signal. In short, I have created a smoothed "baseline" using CFTool which I want to subtract from the original signal.
I can't figure out how to get these x,y, data out from CFTool. The command "Save to Workspace" generates obscure parameters in my workspace. The MatLab CFTool help is too opaque for me. Is there an easy tutorial for this or better still, do you have an easy explanation?
Thanks!
Answers (1)
dpb
on 13 Jun 2017
I'll grant the CF Tool is really opaque in many ways, fer shure...this is perhaps the most of the many dark corners...
When you save the fit to workspace you're given the opportunity to name the fit object and some other data. For a smoothing spline example I just used SS for the object and SSout for the residuals object.
To use it, with the x vector you have, simply
ySS=SS(x); % evaluate the cfit at x
The content of SS is a fit object; the particulars within such an object are dependent on the type of fit. The information within the cfit object can be accessed from
SSstruct=coeffvalues(SS); % a structure holding the fit object info
>> coeffvalues(SS)
ans =
form: 'pp'
breaks: [1x101 double]
coefs: [100x4 double]
pieces: 100
order: 4
dim: 1
>>
for the one I did with some data here.
See the doc section "Fit Postprocessing" under the 'cfit' documentation to get to the more detailed explanations.
Hopefully that'll get you started.. *)
Feel free to ask more detailed and attach the actual data/object if still have trouble.
4 Comments
dpb
on 14 Jun 2017
Pick a name for the objects in the Save Fit window...the first will be a fit object, the second a structure of GOF data and the last the residuals (yes, I know, the residuals, NOT the predicted values, we'll deal with that in a minute.
Again, I'll use SS for smoothing spline and 'cuz it's short as base name and SSout for residuals.
Now you'll have those objects by that name in the workspace. I've never tried this with none for x; I didn't think it could do that).
Anyway, I presume you know where these values are, if not you can get them by
x1=find(isfinite(transposedata1));
yhat1=SS(x1); % will be those points
I can't tell whether the 480 points in the data array are the ordinal numbers 1:480 or something else??? -- looks like goes past 500 on the fit so I presume that's the case with the originals, I'm not sure there.
But, anyway, set
x=linspace(xStrt,xEnd,480); % one way to get 480 points
yfit480=SS(x); % evaluate the fit at those points
You'll just have to know from somewhere what the x values were that were implicit in the fitting that you did.
Again, use
coefficients(SS)
to see what the content of the fit structure is; just type
SSout
to see the output structure members.
Stephen
on 14 Jun 2017
BTW, you recognize you can do the same thing programmatically as
SS=fit(x1,transposedata1,'smoothingspline');
don't you? x1, transposedata1 each need be column vectors. That's the same fit object returned as that the cftool returns as the fit object with default values.
I still don't quite follow what it's doing in the tool when the none option for x data is selected--there's got to be some x data somewhere!
ADDENDUM OK, as I presumed must be, there's a helper function prepareCurveData that takes the input [] for X and returns the indices to Y after removing NaN/Inf. You can see this if you ask for the Generate Code option under File, calling that function is the first thing the generated function does.
Categories
Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
