Generate sine wave with varying phase

Hello, I would like to have 2 sinewaves, the second sine wave should be in phase with the first for half of its total time and must be out of phase by 30° for the rest of the time. Is there a method to generate this?
Thanks in advance.

 Accepted Answer

One approach:
t = linspace(0, 2, 500);
f = 10;
s(1,:) = sin(2*pi*f*t/t(end));
s(2,:) = [sin(2*pi*f*t(1:numel(t)/2)/t(end)) sin(2*pi*f*t((numel(t)/2+1):end)/t(end) + 30*pi/180)];
figure
plot(t, s)
grid
Experiment to get the result you want.
And I hope this is not homework.

3 Comments

Perfect! This is exactly what I was looking for. This is not a homework problem! This is a part of a research that I am working on. Thanks!
As always, my pleasure!
Good luck with your research!
Thank you!

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Asked:

on 26 Sep 2018

Commented:

on 26 Sep 2018

Community Treasure Hunt

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

Start Hunting!