改变频域信号的相位(MatLab) [英] Change phase of a signal in frequency domain (MatLab)

查看:1496
本文介绍了改变频域信号的相位(MatLab)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在dsp.stackexchange上发布了这个问题,并且被告知它与stackoverflow更相关,因为它主要是一个编程问题:

我试图写一个代码,它允许我改变频域信号的相位。但是,我的输出不完全正确,所以一定是错的。举一个简单的例子,假设我们有函数y = sin(2 * pi * t)并且想实现-pi / 2的相移。我的代码如下所示:

 清除所有
关闭所有

N = 64; %样本数量
fs = 10; %采样频率
ts = 1 / fs; %采样间隔
tmax =(N-1)* ts;
t = 0:ts:tmax;
y = sin(2 * pi * t);

figure
plot(t,y)

%我们做FT
f = -fs / 2:fs /(N-1): fs / 2的;
Y = fftshift(fft(y));

%幅度
figure
plot(f,abs(Y));

phase = angle(Y);

相谱

图(f,阶段)

Y = ifftshift(Y)

%尝试相移
Y = Y. * exp(-i * 2 * pi * f * pi / 2);

%逆FT
u = ifft(Y);

figure
plot(t,real(u))

除了最后的情节外,所有情节都看起来不错:





这看起来几乎正确,但并不完全。如果任何人都可以给我一些关于如何纠正我的代码,以解决这个问题的指针,我将不胜感激!我有一种感觉,我的错误与行 Y = Y. * exp(-i * 2 * pi * f * pi / 2); 有关,但是我我不知道如何解决这个问题。
解决方案

我不能真正进入傅里叶分析的细节(因为我没有真的知道他们),但我可以提供一个工作解决方案,提供一些提示:首先,你应该用虚构的术语来表达你的浪潮,例如:

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

更重要的是,您必须真正地转换阶段,而不要混淆整个频谱:

 %尝试相移
Y = abs(Y)。* exp(1i * angle(Y) -1i * PI / 4); %-pi / 4 shift

您应该注意,这个转换与频率无关,我猜是有道理的
最后你可以画出结果:

$ p $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ k')
持有
图(t,real(y),'r')

real(y)实际上是一个余弦函数,并且您以正弦开始,但是希望您能理解。
对于pi / 4 shift我得到了这样的东西(用红色开始,用黑色结束):


I posted this question on dsp.stackexchange, and was informed that it was more relevant for stackoverflow as it is primarily a programming question:

I am attempting to write a code which allows me to change the phase of a signal in the frequency domain. However, my output isn't exactly correct, so something must be wrong. For a simple example assume that we have the function y = sin(2*pi*t) and want to implement a phase shift of -pi/2. My code looks as follows:

clear all
close all

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

figure
plot(t,y)

% We do the FT
f = -fs/2:fs/(N-1):fs/2;
Y = fftshift(fft(y));

% Magnitude spectrum
figure
plot(f,abs(Y));

phase = angle(Y);

% Phase spectrum
figure
plot(f,phase)

Y = ifftshift(Y)

% Attempt at phase shift
Y = Y.*exp(-i*2*pi*f*pi/2);

% Inverse FT
u = ifft(Y);

figure
plot(t,real(u))

All plots look OK except for the final plot which looks as follows:

This looks almost correct but not quite. If anyone can give me some pointers as to how my code can be corrected in order to fix this, I would greatly appreciate it! I have a feeling my mistake has something to do with the line Y = Y.*exp(-i*2*pi*f*pi/2);, but I'm not sure how to fix it.

解决方案

I can't really get into the Fourier analysis details (because I do not really know them), but I can offer a working solution with some hints:

First of all, You should express Your wave in imaginary terms, i.e.:

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

And what's even more crucial, You have to truly shift only the phase, without messing with the whole spectrum:

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

You should note that the shift isn't related to frequency anymore, which I guess makes sense. Finally You can plot the results:

figure
plot(t,real(u),'k')
hold on
plot(t,real(y),'r')

real(y) is actually a cosine function, and You started with sine, but hopefully You get the idea. For pi/4 shift i got something like this (started with red, finished with black):

这篇关于改变频域信号的相位(MatLab)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