# how to filter the noise of a signal

10 visualizzazioni (ultimi 30 giorni)
Luca Tognetti il 28 Feb 2023
Risposto: Mathieu NOE il 28 Feb 2023
Hi, I need to filter the signals when the value is close to 0 (where the noise is much present). as you can see from the picture there is a lot of noise. I attached the .mat file and the picture
I don't need a particular filter, i just need to clean it a bit so I ask you which is the best method.
thanks.
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

Mathieu NOE il 28 Feb 2023
hello
I was surprised to see that your signal length is very long (730185 samples) and probably you are using a quite high sampling rate for what you really need
so basically I started downsampling your data with decimate (that includes also a low pass filter) and that is enough to already decrease significantly your noise level (which is high freq noise)
as a second step you can add some smoothing with smoothdata (equivalent to a low pass filter without phase distortion)
fyi, you can remove the decimation step if you really need to keep that high amount of data, but for plotting we rarely need more than a few thousands points
Zoom
% convert to double
F = double(F);
x = 1:numel(F);
% decimate first
r = 25;
Fd = decimate(F,r);
xd = 1:r:x(end);
% then low pass filter
N = 25;
Fs1=smoothdata(Fd,'movmedian',N);
plot(x,F,xd,Fd,xd,Fs1)
legend('raw','decimated','decimated and smoothed');
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Più risposte (2)

John D'Errico il 28 Feb 2023
Modificato: John D'Errico il 28 Feb 2023
This is probably a good task for a median filter.
whos
Name Size Bytes Class Attributes F 730185x1 2920740 single ans 1x35 70 char cmdout 1x33 66 char
plot(F)
Fhat = medfilt1(F,100);
plot(Fhat)
Larger values for the second argument will produce a wider window for the filter.
There are many options of course, and many tools you can use.
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

Joel il 28 Feb 2023
toleranz=5;
for i=1:length(F)
if abs(F(i))<toleranz
F(i)=0;
end
end
plot(F)
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Multirate Signal Processing in Help Center e File Exchange

R2021a

### Community Treasure Hunt

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

Start Hunting!

Translated by