From: Frank on
Dear all,

I created 2 signals, one sinusoid and its shifted version. I performed FFT on both and tried to multiply the FFT of the original signal elementwise by a vector which contains the phase shift. However, I found that it is not equal to the FFT of the shifted version. Can anyone help?

Attached please find my code:

clear all;
%sample frequency = 1
w = 2*pi*0.17;%angular frequency
N = 256;%No. of data
n = 0:N-1;%time index
phi = 1;%phase
t = 0.1;%delay
s = cos(w*n+phi);%orignal time domain signal
s1 = cos(w*(n-t)+phi);%shifted version of the sinusoid
S = fft(s);%FFT of the sinusoid
S1 = fft(s1);%FFT of the shifted sinusoid
e = exp(-1i*2*pi/N*n*t);% vector contains phase shift
norm(S.*e-S1)%should be zero

Thanks.
From: Wayne King on
"Frank " <allinone_2003(a)yahoo.com.hk> wrote in message <hpkbtt$reg$1(a)fred.mathworks.com>...
> Dear all,
>
> I created 2 signals, one sinusoid and its shifted version. I performed FFT on both and tried to multiply the FFT of the original signal elementwise by a vector which contains the phase shift. However, I found that it is not equal to the FFT of the shifted version. Can anyone help?
>
> Attached please find my code:
>
> clear all;
> %sample frequency = 1
> w = 2*pi*0.17;%angular frequency
> N = 256;%No. of data
> n = 0:N-1;%time index
> phi = 1;%phase
> t = 0.1;%delay
> s = cos(w*n+phi);%orignal time domain signal
> s1 = cos(w*(n-t)+phi);%shifted version of the sinusoid
> S = fft(s);%FFT of the sinusoid
> S1 = fft(s1);%FFT of the shifted sinusoid
> e = exp(-1i*2*pi/N*n*t);% vector contains phase shift
> norm(S.*e-S1)%should be zero
>
> Thanks.

Hi Frank, I'm not sure why you're comparing norm(S.*e-S1).

n=0:95;
x = cos(pi/4*n);
delay=2;
y = cos(pi/4*(n-delay));
k=0:95;
% the DFT of y is exp(-1j*2*pi*k*delay/96)
phaseshift = exp(1j*2*pi*k*delay/96);
ydft = fft(y);
xdft = fft(x);
ydft=ydft.*phaseshift;
norm(xdft-ydft)
% 3.0397e-014
max( max(real(xdft)-real(ydft)), max(imag(xdft)-imag(ydft)))
% also on the order of 10^(-14)

y1 = ifft(ydft,'symmetric');
subplot(211);
plot(x);
subplot(212);
plot(y1);


Wayne
From: Frank on
Hi Wayne, Thanks for your reply.

However, if I try to set the delay to 0.12 instead of 2, norm(xdft-ydft) = 35.34, which is greater than zero by a lot. What can we do in this case?

Frank

