Smoothing 2 columns text file
1 次查看(过去 30 天)
显示 更早的评论
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/158496/image.png)
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 个)
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'
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!