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)')