"Wayne King" <wmkingty(a)gmail.com> wrote in message <hpkqq5$q1t$1(a)fred.mathworks.com>...
> "Frank " <allinone_2003(a)yahoo.com.hk> wrote in message <hpkbtt$reg$1(a)fred.mathworks.com>...
> > Dear all,
> >
> > I created 2 signals, one sinusoid and its shifted version. I performed FFT on both and tried to multiply the FFT of the original signal elementwise by a vector which contains the phase shift. However, I found that it is not equal to the FFT of the shifted version. Can anyone help?
> >
> > Attached please find my code:
> >
> > clear all;
> > %sample frequency = 1
> > w = 2*pi*0.17;%angular frequency
> > N = 256;%No. of data
> > n = 0:N-1;%time index
> > phi = 1;%phase
> > t = 0.1;%delay
> > s = cos(w*n+phi);%orignal time domain signal
> > s1 = cos(w*(n-t)+phi);%shifted version of the sinusoid
> > S = fft(s);%FFT of the sinusoid
> > S1 = fft(s1);%FFT of the shifted sinusoid
> > e = exp(-1i*2*pi/N*n*t);% vector contains phase shift
> > norm(S.*e-S1)%should be zero
> >
> > Thanks.
>
> Hi Frank, I'm not sure why you're comparing norm(S.*e-S1).
>
> n=0:95;
> x = cos(pi/4*n);
> delay=2;
> y = cos(pi/4*(n-delay));
> k=0:95;
> % the DFT of y is exp(-1j*2*pi*k*delay/96)
> phaseshift = exp(1j*2*pi*k*delay/96);
> ydft = fft(y);
> xdft = fft(x);
> ydft=ydft.*phaseshift;
> norm(xdft-ydft)
> % 3.0397e-014
> max( max(real(xdft)-real(ydft)), max(imag(xdft)-imag(ydft)))
> % also on the order of 10^(-14)
>
> y1 = ifft(ydft,'symmetric');
> subplot(211);
> plot(x);
> subplot(212);
> plot(y1);
>
>
> Wayne
From: Wayne King on
"Frank " <allinone_2003(a)yahoo.com.hk> wrote in message <hpm06e$q8k$1(a)fred.mathworks.com>...
> Hi Wayne, Thanks for your reply.
>
> However, if I try to set the delay to 0.12 instead of 2, norm(xdft-ydft) = 35.34, which is greater than zero by a lot. What can we do in this case?
>
> Frank
>
> "Wayne King" <wmkingty(a)gmail.com> wrote in message <hpkqq5$q1t$1(a)fred.mathworks.com>...
> > "Frank " <allinone_2003(a)yahoo.com.hk> wrote in message <hpkbtt$reg$1(a)fred.mathworks.com>...
> > > Dear all,
> > >
> > > I created 2 signals, one sinusoid and its shifted version. I performed FFT on both and tried to multiply the FFT of the original signal elementwise by a vector which contains the phase shift. However, I found that it is not equal to the FFT of the shifted version. Can anyone help?
> > >
> > > Attached please find my code:
> > >
> > > clear all;
> > > %sample frequency = 1
> > > w = 2*pi*0.17;%angular frequency
> > > N = 256;%No. of data
> > > n = 0:N-1;%time index
> > > phi = 1;%phase
> > > t = 0.1;%delay
> > > s = cos(w*n+phi);%orignal time domain signal
> > > s1 = cos(w*(n-t)+phi);%shifted version of the sinusoid
> > > S = fft(s);%FFT of the sinusoid
> > > S1 = fft(s1);%FFT of the shifted sinusoid
> > > e = exp(-1i*2*pi/N*n*t);% vector contains phase shift
> > > norm(S.*e-S1)%should be zero
> > >
> > > Thanks.
> >
> > Hi Frank, I'm not sure why you're comparing norm(S.*e-S1).
> >
> > n=0:95;
> > x = cos(pi/4*n);
> > delay=2;
> > y = cos(pi/4*(n-delay));
> > k=0:95;
> > % the DFT of y is exp(-1j*2*pi*k*delay/96)
> > phaseshift = exp(1j*2*pi*k*delay/96);
> > ydft = fft(y);
> > xdft = fft(x);
> > ydft=ydft.*phaseshift;
> > norm(xdft-ydft)
> > % 3.0397e-014
> > max( max(real(xdft)-real(ydft)), max(imag(xdft)-imag(ydft)))
> > % also on the order of 10^(-14)
> >
> > y1 = ifft(ydft,'symmetric');
> > subplot(211);
> > plot(x);
> > subplot(212);
> > plot(y1);
> >
> >
> > Wayne

Hi Frank, that's because you are attempting to deal with fractional delays. If your sampling rate is 1 and you try to delay a signal by 0.2, you have a fractional delay, a delay that is not an integer number of samples. Read up on fractional delay filters to see the adjustments you have to make in that case.
Wayne