Segmented Sinewave

Hi How Can i define a periodic signal like a segmented sine wave but with different amplitudes for segments ? Thanks.

답변 (4개)

Matt Tearle
Matt Tearle 2011년 2월 16일

0 개 추천

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')
Ali
Ali 2011년 2월 20일

0 개 추천

Thanks , that was very helpful , but what i am looking for is a segmented sine wave with different amplitudes for each step .

댓글 수: 5

Matt Tearle
Matt Tearle 2011년 2월 20일
OK, sorry, then I guess I don't understand what that means. Can you explain it or point me to a reference?
Ali
Ali 2011년 2월 20일
sure , what i mean periodic segmented signal like sine wave but with different amplitudes for each step , for example starts with amplitude of one stays one for one segment of time then goes to different value such as two ,stays two for one segment and continues like this.
Walter Roberson
Walter Roberson 2011년 2월 20일
Please clarify what a "segment" is for this purpose. Matt's code presented sets different amplitudes for segment boundaries that are delimited by time, which would seem to be what you want except that perhaps you need a slightly different way to determine the "segment" boundaries.
Jiro Doke
Jiro Doke 2011년 2월 21일
Ali, you use the word "segment" and "step". Do you mean for each "period" (when it goes through one cycle of sine wave)? In Matt's example, if you set p = 1, and set tseg = 0:9, you can change the amplitude for every period.
Ali
Ali 2011년 2월 22일
Sorry I might have used wrong terminology , what i meant by segment is to divide one period to n parts ,for each part out of n i will replace portion of sine wave with square pulse , its still periodic . exactly same as graphical method for integrating sine wave .

댓글을 달려면 로그인하십시오.

Jiro Doke
Jiro Doke 2011년 2월 22일

0 개 추천

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);
Ali
Ali 2011년 2월 23일

0 개 추천

Thanks jiro , it was very helpful , but i dont want it just as plot but signal because i will be doing some DSP operations on that signal.

댓글 수: 1

Jiro Doke
Jiro Doke 2011년 2월 23일
See the second block of code in my answer. Those are the coordinates of the segmented wave.

댓글을 달려면 로그인하십시오.

카테고리

질문:

Ali
2011년 2월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by