简体   繁体   English

如何对正弦波进行相移-MATLAB?

[英]How to phase shift a sinusoidal wave- MATLAB?

I want to phase shift a sinusoidal wave as shown below. 我想对正弦波进行相移,如下所示。

在此处输入图片说明

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? 有人可以告诉我代码中的错误吗?

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. 只需在if语句中将==更改为> =即可。

The result is as follows. 结果如下。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM