Borrar filtros
Borrar filtros

Plotting points across the Sine Curve

7 visualizaciones (últimos 30 días)
Osita Onyejekwe
Osita Onyejekwe el 2 de Nov. de 2016
Comentada: Osita Onyejekwe el 3 de Nov. de 2016
I need help with my plot. I have points going across the sine function (zero-crossing). May someone please help me have different symbols for the symbols on the zero line. Say one symbol for the point on the zero-line on your way down. And another symbol for the point on your zero-line on your way up. Thank you! I am not interested in the peaks here. Thanks !
Here is the code. I know you will have to manipulate the code in some way to distinguish the negative direction going onto the zero line and the positive direction going onto the zero line.
x = 1:2000;
X = x;
J = 1;
Fs = 1999;
N = J*Fs;
t = 0: 1/Fs : J;
Fn = 5; % this control the number of cycles/periods
deltaJ = 0.0020;
deltax = 1;
y_sine_25HZ = sin(Fn*2*pi*t);
y = y_sine_25HZ ;
plot(x,y, 'k.')
drvY = gradient(y); % First Derivative Using Gradient
secondDrvY = gradient(drvY); % Second Derivative Using Gradient
indices = [find(secondDrvY(2:end).*secondDrvY(1:end-1)<0) find(abs(secondDrvY)<1e-15)]; % you are dealing with a discrete function here so the second derivative may not be exactly at zero
x_indices = t(indices);
dy=[0 sign(diff(y))]; % First derivative
locdn = find((diff(dy))== 2); % location down (second derivative)
locup = find((diff(dy))==-2);
plot(t,y)
ylim([-1.05 1.05])
hold on
scatter(t(locup)',y(locup)',30,'r','*')
scatter(t(locdn)',y(locdn)',30,'g','d','filled')
% plot(t(zx), y(zx), 'x')
plot(t,y, 'k.', t(indices), zeros(1,length(indices)), 'd', 'MarkerSize', 10, 'MarkerFaceColor', 'r')
plot(t, secondDrvY, 'r')
plot(t, drvY, 'b')
legend('Signal', 'Approximate Zero-Crossings')
hold off
grid

Respuesta aceptada

Thorsten
Thorsten el 3 de Nov. de 2016
plot(t, y)
hold on
ind = find(diff(y>0)<0);
plot(t(ind), y(ind), 'ko')
ind = find(diff(y>0)>0);
plot(t(ind), y(ind), 'ro')
  1 comentario
Osita Onyejekwe
Osita Onyejekwe el 3 de Nov. de 2016
is there a way to do this using the gradient and indices I already have in my plots, instead of the diff, thank you

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Simulink en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by