Apply a filter to a dataset of ecg signals

10 vues (au cours des 30 derniers jours)
Sabaudian
Sabaudian le 17 Juin 2022
Commenté : Sabaudian le 17 Juin 2022
I have a dataset of 48 ECG signals (attached here as a zip file, but I use it unzipped), placed in a directory. I have use a for-cicle to load all the signal in the workspace, but now I am a bit confunsed.
I want to apply to the signals a Band-Pass Butterworth filter, so I use butter to design the filter and filtfilt to apply it. But I have a problem with size in "y(i)". This is the error I get:
"Unable to perform assignment because the indices on the left side are not compatible
with the size of the right side."
this is my code:
Fs = 360; % sample frequency of signals [Hz]
files = dir(fullfile("dataset/","*.mat"));
for i = 1:numel(files)
data(i) = load(files(i).name); % load signals
[b,a] = butter(3,[1 30]/(Fs/2),"bandpass"); % bandpass butterworth filter of third order with 1-30 Hz
y(i) = filtfilt(b,a,data(i).val); % apply the filter to all signals
end

Réponse acceptée

Karim
Karim le 17 Juin 2022
Hello, the problem is that you didn't initalize the variable "y". Hence you are trying to fit an array of 1x3600 into a single position (i.e. y(i) ).
See below for a quick fix:
files = dir(fullfile("dataset/","*.mat"));
Fs = 360; % sample frequency of signals [Hz]
[b,a] = butter(3,[1 30]/(Fs/2),"bandpass"); % bandpass butterworth filter of third order with 1-30 Hz
y = zeros(numel(files), 3600);
for i = 1:numel(files)
data(i) = load(fullfile("dataset/",files(i).name)); % load signals
y(i,:) = filtfilt(b,a,data(i).val); % apply the filter to all signals
end

Plus de réponses (0)

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by