Median filter for an imported Excel file (removing spikes from a signal)
3 次查看(过去 30 天)
显示 更早的评论
My excel file has 2 columns with the two variables winkel (x-axis) and weg (y-axis). I want to remove the spikes from my signal. How do I do this with the medfilt command or is there another solution? I am completely desperate. Thanks in advance
clear all;
xlsread('Stahl_rau.xlsx');
tbl = readtable ('Stahl_rau.xlsx');
weg = tbl.Weg;
winkel = tbl.Winkel;
plot(winkel,weg,'LineWidth',0.2);
set (gca, 'Xtick', 0:30:360);
set (gca, 'Ytick', -1.5:.05:1.5);
ylim([-0.1 1])
xlim([0 360])
0 个评论
采纳的回答
Chad Greene
2021-3-28
weg_f = medfilt1(weg,3);
weg_f = movmedian(weg,3);
Depending on what exactly you're trying to do, you may prefer a different solution, which would be to use isoutlier to find the outliers and set them to NaN, like this:
weg(isoutlier(weg)) = nan;
0 个评论
更多回答(1 个)
freshprince
2021-3-28
1 个评论
Chad Greene
2021-3-28
It's hard to troubleshoot what the problem could be if the only information is "there is always an error." If you want to use medfilt1, then describe the error and maybe we can get to the bottom of it.
You say you're not seeing a change with movmedian. I assume you mean the signal looks the same before and after applying a 3 point median window? If the outliers are more than 1 point long, then the median of a 3 point moving window will follow the outliers.
It looks like the spikes are adequately removed by isoutlier, but now you want to fill in the gaps with some reasonable values. It's important to keep in mind that in this situation, any method of filling in the gaps is just making up data. Depending on the application, that might be absolutely fine, or it might be problematic, so that's where your judgment has to come in.
One way to fill in the gaps after using isoutlier is to use fillmissing. To do that, you might use the option to linearly interpolate across the sections of missing data, like this:
weg(isoutlier(weg)) = nan;
weg = fillmissing(weg,'linear');
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Preprocessing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!