How do I create a Filter that takes out irrelevant data?

3 views (last 30 days)
Hey everyone,
So I have a large amount of data stored in a matrix that displays the surface of an object when plotted. The only problem is that this contains the whole surface, and not just the roughness curve that I need from it. How can I create a filter (i'm guessing of a gaussian type) that controls the data being output? I don't need code to be provided, just simple direction would be nice.
I had an idea for where to start but I'm not sure if it's right.
A = imread('file_name.txt'); H = fspecial('gaussian',hsize,std)
The thing about this fspecial function is that I do not know what size to specify in the argument. The documentation does not cover this unfortunately.
Thanks, Ian

Accepted Answer

Teja Muppirala
Teja Muppirala on 24 May 2011

The curve fitting toolbox can help you deal with irregular data. Here I make a noisy surface, approximate it using polynomials, subtract the two, and then display the noise. There is a neat surface fitting GUI tool called "sftool" as well.

x = rand(65000,1);
y = rand(65000,1);
z0 = log(1+x).*sin(3*y);
z = z0 + 0.05*randn(size(z0));
figure
plot3(x,y,z,'k.','markersize',1);
hold on;
F = fit([x y],z,'poly55');
plot(F);
alpha 0.5;
figure
subplot(211)
plot3(x,y,F(x,y) - z,'.','markersize',1);
subplot(212)
plot(F(x,y) - z);
  1 Comment
Ian Wood
Ian Wood on 24 May 2011
This is exactly what I was looking for. Modifying this code a little for my code, I come up with the profile roughness I need to extrapolate. Thanks Teja, and thanks to you too Ben.

Sign in to comment.

More Answers (2)

Ben Mitch
Ben Mitch on 22 May 2011
Hi Ian
There's some information missing from your question, but it sounds like you're looking to interpolate a large amount of data to summarize its form with a small data set.
If so, you might get some mileage out of interp2() and filter2(), if that's the case (interp() and filter() if your "surface" is 1-D). Use interp2() to get the value of your function on a high-resolution regular grid, then use filter2() to smooth it as much as you like (use a matrix of ones as "b" in filter2()), then use interp2() again (or simply decimate) to obtain a smoothed surface on a low-resolution regular grid.
If you need more control over the curvature of the summary surface, you could try instead polynomial estimation. Denote your input data [x, y] as X, and your output data [z] as Y, and use polyfit() to fit an nth-degree polynomial of your choice, then use polyval() to provide a summary data set on a regular grid.
Cheers
  1 Comment
Ian Wood
Ian Wood on 23 May 2011
Hi Mitch,
Thanks for the reply. What you said in the first paragraph is the idea yes. I will see what I can come up with using your suggestion and let you know how it goes.
Regards

Sign in to comment.


Ian Wood
Ian Wood on 24 May 2011
Ok so if I'm reading this correctly the pre-defined function interp2 requires a monotonic matrix, and unfortunately that's not what i have. I will provide more information:
So it's a ~65000 by 3 matrix, that holds x, y, and z plot points to approximate a surface. The problem is it's a surface and not a 2-D roughness curve, which i need to calculate certain parameters, but that code is already done. I just need to know the best method to get this roughness curve.
It should look like a zig-zag pattern. The useful part of the filtering is eliminating the data that represents the surface. Once I have this curve I can take the difference between the two plots (original and filtered), and this will give me the variables i need to implement in my equations.
  2 Comments
Ian Wood
Ian Wood on 24 May 2011
It's terminology for a surface's actual profile at a microscopic level. The heights deviating from the average profile are usually very small (micrometres).

Sign in to comment.

Categories

Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!