所以我有一个简单的程序,我想转移一个简单的正弦函数pi / 2。现在我知道通过插入偏置(即A * sin(2 * pi *频率+偏置))非常容易。但是这个程序是测试理论的简单方法。我需要移动复杂的磁数据,但是移位是频率相关的。所以要弄清楚如何做到这一点我只是想通过设置移位来移动这个sin波,但我想在频域中进行。虽然下面的代码没有显示任何错误,但它确实没有正确地移动数据并影响幅度。代码如下。谢谢!
clear all
time = 1:0.01:2*pi; %Create time vector
mag = sin(2*pi*time);
Y = fft(mag); %transform
Pnewr = pi/2;
%t = angle(mag);
t = imag(Y);
%t_fin = t-Pnewr; %Subtract the pahse delay from the original phase vector
R=real(Y);
I=t;
k = I./R
Phi = tan(k);
PhiFinal = Phi-Pnewr;
PhiFinal = PhiFinal'
IFinal = R * atan(PhiFinal);
spec=complex(R,IFinal);
Finalspec = ifft(spec); %Invert the transform
Final = Finalspec;
plot(time,mag);
hold on
plot(time,Final,'r')
grid on
答案 0 :(得分:0)
一方面,你没有正确地重新组合想象和真实的组件,因为
PhiFinal = PhiFinal'
IFinal = R * atan(PhiFinal);
实际上是点积,而不是元素乘积的元素。一般来说,看起来你并没有正确使用复杂的关系。以下内容产生干净的相移:
time = 1:0.01:2*pi;
mag = sin(2*pi*time);
Y = fft(mag); %transform
Pnewr = pi/2;
R = real(Y);
I = imag(Y);
It = abs(Y);
% It = sqrt(I.^2 + R.^2);
Phi= angle(Y); % <-- using matlab function, equivalent to `Phi = atan2(I, R);`
k = I./R;
Phi0 = atan(k);
figure, subplot(121), plot(Phi0,Phi,'.'), xlabel('Phi from tan'), ylabel('Phi from ''angle'''), grid on, axis('tight')
PhiFinal = Phi-Pnewr; % <-- phase shift
IFinal = It .* sin(PhiFinal);
RFinal = It .* cos(PhiFinal);
spec= RFinal + 1i*IFinal;
Final = ifft(spec); %Invert the transform
subplot(122)
plot(time,mag);
hold on
plot(time,real(Final),'r')
plot(time,imag(Final),'r:')
grid on
axis('tight')
legend('Initial','Final'),xlabel('t'), ylabel('I')
mag*mag' % <-- check that total power is conserved
Final*Final'
这些数字显示了使用tan
与matlab的angle
(使用atan2
)计算的相位,以及相移的结果(右侧面板):