Median filter for an imported Excel file (removing spikes from a signal)
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
freshprince
el 28 de Mzo. de 2021
Comentada: Chad Greene
el 28 de Mzo. de 2021
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 comentarios
Respuesta aceptada
Chad Greene
el 28 de Mzo. de 2021
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 comentarios
Más respuestas (1)
freshprince
el 28 de Mzo. de 2021
1 comentario
Chad Greene
el 28 de Mzo. de 2021
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');
Ver también
Categorías
Más información sobre Data Preprocessing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!