Brace indexing is not supported for variables of this type.

reference_data=readtable('reference_150ohmn.csv');

2 Comments

i is defined in this code as a scalar numeric loop iterator:
for i=1:1:size(reference_time,1)
..
if isnumeric(i{1}) || ischar(i{1}) || islogical(i{1}) || isstruct(i{1})
.. % ^^^ ^^^ ^^^ ^^^
end
end
What do you expect curly brace indexing into a scalar numeric to achieve?
That wasn't supposed to be there, I had forgot to delete it because it didn't work

Sign in to comment.

 Accepted Answer

The problem is immediately apparent on viewing the contents —
ViewContents = readcell('https://www.mathworks.com/matlabcentral/answers/uploaded_files/594720/reference_150ohmn.csv')
ViewContents = 10017×2 cell array
{'Model' } {'MDO3024' } {'Firmware Version' } {[ 1.1400]} {'Waveform Type' } {'ANALOG' } {'Point Format' } {'Y' } {'Horizontal Units' } {'s' } {'Horizontal Scale' } {[ 1]} {'Horizontal Delay' } {[ 0]} {'Sample Interval' } {[ 1.0000e-03]} {'Record Length' } {[ 10000]} {'Gating' } {'0.0% to 100.0%'} {'Probe Attenuation'} {[ 1]} {'Vertical Units' } {'V' } {'Vertical Offset' } {[ 0]} {'Vertical Scale' } {[ 0.0500]} {'Vertical Position'} {[ 5]} {'Label' } {1×1 missing }
Try this instead: —
reference_data=readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/594720/reference_150ohmn.csv', 'HeaderLines',16);
reference_data.Properties.VariableNames = {'TIME','REF1'};
reference_time=reference_data.TIME;
reference_voltage=reference_data.REF1;
Ts = mean(diff(reference_time))
Ts = 1.0000e-03
Fs = 1/Ts
Fs = 1.0000e+03
% % % % % % % % THE COMMENTED-OUT SECTION IS NOT NECESSARY, SO DELETE IT —
% x = zeros(1, 10000);
% for i=1:size(reference_time,1)
% reference_time_double=str2double(cell2mat(reference_time(i)))
% end
% reference_time_double=reference_time_double+5;
% x1 = zeros(1, 10000);
% for i=1:1:size(reference_time,1)
% for reference_voltage_double=str2double(cell2mat(reference_voltage(i)))
% end
% if isnumeric(i{1}) || ischar(i{1}) || islogical(i{1}) || isstruct(i{1})
% x1(i)=1:1:size(reference_time,1);
% end
% end
filterred_reference=bandpass(reference_voltage,[0.51,59],Fs); % bandpass filtering
notch_frequencies=[58 61];
Sig_notch_reference=bandstop(filterred_reference,notch_frequencies,Fs); % notch filtering
f1=figure('units','normalized','outerposition',[0 0 1 1]);
subplot(2,1,1)
plot(reference_time,reference_voltage,'k','LineWidth',1)
grid on
title('Reference Electrode, before filtering')
set(gca,'FontSize',20);
subplot(2,1,2)
plot(reference_time,Sig_notch_reference,'k','LineWidth',1)
title('Reference Electrode, after filtering')
grid on
set(gca,'FontSize',20);
The filtering obviously needs work. Since I have no idea what you want to do, I will leave that to you.
I would apply the 60 Hz notch (bandstop) filter first, then use a bandpass filter with a bandwidth of 1 Hz to 100 Hz to filter the EKG. That willl remove the baseline wander and any remaining high-frequency noise without removing necessary parts of the EKG trace itself.
.

4 Comments

