简体   繁体   English

在频域中改变信号的相位

[英]Changing the phase of a signal in frequency domain

i want to change the phase of a signal in the frequency domain. 我想改变频域中信号的相位。 so i generated a cosine test signal to verify the code: 所以我生成了一个余弦测试信号来验证代码:

ycheck = cos(2*pi*t);

when i want to shift the phase about pi/4 i perform a fft on the signal split it in magnitude and phase and substract pi/4 from it. 当我想将相位移动到pi / 4时,我会对信号执行fft,将其分为幅度和相位,并从中减去pi / 4。

Ycheck = abs(Ycheck).*exp(1i*angle(Ycheck)-1i*pi/4); % -pi/4 shift

plotting the result it looks like only the amplitude of the signal was lowered, but no phase shift happened. 绘制结果,看起来只有信号的幅度降低,但没有发生相移。 i did a little research on the forum and found this post Change phase of a signal in frequency domain (MatLab) . 我在论坛上做了一些研究,发现这个帖子在频域(MatLab)中改变信号的相位 So i generated another testsignal using the following: 所以我使用以下方法生成了另一个testignal:

y = exp(1i*2*pi*t);

when i do the phase shift with this signal it gives the desired result. 当我用这个信号进行相移时,它会给出所需的结果。 sadly i can not post pictures :(, so i try to describe (the code is attached, so you can execute it): only the ifft of the imaginery term is shifted correctly. the ifft of the standard cosine is only lowered in amplitude. i dont quite get, whats the problem here. 遗憾的是我不能张贴图片:(,所以我试着描述(代码是附加的,所以你可以执行它):只有想象术语的ifft正确移动。标准余弦的ifft只降低幅度。我不明白,这里的问题是什么。

my question is, why does the phase shift work on signals expressed in an imaginary term and not on a regularly generated cosine? 我的问题是,为什么相移对假想项中表示的信号起作用而不是对常规生成的余弦表示? My plan is to apply this phase shift to real signals - can i apply the phase shift in frequency domain to eg music signals or is there another (maybe smarter) way? 我的计划是将这种相移应用于实际信号 - 我可以将频域中的相移应用于音乐信号,还是应用另一种(可能更智能)的方式?

My code is here: 我的代码在这里:

clear all;
close all;
clc;

N = 64; %number of samples
fs = 10; %sampling frequency
ts = 1/fs; %sample interval
tmax = (N-1)*ts;
t = 0:ts:tmax;
y = exp(1i*2*pi*t);
ycheck = cos(2*pi*t);

% plot test signals
figure
plot(t,y)
hold on
plot(t,ycheck,'r--')

% fft
Y = fft(y);
Ycheck = fft(ycheck);

% phase shift
Y = abs(Y).*exp(1i*angle(Y)-1i*pi/4); % -pi/4 shift
Ycheck = abs(Ycheck).*exp(1i*angle(Ycheck)-1i*pi/4); % -pi/4 shift

%ifft
u = ifft(Y);
ucheck = ifft(Ycheck);

% plot
figure
plot(t,real(u),'k')
hold on
plot(t,real(y),'r')
hold on
plot(t,real(ucheck),'g')
hold on
plot(t,ycheck,'b--')
legend('ifft(exp(1i*2*pi*t)) %-pi/4shift','real(cos(2*pi*t))','ifft(cos(2*pi*t)) %-pi/4 shift','cos(2*pi*t)')

Interesting question! 有趣的问题!

As you know, the cosine can be expressed as the sum of two imaginary exponentials: 如您所知,余弦可以表示为两个虚数指数的总和:

 cos(x) = ( exp(1i*x) + exp(-1i*x) ) / 2;

Changing the phase of the cosine means adding a number, say phi , to the cosine argument x : 改变余弦的相位意味着在余弦参数x添加一个数字,比如phi

 cos(x+phi) = ( exp(1i*(x+phi)) + exp(-1i*(x+phi)) ) / 2;

that is, 那是,

 cos(x+phi) = ( exp(1i*x + 1i*phi) + exp(-1i*x - 1i*phi) ) / 2;

Thus, you need to add 1i*phi in one of the exponents and subtract 1i*phi in the other. 因此,您需要在其中一个指数中添加1i*phi ,并在另一个中减去 1i*phi In your case phi = -pi/4 . 在你的情况下, phi = -pi/4 However, your line 不过,你的路线

Ycheck = abs(Ycheck).*exp(1i*angle(Ycheck)-1i*pi/4); % -pi/4 shift

adds the same term to both exponentials (actually, to all frequency components). 为两个指数添加相同的项(实际上,对所有频率成分)。 That is the problem. 那就是问题所在。

In an ordinary Fourier transform, the first exponential corresponds to positive frequency in the transformed domain, and the second to negative frequency. 在普通傅里叶变换中,第一指数对应于变换域中的正频率,第二指数对应于负频率。 But since you are doing a DFT (FFT), the negative frequencies get folded and appear in the upper part. 但是,由于您正在进行DFT(FFT),负频率会折叠并出现在上半部分。 So you need to add phi in the lower half of the DFT and subtract phi in the upper half . 所以你需要在DFT的下半部分添加phi并在上半部分减去phi

Assuming that the number of points of the DFT is even, as in your example, you just need to replace the line indicated above by 假设DFT的点数是偶数,如在您的示例中,您只需要替换上面指定的行

phi = -pi//4; %/ desired phase shift
ind = 1:numel(Ycheck)/2; %// lower half
Ycheck(ind) = abs(Ycheck(ind)).*exp(1i*angle(Ycheck(ind))+1i*phi); %// add 1i*phi
ind = numel(Ycheck)/2+1:numel(Ycheck); %// upper half
Ycheck(ind) = abs(Ycheck(ind)).*exp(1i*angle(Ycheck(ind))-1i*phi); %// subtract 1i*phi

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

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