Signal phase change in the frequency domain

I want to change the phase of the signal in the frequency domain. so I generated a cosine test signal to test the code:

ycheck = cos(2*pi*t);

when I want to shift the phase around pi / 4, I execute fft on the signal, breaking it in magnitude and phase and subtracting pi / 4 from it.

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

Deriving the result, it seems that only the signal amplitude was reduced, but the phase shift did not occur. I did a little research on the forum and found this post Change phase of signal in frequency domain (MatLab) . So I generated another test case using the following:

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

when I do a phase shift with this signal, it gives the desired result. Unfortunately, I cannot post snapshots :(, so I'm trying to describe (the code is attached so you can execute it): only ifft of the term imagensing shifts correctly. Ifft of standard cosine only decreases in amplitude. I do not quite understand what the problem is.

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 a phase shift in the frequency domain to music signals, or is there another (perhaps 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)')
+4
source share
1

!

, :

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

, phi, cosine x:

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

..

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

, 1i*phi 1i*phi . phi = -pi/4.

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

(, ). .

, - . DFT (FFT), . phi DFT phi .

, , ,

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
+6

Source: https://habr.com/ru/post/1607442/


All Articles