I tried rewriting this as the code and received this error:
Error in ecg150ohm (line 11)
filterred_reference=bandpassFilter(reference_voltage,[0.51,59],Fs); % bandpass filtering
and this is my line 11:
filterred_reference=bandpassFilter(reference_voltage,[0.51,59],Fs); % bandpass filtering
I cannot use the filter code in your post because you did not provide those functions. I am using the available Signal Processing Toolbox functions instead.
Wiiith a few minor changes —
reference_data=readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/594720/reference_150ohmn.csv', 'HeaderLines',16);
reference_data.Properties.VariableNames = {'TIME','REF1'};
reference_time=reference_data.TIME;
reference_voltage=reference_data.REF1;
Ts = mean(diff(reference_time))
Ts = 1.0000e-03
Fs = 1/Ts
Fs = 1.0000e+03
% % % % % % % % THE COMMENTED-OUT SECTION IS NOT NECESSARY, SO DELETE IT —
% x = zeros(1, 10000);
% for i=1:size(reference_time,1)
% reference_time_double=str2double(cell2mat(reference_time(i)))
% end
% reference_time_double=reference_time_double+5;
% x1 = zeros(1, 10000);
% for i=1:1:size(reference_time,1)
% for reference_voltage_double=str2double(cell2mat(reference_voltage(i)))
% end
% if isnumeric(i{1}) || ischar(i{1}) || islogical(i{1}) || isstruct(i{1})
% x1(i)=1:1:size(reference_time,1);
% end
% end
Fn = Fs/2;
L = numel(reference_time)
L = 10000
nfft = 2^nextpow2(L);
FTs = fft(reference_voltage-mean(reference_voltage),nfft)/L;
Fv = linspace(0, 1, nfft/2 + 1)*Fn;
Iv = 1:numel(Fv);
figure
plot(Fv, abs(FTs(Iv))*2)
grid
xlim([0 Fn])
title('Fourier Transform (Full Spectrum)')
xlabel('Frequency (Hz)')
ylabel('Amplitude (V)')
figure
plot(Fv, abs(FTs(Iv))*2)
grid
xlim([0 100])
title('Fourier Transform (0 - 100 Hz)')
xlabel('Frequency (Hz)')
ylabel('Amplitude (V)')
filterred_reference=bandpass(reference_voltage,[1 100],Fs, 'ImpulseResponse','iir'); % bandpass filtering
notch_frequencies=[58 61];
Sig_notch_reference=bandstop(filterred_reference,notch_frequencies,Fs, 'ImpulseResponse','iir'); % notch filtering
f1=figure('units','normalized','outerposition',[0 0 1 1]);
subplot(2,1,1)
plot(reference_time,reference_voltage,'k','LineWidth',1)
grid on
title('Reference Electrode, before filtering')
set(gca,'FontSize',20);
subplot(2,1,2)
plot(reference_time,Sig_notch_reference,'k','LineWidth',1)
title('Reference Electrode, after filtering')
grid on
set(gca,'FontSize',20);
sgf_filtered_reference = sgolayfilt(reference_voltage, 3, 61);
figure
plot(reference_time, sgf_filtered_reference)
grid
title('Savitzky-Golay Filtered Signal')
xlabel('Time')
ylabel('Amplitude')
sgf_filtered_reference_2 = bandpass(sgf_filtered_reference,[2.5 97.5],Fs, 'ImpulseResponse','iir'); % bandpass filtering
sgf_filtered_reference_2 = bandstop(sgf_filtered_reference_2,[49 51],Fs, 'ImpulseResponse','iir'); % notch filtering
figure
plot(reference_time, sgf_filtered_reference_2)
grid
title('Savitzky-Golay & Bandpass & Notch Filtered Signal')
xlabel('Time')
ylabel('Amplitude')
The signal exhibits broadband noise (as the Fourier transform plot demonstrates), and the only effective way to deal with that is with a Savitzky-Golay filter (or wavelet denoising). Combined with the bandpass and bandstop filters, that provides a reasonably decent result, although still not optimal (at least in my opinion). Experiment with the sgolayfilt parameters and the bandpass frequencies to see if you can improve on the result. This is the best I can do.
this helps a lot, thank you !
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

Sign in to comment.

More Answers (0)

Categories

Tags

Asked:

Joy
on 23 Apr 2021

Edited:

Joy
on 28 Apr 2021

Community Treasure Hunt

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

Start Hunting!