How can I plot slope including maximum peaks?

Hello, How can I plot slope including peaks point? It should look like exp. I tried envelope but It does not work for my code.
Thank you.

 Respuesta aceptada

Star Strider
Star Strider el 13 de Dic. de 2017
Editada: Star Strider el 13 de Dic. de 2017
If you have the Signal Processing Toolbox, use the findpeaks function to define the peaks and their locations. You can then use those values directly in your exponential regression.
EDIT
Try this:
y = [12 14 2 8 9 4 6 7 9 5 6];
x = 1:length(y);
ym = mean(y);
yz = y - ym; % Create Symmetry About Mean
[pospks, poslocs] = findpeaks(yz); % Positive Peaks & Locations
[negpks, neglocs] = findpeaks(-yz); % Negative Peaks & Locations
pkvct = [pospks negpks]; % Combine In One Vector FOr Sorting
[locs,idx] = sort([poslocs neglocs]); % Sort
pks = pkvct(idx);
objfcn = @(b,x) b(1).*exp(b(2).*x); % Exponential Objective Function
[B,resnorm] = fminsearch(@(b) norm(pks - objfcn(b,locs)), rand(2,1)); % Fit Data (EStimate Parameters)
figure(1)
plot(x, y, '-g')
hold on
% plot(locs, pks+ym, 'pg')
plot(locs, objfcn(B,locs)+ym, '-r')
hold off
text(5, 13, sprintf('y(x) = %.3f + e^{%.3f\\cdotx} + %.3f', B, ym))

2 comentarios

Ezgi Ertunç
Ezgi Ertunç el 14 de Dic. de 2017
Thank you for answer. My graph is changing when I run the Matlab.
Star Strider
Star Strider el 14 de Dic. de 2017
My pleasure.
If my Answer helped you solve your problem, please Accept it!

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 13 de Dic. de 2017
Why would you try envelope()? diff() would give the slope
slopes = diff(y)

Etiquetas

Preguntada:

el 13 de Dic. de 2017

Comentada:

el 14 de Dic. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by