# 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:http://www.physionet.org/ 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))],...

'VerticalAlignment','middle',...

'HorizontalAlignment','left',...

'FontSize',7)

text(x(imax),y(imax),['Max ',num2str(y(imax))],...

'VerticalAlignment','bottom',...

'HorizontalAlignment','right',...

'FontSize',7)

i plot my diagram (ECG ) that i get info from database in this site:http://www.physionet.org/ 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))],...

'VerticalAlignment','middle',...

'HorizontalAlignment','left',...

'FontSize',7)

text(x(imax),y(imax),['Max ',num2str(y(imax))],...

'VerticalAlignment','bottom',...

'HorizontalAlignment','right',...

'FontSize',7)

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))

end

end

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))

end

end

Need a fast expert's response?

Submit orderand get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

## Comments

Assignment Expert20.05.14, 16:18General 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.

roshanak20.05.14, 10:42hi

how can i remove noise on my ECG diagram in matlab

with wavedec function or ?

and how?

thanks

Assignment Expert13.05.14, 15:45If 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 =

1.1000

>> b(end) % maximal value

ans =

22.5300

>> b(end - 1) % second maximal value

ans =

5.8000

etc.

Roshanak12.05.14, 15:05hi 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 ....

thanks

Assignment Expert12.05.14, 14:30Dear 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!

Roshanak10.05.14, 16:13it works.....thankssssssssssssssssss aloooooot ...... really really really thanks

## Leave a comment