Answer to Question #42133 in MatLAB | Mathematica | MathCAD | Maple for Roshanak

Question #42133
hi.... i have a problem in my code in matlab
i plot my diagram (ECG ) that i get info from database in this site: with
now i have ECG diagram in matlab but i want to find value and position of max and min OF ALL OF WAVE ....but with this code i found just one min and one max and i dont know how i can write a loop or for to search and find whole Min and Max of wave with their values in axes y ... in medical field i mean find R-peaks in EKG
thanks alot and my code

x = load ('C:\ekg\example_ecg.txt');
y = x ( : , 2);
h = plot (y );
x = get(h,'XData'); % Get the plotted data
y = get(h,'YData');
imin = find(min(y) == y);% Find the index of the min and max
imax = find(max(y) == y);

text(x(imin),y(imin),[' Min ',num2str(y(imin))],...
text(x(imax),y(imax),['Max ',num2str(y(imax))],...
Expert's answer
If you need to get extrema on the y variable, you can do smth like following.

deriv = diff(y)./x(1:end-1) % numerical derivation, function diff generates array which is one element shorter than initial one.

for i = 2:length(deriv)
if deriv(i-1)*deriv(i) < 0 % i.e. signs are different,
 fprintf(1, 'Extremum in point (%f, %f)\n', x(i), y(i))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!


Assignment Expert
20.05.14, 16:18

General way is the following: one can use fft to obtain Fourier spectrum of the signal or wavedec to obtain the wavelet harmonics. If you know what noise should be filtered, you remove corresponding harmonics. For example, if all ECG data has harmonics not larger than F0, ampltitudes of all harmonics larger than F0 should be set in 0. Then one makes inverse transform of the spectrum with dropped noise harmonics and obtain filtered signal. 

20.05.14, 10:42

how can i remove noise on my ECG diagram in matlab
with wavedec function or ?
and how?

Assignment Expert
13.05.14, 15:45

If we understand your first question right, the following method can be helpful. For example, one has 
>> a = [2.3 5.8 1.1 22.53 5.1];
and we need to find all points in the interval (5, 6). We can create the logical array 
>> inds = a > 4 & a < 6
inds =
     0     1     0     0     1
which contains ones on positions of the needed values. Now 
>> a(inds)
ans =
    5.8000    5.1000

If a is array of maximal values found in ECG diagram, you can sort them in the ascending order
>> b = sort(a)
b =
    1.1000    2.3000    5.1000    5.8000   22.530
and take corresponding values:
>> b(1) % minimal value
ans =
>> b(end) % maximal value
ans =
>> b(end - 1) % second maximal value
ans =


12.05.14, 15:05

hi again
Respectfully i have another question which is related to Previous Que...
now i have Coordinate of every points in my diagram ( my diagram is look like a ECG diagram)
now in your opinion with these info how can i find specific point or better than specific line in my diagram ???
if you cannt explain my problem please help me that how to find the first maximum relative after all of min absolute in matlab ....

Assignment Expert
12.05.14, 14:30

Dear Roshanak.
You're welcome. We are glad to be helpful. If you really liked our service please press like-button beside answer field. Thank you!  

10.05.14, 16:13

it works.....thankssssssssssssssssss aloooooot ...... really really really thanks

Leave a comment

Ask Your question

New on Blog