How to calculate the small changes in a signal?
24 views (last 30 days)
I have an ECG signal and would like to know what minor amplitude changes I can recognize. The goal is to see if I'm able to get the resolution that's provided by the recording system or not. I use the gradient function to calculate the derivative and look at the minimum value to determine the resolution. I would like to know if this is the best approach to take or not. The signal is attached here. Any suggestions would be appreciated.
Fs = 1024; % sampling rate
Ft = gradient(data, 1/Fs)
min(Ft) % the smallest change in the signal's amplitude
Star Strider on 31 Aug 2022
Iam not certain what result you want, however to get the smallest amplitude change, using gradient on the original signal is likely not going to produce the result you want, since the minimum gradient is going to be the minimum of the entire record, likely returning the value of the deepest Q- or S-deflection. Taking the gradient of the abolute value instead may do what you want.
Try this —
LD = load(websave('A','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1112930/A.mat'));
data = LD.A;
Fs = 1024;
L = numel(data)
t = linspace(0, L-1, L)/Fs;
Ft = gradient(data, 1/Fs);
[minFt,idx] = min(abs(Ft)) % the smallest change in the signal's amplitude
minidx = find(Ft == min(abs(Ft)))
Ft2 = gradient(Ft); % Second Derivative
resolution = diff(data);
min_resolution = min(resolution(resolution>0))
plot(t, data, 'DisplayName','Data')
plot(t(minidx), data(minidx), '+r', 'DisplayName','Gradient = 0')
plot(t, Ft, 'DisplayName','Gradient')
That returns several values of a flat gradient, all representing inflection points in the EKG trace. Calculating the second derivative will allow the determination of the inflection points being a minimum, maximum, or saddle point. This may be helpful, however I am not certain what you want.
The minimum resolution appears to be equal to 1, however that likely needs to be calibrated with respect to the actual voltage values of the EKG (the R-deflection is normally about 1±0.2 mV) to be useful. It will likely be necessary to check the gain on the instrumentation.
More Answers (1)
dpb on 31 Aug 2022
Edited: dpb on 31 Aug 2022
We've elsewhere determined the data are recorded as signed 16-bit integers which span +/-32K which is a 64K range. A default double has approximately 15 decimal digits of precision (53 bits in the significand) so it can easily hold all the precision available from the instrument without any loss.
Given the number of possible inputs from the device is only the 64K unique values, any more than that number of unique values in a processed input signal will have come only as artifacts during the calculations as long as the calculations are on a per channel basis.