Apply a filter to a dataset of ecg signals

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

采纳的回答

Karim
Karim 2022-6-17
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Filter Analysis 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by