Segmented Sinewave
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi How Can i define a periodic signal like a segmented sine wave but with different amplitudes for segments ? Thanks.
0 comentarios
Respuestas (4)
Matt Tearle
el 16 de Feb. de 2011
Something like this?
p = 3;
t = linspace(0,10*p,201);
tseg = p*[0 1 4 5:9];
n = length(tseg)-1;
y = sin(2*pi*t);
A = randi(10,n,1)
for k = 1:n
idx = (t>tseg(k)) & (t<tseg(k+1));
y(idx) = A(k)*y(idx);
end
plot(t,y,tseg,tseg*0,'o')
0 comentarios
Jiro Doke
el 22 de Feb. de 2011
Okay, I'm still not entirely sure what you mean, but based on your response to one of the questions, it seems like you just want to discretize your sine wave.
If you just want to create a plot:
% 20 segments
t = linspace(0, 2*pi, 20);
y = sin(t);
stairs(t, y)
If you want coordinates for the "segmented" sine wave:
t2 = reshape([t;t], 1, []);
t2 = t2(2:end);
y2 = reshape([y;y], 1, []);
y2 = y2(1:end-1);
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!