hi! I need help to check my function.

4 visualizzazioni (ultimi 30 giorni)
Anthony Fuentes
Anthony Fuentes il 21 Nov 2016
Commentato: Image Analyst il 22 Nov 2016
Hi! I need help with my function i MATLAB CODE, I try to find the maximum peaks of my data, but my function search all the maximums (locals and absolutes), but I need only the peaks in a electrocardiogram data. this is the problem instructions: Write a function in Matlab that allows you to find the maximum peaks in a data series. The input data are 2 vectors that contain the abscissa and ordinate of the data at which the maximums are to be found. The output is 2 vectors that contain the abscissa and ordinates of the maximum peaks in the data entry. To find the peaks its function must "stop" at each data point and check if it is larger than its neighbors on both sides and thus decide if Is a maximum, in which case you should save it as "peak" along with the abscissa in which it happened. Note that the endpoints only have neighbor to one side, omit these points in your analysis. Identify the R peaks throughout the data and generate a graph
My function:
function [vabs,pico]=picosmax(x,y)
lx=length(x);
v=0;
for kx=2:lx-1;
if y(kx)>y(kx-1) && y(kx)>y(kx+1)
v=v+1;
vabs(v)=x(kx);
pico(v)=y(kx);
end
end
MY PROGRAM:
addpath('C:\Users\Anthony\Desktop\Proyecto #4')
expdata = load ('cardio.txt');
x = expdata(:,1);
y = expdata(:,2);
figure; plot(x,y,'r-');
xlabel('time [s]'); ylabel('voltage[mV]')
figure; plot(x,y,'r-');
xlabel('time [s]'); ylabel('voltage[mV]')
xlim([868 888]);
[vabs,pico]=picosmax(x,y);
figure; % HERE IS THE PROBLEM, THE FIGURE SHOWS ME a lot of points(local maximas).
plot(x,y,vabs,pico,'-b'); hold on
plot( vabs,pico,'go', 'MarkerSize',10,'MarkerEdgeColor','r', 'MarkerFaceColor','g');
hold off
xlabel('Year')
ylabel('Number')
xlim([868 888])
IF YOU CAN HELP ME! THANKS A LOT!

Risposte (1)

Image Analyst
Image Analyst il 21 Nov 2016
Have you considered using findpeaks() in the Signal Processing Toolbox? It has lots of options to control which peaks get chosen or ignored. It's worth spending time studying.
  2 Commenti
Anthony Fuentes
Anthony Fuentes il 22 Nov 2016
I can't use that. I need to create the function that receive two vectors, one with the x-values and other with y-values, so then the proffesor don't give me points, if I use it. Thanks
Image Analyst
Image Analyst il 22 Nov 2016
Alternate ways of identifying peaks include imdilate() and imregionalmax(). Can you use either of those functions? I've tagged your post as homework for you.

Accedi per commentare.

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by