필터 지우기
필터 지우기

Smoothing 2 columns text file

조회 수: 1 (최근 30일)
Alex M.
Alex M. 2016년 11월 29일
댓글: Alex M. 2016년 12월 1일
Hi, I would like to have a smoothed line fitting my data in order to get rid of the noise. Below is the what the data looks like along with the code I am using. How can I implement a simple smoothing method to my code? Thank you.
fid=fopen('1GPL.txt');
s=textscan(fid,'%d %d %d','headerlines',23);
fclose(fid);
x=s{1};
y=s{2};
xx=x(x>=400 & x<=700);
yy=y(x>=400 & x<=700);
plot(xx,yy)
  댓글 수: 1
Alex M.
Alex M. 2016년 12월 1일
In addition, I tried using smooth but it doesn't seem to be working properly here.

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

답변 (1개)

Jorrit Montijn
Jorrit Montijn 2016년 12월 1일
Hi Alex,
Have you looked into using a function like filtfilt()? You can look it up in the MATLAB help; you can use several built-in filters depending on the type of filtering you wish to apply.
Alternatively, you can perform a simple convolution with conv(). You could for example apply a Gaussian filter like this:
yyFiltered = conv(yy,normpdf(-2:2,0,1)./sum(normpdf(-2:2,0,1)),strFlag)
Note that this way you either get a shorter trace when strFlag is 'valid', or has artifacts near the edges, because of zero-padding when using strFlag = 'same'
  댓글 수: 1
Alex M.
Alex M. 2016년 12월 1일
Hi Jorrit, I am unsure how to apply designfilt in my case when using filtfilt. Also the convolution method doesn't work and returns:
Undefined function 'conv2' for input arguments of type 'int32'.
Error in conv (line 40)
c = conv2(a(:),b(:),shape);
Error in test (line 12)
yyFiltered = conv(yy,normpdf(-2:2,0,1)./sum(normpdf(-2:2,0,1)),'valid')

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

카테고리

Help CenterFile Exchange에서 Smoothing and Denoising에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by