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

조회 수: 5 (최근 30일)
Ian Wood 2011년 5월 21일
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

댓글을 달려면 로그인하십시오.

### 채택된 답변

Teja Muppirala 2011년 5월 24일

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이전 댓글 -1개 표시이전 댓글 -1개 숨기기
Ian Wood 2011년 5월 24일
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.

댓글을 달려면 로그인하십시오.

### 추가 답변 (2개)

Ben Mitch 2011년 5월 22일
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이전 댓글 -1개 표시이전 댓글 -1개 숨기기
Ian Wood 2011년 5월 23일
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

댓글을 달려면 로그인하십시오.

Ian Wood 2011년 5월 24일
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없음 표시없음 숨기기
Walter Roberson 2011년 5월 24일
What is a "roughness curve" ?
Ian Wood 2011년 5월 24일
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).

댓글을 달려면 로그인하십시오.

### 카테고리

Help CenterFile Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기

### Community Treasure Hunt

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

Start Hunting!

Translated by