0

I want to phase shift a sinusoidal wave as shown below.

enter image description here

What is happening here is that a phase shift occurs at the point of the red line. So, instead of following its natural path(dotted lines), it begins to follow the shifted path(dashed line).

I have tried to code it as follows.

clear;

t =(0:10000)/10000';

for ii = 1:length(t)

 x(ii)=exp(i*2*100*t(ii));

   if ii == 235      % point at which the phase shift occurs

        x(ii) = x(ii)*exp(-i*(pi/4));

   end

 end
 plot(t,real(x));

Can someone tell me the mistake in my code?

nashynash
  • 375
  • 2
  • 19

1 Answers1

1
clear;

t =(0:1000)/10000';

for ii = 1:length(t)

 x(ii)=exp(i*2*100*t(ii));

   if ii >= 235      % point at which the phase shift occurs

        x(ii) = x(ii)*exp(i*(pi/4));

   end

 end
 plot(t,real(x));

Just change == as >= in if statement.

The result is as follows.

enter image description here

KKS
  • 1,389
  • 1
  • 14
  • 33
  • I changed one more thing, exp(-i*(pi/4)) as exp(i*(pi/4)) to make result more similar to your picture. – KKS Mar 28 '16 at 07:41