Asked by Haguy Wolfenson
on 20 Jan 2019

Hello,

I am looking for a way to normalize curves with multiple peaks such that each local maximum and minimum will be set to 1 and 0 respectively, and that the values between the maxima and minima will be set accordingly.

Thanks,

Haguy.

Answer by dpb
on 20 Jan 2019

Edited by dpb
on 21 Jan 2019

Accepted Answer

If you mean 'builtin' already coded to do that, "No, I don't think so!" I've never seen it actually done before; don't think it's terribly common.

I don't have time to write full-blown code, but you should be able to follow along and write a function from a demo of the idea done at command line for the sample data--

y=x+abs(min(x)); % move whole trace to baseline first

findpeaks(y) % just to make the fancy plot

[pks,ipk]=findpeaks(y); % get the peaks, locations

[vlys,ivly]=findpeaks(-y); % and the valleys

vlys=-vlys; % back to correct sign of signal

hold on

plot(ivly,vlys-1,'^r','MarkerFaceColor','r');% add markers for the valleys just for fun

b=polyfit([ipk(1) ivly(1)],[1/pks(1) 0],1); % linear transformation peak-->1, valley-->0 first section

yhat=polyval(b,ipk(1):ivly(1)); % get the scale factor for the section

yhat=yhat.*y(ipk(1):ivly(1)).'; % and scale the actual data

yyaxis right % to plot the scaled on appropriate scale

plot((ipk(1):ivly(1)).',yhat,'k-'); % and plot that first section...

ylim([-0.2 1.6]) % just to make origins aline left/right axes...

polyfit([ivly(1) ipk(2)],[0 1/pks(2)],1) % now do the next section vly(1)-->0; pk(2)==>1

yhat=polyval(b,[ivly(1):ipk(2)]); % and rinse and repeat above pattern...

yhat=yhat.*y(ivly(1):ipk(2)).';

hold on

plot((ivly(1):ipk(2)).',yhat,'k-');

hLg=legend(hLy(1),'Normalized','Location','northwest');

Above yields inserted image; your mission, should you choose to accept it, is to take the above and turn it into the general function walking through the located peaks and valleys. You'll have to decide just what to do about the end sections where you don't have the alternate peak/valley to use to fully define the linear transformation...it's purely a guess as to what that scaling factor should

be as it is not known what the other extremum or its location would have been.

Answer by Sargondjani
on 20 Jan 2019

Opportunities for recent engineering grads.

Apply Today
## 2 Comments

## dpb (view profile)

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/440579-how-to-normalize-curves-with-multiple-peaks-such-that-each-peak-will-be-1-and-each-valley-will-be-0#comment_662275

## Haguy Wolfenson (view profile)

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/440579-how-to-normalize-curves-with-multiple-peaks-such-that-each-peak-will-be-1-and-each-valley-will-be-0#comment_662298

Sign in to comment.