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.
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). So i generated another testsignal using the following:
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.
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)')