MATLAB: Remove noise parts in the signal

signal processingSignal Processing Toolbox

Hi,
How could I remove the noise from a mat file?
The fs is 30 Hz. I tried to use a low pass filter, but seem not work well.
I am not good at programming matlab.
Could you fix my code and explain that?
Kind Regards,
David
clear all;
load('examples.mat');
n = 57;
y = examples(n).data;
figure(1)
grid on;
plot(y);
xlabel('Times');
ylabel('Amplitude');
title('Original Noisy Signal');
fs = 30;
fpass = 3;
yf = lowpass(y, fpass, fs);
figure(2)
grid on;
plot(yf);
xlabel('Times');
ylabel('Amplitude');
title('Filtered Signal');

Best Answer

The problem is that your signal displays broadband noise (readily apparent in the Fourier transform plot), and no freuqency-selective filter is going to have any effect on it. The best you can do is to use wavelets, or the smoothdata function (introduced in R2017a), however your signal resisted my attempts to reduce the noise in the fft using 'sgolay' or any other method.
I post my code in the event you want to experiment with the smoothdata function:
D = load('examples.mat');
data = D.ppg.data;
Fs = 30; % Sampling Frequency (Hz)
Fn = Fs/2; % Nyquist Frequency (Hz)
L = numel(data);
t = linspace(0, L, L)/Fs;
figure
plot(t, data)
grid
title('PPG Signal')
xlabel('Time (s)')
ylabel('Amplitude (?)')
datam = mean(data);
FTdata = fft(data - datam)/L;
Fv = linspace(0, 1, fix(L/2)+1)*Fn; % Frequency Vector

Iv = 1:numel(Fv); % Index Vector

figure
plot(Fv, abs(FTdata(Iv))*2)
grid
title('Fourier Transform - Original Signal')
xlabel('Frequency (Hz)')
ylabel('Amplitude (?)')
xlim([0 7])
datafilt = smoothdata(data, 'rlowess', 15);
datam = mean(datafilt);
FTdatafilt = fft(datafilt - datam)/L;
Fv = linspace(0, 1, fix(L/2)+1)*Fn; % Frequency Vector
Iv = 1:numel(Fv); % Index Vector
figure
plot(Fv, abs(FTdatafilt(Iv))*2)
grid
title('Fourier Transform - Filtered Signal')
xlabel('Frequency (Hz)')
ylabel('Amplitude (?)')
xlim([0 7])
.