here the program for rr interval, pls any one check any say correct or wrong. if it wrong, correctio

Discussion in 'MATLAB' started by nethaji anandhavalli, Apr 17, 2010.

  1. clc;
    clear;
    y= load ('C:\Program Files\MATLAB71\work\ecg2.txt'); %load the original signal
    t=load('C:\Program Files\MATLAB71\work\final1.txt');
    WidthPoints=length(y)/40;
    disp (WidthPoints)% Change to match approx. # of points in your peaks
    SlopeThreshold=WidthPoints^-2;
    disp (SlopeThreshold)% Change to match approx. # of points in your peaks
    AmpThreshold=min(y)+0.05*(max(y)-min(y));
    smoothwidth=round(WidthPoints/2); % SmoothWidth should be roughly equal to 1/2 the peak width (in points)
    FitWidth=round(WidthPoints/2); % FitWidth should be roughly equal to 1/2 the peak widths(in points)
    if FitWidth<3,FitWidth=3;end
    PeakNumber=0;
    smoothwidth=round(smoothwidth);
    FitWidth=round(FitWidth);
    d=fastsmooth(deriv(y),smoothwidth);
    n=round(FitWidth/2+1);
    P=[0 0 0 0];
    vectorlength=length(y);
    pe=1;
    AmpTest=AmpThreshold;
    for j=smoothwidth:length(y)-smoothwidth,
    if sign(d(j)) > sign (d(j+1)), % Detects zero-crossing
    if d(j)-d(j+1) > SlopeThreshold*y(j), % if slope of derivative is larger than SlopeThreshold
    if y(j) > AmpTest, % if height of peak is larger than AmpThreshold
    for k=1:FitWidth, % Create sub-group of points near peak
    groupindex=j+k-n+1;
    if groupindex<1, groupindex=1;end
    if groupindex>vectorlength, groupindex=vectorlength;end
    xx(k)=y(groupindex);yy(k)=t(groupindex);
    end
    [coef,S,MU]=polyfit(xx,log(abs(yy)),2); % Fit parabola to log10 of sub-group with centering and scaling
    c1=coef(3);c2=coef(2);c3=coef(1);
    PeakX=-((MU(2).*c2/(2*c3))-MU(1)); % Compute peak position and height of fitted parabola
    PeakY=exp(c1-c3*(c2/(2*c3))^2);
    MeasuredWidth=norm(MU(2).*2.35703/(sqrt(2)*sqrt(-1*c3)));

    % if the peak is too narrow for least-squares technique to work
    % well, just use the max value of y in the sub-group of points near peak.
    if FitWidth<7,
    PeakY=max(yy);
    pindex=val2ind(yy,PeakY);
    PeakX=xx(pindex(1));
    end

    % Construct matrix P. One row for each peak
    % detected, containing the peak number, peak
    % position (x-value) and peak height (y-value).
    P(pe,:) = [round(pe) PeakX PeakY MeasuredWidth];
    pe=pe+1;
    end
    end
    end
    end
    val=200;
    [index,closestval]=val2ind(y,200)
    % Returns the index and the value of the element of vector x that is closest to val
    % If more than one element is equally close, returns vectors of indicies and values
    % Tom O'Haver () October 2006
    % Examples: If x=[1 2 4 3 5 9 6 4 5 3 1], then val2ind(x,6)=7 and val2ind(x,5.1)=[5 9]
    % [indices values]=val2ind(x,3.3) returns indices = [4 10] and values = [3 3]
    dif=abs(y-val);
    index=find((dif-min(dif))==0);
    closestval=y(index);
     
    nethaji anandhavalli, Apr 17, 2010
    #1
    1. Advertisements

  2. nethaji anandhavalli

    Mark Shore Guest

    Why on Earth would anyone want to try to debug Tom O'Haver's code for you, assuming that it even *needs* debugging? This is presumptuous behaviour - at best - on your part (and I'm being generous).
     
    Mark Shore, Apr 17, 2010
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.