Eliminating the noise from the raw data using median filter
19 views (last 30 days)
Show older comments
Hi everyone,
I have a raw csv file data and when I am to plot it, it seems pretty noisy. What I wanted to do ıs either the entire signal(data); or just along the decay curve to be smoothened; in other words; deleting the noise as much as possible. I'd be appreciated if anyone could help me out.
Here's the code that I am dealing with. Apart from reading the csv file, I also come across a similar code on the community so I was trying to modify it.
% Remove quiet parts of a signal.
clc;
close all;
clear;
workspace;
format long g;
format compact;
fontSize = 25;
data= readmatrix('T0027CH1.CSV');
x=data(:,1);
y=data(:,2);
y=(y+35.6);
x=(x+0.8*10^(-3));
N = 125013; % length(col1) if doing the whole signal
col1 = data(1:N, 1);
subplot(2, 2, 1);
plot(col1,y,'b-')
grid on
title('Original Signal', 'FontSize', fontSize);
subplot(2, 2, 2);
col1a = medfilt1(abs(col1),50000);
plot(col1a,y,'b-')
title('After median filter', 'FontSize', fontSize);
threshold = 50;
yline(threshold, 'Color', 'r', 'LineWidth', 2)
grid on;
badIndexes = col1a < threshold;
subplot(2, 2, 3);
plot(badIndexes,y, 'b-', 'LineWidth', 2);
title('Bad parts', 'FontSize', fontSize);
grid on;
% Remove bad indexes.
col1(badIndexes) = [];
subplot(2, 2, 4);
plot(col1,'b-')
grid on;
title('Bad parts removed', 'FontSize', fontSize);
2 Comments
Answers (1)
Mathieu NOE
on 28 Nov 2022
hello again
is it now smooth enough ?
% Remove quiet parts of a signal.
clc;
close all;
clear;
workspace;
format long g;
format compact;
fontSize = 25;
data= readmatrix('T0027CH1.CSV');
x=data(:,1);
y=data(:,2);
y=(y+35.6);
x=(x+0.8*10^(-3));
% removing x NaNs
idx = ~isnan(x);
x = x(idx);
y = y(idx);
ys = smoothdata(y,'gaussian',2500);
plot(x,y,'b',x,ys,'r')
legend('raw','smoothed');
4 Comments
Mathieu NOE
on 31 Jan 2023
hello again
If my submission fullfills your request, do you mind accepting it ?
tx
See Also
Categories
Find more on Multirate Signal Processing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!