I posted this question on dsp.stackexchange and was informed that this is more relevant for stackoverflow, since this is primarily a programming issue:
I am trying to write code that allows me to change the phase of a signal in the frequency domain. However, my conclusion is not entirely correct, so something must be wrong. For a simple example, suppose we have the function y = sin (2 * pi * t) and want to implement the -pi / 2 phase shift. My code is 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 graphs look OK, except for the final graph, which looks like this:

, . - , , , ! , Y = Y.*exp(-i*2*pi*f*pi/2);, , .