Remove noise parts in the signal

2 次查看(过去 30 天)
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');

采纳的回答

Star Strider
Star Strider 2020-9-7
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])
.
  3 个评论
Leo David
Leo David 2020-9-13
Hi,
I changed n from 57 to 2, the signal waveform is look like this.
The wave before t = 1200 is useless waveform.
How could I remove those and keep wave only after t = 1200?
By the way, what is the value of n in your script?
Star Strider
Star Strider 2020-9-13
First: figure(1) is the original time-domain signal, figure(2) is the Fourier transform of the original signal, and figure(3) is the Fourier transform off the filtered signal.
Second: The index of 1200 corresponds approximately to 40 seconds, using the time vector in my code. To keep only the data after index 1200:
data = data(1200:end);
t = t(1200:end);
Third: I looked at various values for ‘n’ to see if I could write something that could generalise to all the records. I could not. That was the basis of my Answer.
There might be a way to automatically threhsold the records to determine if the entire record is relatively noiseless, and if not, how to determine what the reliable parts off the signal are. The width of the peak of the Fourier transform is likely the best determinant of the noise content, after which it could be possible to automatically determine the region containing the most reliable data.
For 2 (and perhaps others like it), something like this could work:
mvdata = movvar(data, 350);
tmvdata = mean(mvdata)*0.75;
idx = find(mvdata > tmvdata, 1, 'last');
figure
plot(t, data)
hold on
plot(t, mvdata, 'LineWidth',1.5)
plot(t(idx)*[1 1], ylim, '-r')
hold off
grid
title('PPG Signal')
xlabel('Time (s)')
ylabel('Amplitude (?)')
figure
plot(t(idx:end), data(idx:end))
grid
title('PPG Signal')
xlabel('Time (s)')
ylabel('Amplitude (?)')
.

请先登录,再进行评论。

更多回答(1 个)

Image Analyst
Image Analyst 2020-9-7
Here is some improved code. But I'm not quite sure what you want.
% Initialization steps.
clc; % Clear the command window.
fprintf('Beginning to run %s.m ...\n', mfilename);
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
fileName = fullfile(pwd, 'examples.mat');
if ~isfile(fileName)
warningMessage = sprintf('File not found:\n%s', fileName);
uiwait(errordlg(warningMessage));
return;
end
s = load(fileName);
examples = s.ppg; % Get a structure array.
fprintf('There are %d examples in the ppg structure inside %s.\n', length(examples), fileName);
n = 57;
y = examples(n).data;
fprintf('example(%d) has %d elements in it.\n', n, length(y));
subplot(2, 1, 1);
plot(y, 'b-');
grid on;
xlabel('Times', 'FontSize', fontSize);
ylabel('Amplitude', 'FontSize', fontSize);
title('Original Noisy Signal', 'FontSize', fontSize);
drawnow;
fs = 30;
fpass = 3;
yf = lowpass(y, fpass, fs);
subplot(2, 1, 2);
plot(yf, 'r-');
grid on;
xlabel('Times', 'FontSize', fontSize);
ylabel('Amplitude', 'FontSize', fontSize);
title('Filtered Signal', 'FontSize', fontSize);
g = gcf;
g.WindowState = 'maximized';
fprintf('Done running %s.m ...\n', mfilename);
If it's not what you want, try adjusting fs and fpass.
  1 个评论
Leo David
Leo David 2020-9-13
Hi,
I changed n from 57 to 2, the signal waveform is look like this.
The wave before t = 1200 is useless waveform.
How could I remove those and keep wave only after t = 1200?
By the way, if there is way to detect which part I should remove via codes?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Multirate Signal Processing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by