# How to normalize curves with multiple peaks such that each peak will be 1 and each valley will be 0?

24 vues (au cours des 30 derniers jours)
Haguy Wolfenson le 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.
##### 2 commentairesAfficher AucuneMasquer Aucune
dpb le 20 Jan 2019
Only thing comes to mind would be to find each max/min pair and compute the necessary factor for those positions and then interpolate that scaling factor between each.
Providing an example data set would probably be beneficial.
Haguy Wolfenson le 20 Jan 2019
Thanks. That's what I was thinking. Is there a specific function for that?
This would be an example for a data set:
7.758833
9.813105
11.43802
10.68728
6.67001
0.737689
-4.47406
-6.98998
-6.52002
-4.11176
-1.15441
1.4053
3.232571
4.339376
4.729456
4.145157
2.181519
-1.10699
-4.71235
-7.04357
-6.92214
-4.30292
-0.38969
2.694517
2.948959
0.215726
-2.97796
-2.9788
1.951206
9.78937
15.93909
16.79721
12.67508
7.168603
3.742826
3.560238
6.438025
12.06834
18.94483
23.36877
21.61921
13.23558
1.492308
-8.82432
-13.8726
-12.363

Connectez-vous pour commenter.

### Réponse acceptée

dpb le 20 Jan 2019
Modifié(e) : dpb le 28 Août 2020
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
hLy=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
hLy(2)=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.
##### 6 commentairesAfficher 4 commentaires plus anciensMasquer 4 commentaires plus anciens
xiaoxiaoliu xiaoxiaoliu le 29 Août 2020
This is the image from which your code runs，Thank you very much for your code.
xiaoxiaoliu xiaoxiaoliu le 7 Sep 2020
I found a formula for this solution, but I don't know how to program it.
%y is original data，max（i）is Local maximum; min(i) is Local minimum.
But I do not know how to write this program, I hope you can help me, thank you very much.

Connectez-vous pour commenter.

### Plus de réponses (2)

Sargondjani le 20 Jan 2019
Yeah, you would have to calculate a scaling factor for each peak/trough. In one dimension you can then use the scaling factor for each interval. In multiple dimensions you would have to interpolate the scaling factor.
##### 1 commentaireAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens
dpb le 20 Jan 2019
That would be discontinuous tho, between the sections excepting in very unusual circumstances.

Connectez-vous pour commenter.

xiaoxiaoliu xiaoxiaoliu le 28 Août 2020
How to normalize curves with multiple peaks such that each peak will be 1 and each valley will be -1？
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Descriptive Statistics dans Help Center et File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by