Effacer les filtres
Effacer les filtres

Phase gradient in fft

27 vues (au cours des 30 derniers jours)
Jiayun Liu
Jiayun Liu le 8 Oct 2022
Commenté : Jiayun Liu le 16 Oct 2022
I recently found out that zero padding can affect the phase gradient of the Fourier transformed data. It seems that depending on the position of the signal, the phase gradient can be positive or negative as shown in the attached figure. I am not talking about the additional phase gradient due to a shift in time signal. Could someone please explain why that is so?
The following code is used
t = 0:1/40:10; t0 = -7;
y = sin(2*pi*10*(t+t0)).*exp(-(t+t0).^2);
fty = fft(y); fty(abs(fty)<1e-6) = 0;
theta = unwrap(angle(fty)); dt = t(2)-t(1);
ftx = (0:1:length(t)-1)*(1/dt)/length(t);
theta = unwrap(angle(fty));
subplot(2,2,1)
plot(t,y); title('Time signal')
subplot(2,2,3)
plot(ftx(1:floor(end/2)),theta(1:floor(end/2))); title('Phase of Fourier components')
t = 0:1/40:20; t0 = -7;
y = sin(2*pi*10*(t+t0)).*exp(-(t+t0).^2);
fty = fft(y); fty(abs(fty)<1e-6) = 0;
theta = unwrap(angle(fty)); dt = t(2)-t(1);
ftx = (0:1:length(t)-1)*(1/dt)/length(t);
theta = unwrap(angle(fty));
subplot(2,2,2)
plot(t,y); title('Time signal')
subplot(2,2,4)
plot(ftx(1:floor(end/2)),theta(1:floor(end/2))); title('Phase of Fourier components')
  2 commentaires
Paul
Paul le 8 Oct 2022
Can you post the code that produced those plots?
Jiayun Liu
Jiayun Liu le 9 Oct 2022
I will post the code as soon as I have access to them. The title of the bottom plots is supposed to be unwrapped phase. Sorry for that

Connectez-vous pour commenter.

Réponse acceptée

Paul
Paul le 8 Oct 2022
Modifié(e) : Paul le 9 Oct 2022
Hi Jiayun,
First of all, I don't see anything in the code that does "zero-padding." That term typically refers to augmenting a sequence with zeros prior to taking the FFT. But, the code in the Question is just taking more sample points of the underlying continuous-time signal, which isn't zero padding.
I pretty sure all you're seeing is the effect of
a) taking a finite number of samples of an infinitely long signal (i.e., a windowing effect), so we'd expect that the more samples taken the closer the DFT will be to samples of the CTFT, which is what I think you're expecting for the phase plots.
b) the code sets a lot of samples of the DFT to zero (fty(abs(fty)<1e-6) = 0;) which also loses all phase information for those points.
Start with an exact signal and its Fourier transform
syms t
t0 = -7;
x(t) = sin(2*sym(pi)*10*(t+t0))*exp(-(t+t0)^2);
xfunc = matlabFunction(x(t));
fplot(x(t),[0 10])
xlabel('t'); ylabel('x(t)')
syms w f
X(w) = (fourier(x(t),t,w));
X(f) = X(2*sym(pi)*f);
Xfunc = matlabFunction(X(f));
Plot the phase of the CTFT, both wrapped and unwrapped
fval = 0:.01:20;
figure
plot(fval,angle(Xfunc(fval)))
xlabel('f (Hz)'); ylabel('angle(X(f)) (rad)')
figure
plot(fval,unwrap(angle(Xfunc(fval))))
xlabel('f (Hz)'); ylabel('angle(X(f)) (rad)')
That funny business of zero phase at the edges is because X(f) numerically evaluates to zero at points near the ends, e.g.,
Xfunc(fval([1 2 end-1 end-2]))
ans = 1×4
0 0 0 0
Settting that issue aside, we see (exact?) linear phase as function of frequency.
Now, sample the signal from t = 0 to t =10 a sampling frequency of Ts = 1/40 and compute its DTFT with lots of frequency points
dt = 1/40;
df = 1/dt;
tval = 0:dt:10;
xval = xfunc(tval);
[h,w] = freqz(xval,1,8192);
figure
plot(w/pi*20,angle(h))
xlabel('f (Hz)'); ylabel('angle(XDTFT(f)) (rad)')
If you look carefully, it's apparent that the character of the phase is different for frequencies in small window 8 < f < 12, and frequencies outside that window. We can see this more easily after unwrapping, which reveals change in slope in the center of the graph.
figure
plot(w/pi*20,unwrap(angle(h)))
xlabel('f (Hz)'); ylabel('angle(XDTFT(f)) (rad)')
grid
xlim([5 15])
Instead of the DTFT, let's take the N-point DFT, where N is the number of samples.
N = numel(tval);
Xval1 = fft(xval,N);
fval1 = (0:(N-1))/N*df;
Plot the angle of the DFT samples on the phase plot of the DTFT
plot(w/pi*20,angle(h),fval1,angle(dt*Xval1),'o')
xlabel('f (Hz)'); ylabel('angle(XDTFT(f) XDFT(f)) (rad)')
xlim([0 20])
plot(w/pi*20,angle(h),fval1,angle(dt*Xval1),'o')
xlabel('f (Hz)'); ylabel('angle(XDTFT(f) XDFT(f)) (rad)')
xlim([8 12])
As must be the case, the angle of the DFT samples are samples of the the angle of the DTFT, but the effect of the time-domain windowing and sampling on the phase of the DTFT makes the frequency-domain samples of the DFT take on an unexpected shape.
I suggest going through the exact same code as above, but with
t = 0:dt:20;
to see how taking more samples of the continuous-time signal impacts the analysis. It should yield a DTFT that closer to the CTFT, and therefore the DFT samples may be closer to what may be expected.
  20 commentaires
Paul
Paul le 15 Oct 2022
Modifié(e) : Paul le 15 Oct 2022
Yes, the example(s) showed that it is possible that the "phase gradient" of the DFTs are different for two seemingly the same signals for the reasons that I've already explained above: where the frequency samples of the DFTs end up relative to the DTFTs, and that the phase of the sum of complex numbers can be very different than the phase of either if both numbers have similar-ish magnitudes, even if they are very small. Here's another example that illustrates the second point. Since we are now talking about measurements, let's just add some noise to the signal that we've been talking about.
t = 0:1/40:10; t0 = -7;
y1 = sin(2*pi*10*(t+t0)).*exp(-(t+t0).^2);
fty1 = fft(y1);
theta1 = angle(fty1);
dt = t(2)-t(1);
ftx = (0:1:length(theta1)-1)*(1/dt)/length(theta1);
Add some noise. This noise is quite small relative to the peak of y1, but is larger than the tails of y1. Is y2 "seemingly the same" as y1? Anyway
rng(100)
y2 = y1 + 1e-4*rand(size(y1));
fty2 = fft(y2);
theta2 = angle(fty2);
figure
subplot(221)
plot(t,y1)
subplot(223)
plot(ftx,unwrap(theta1));xlim([0 20]),ylim([-20 60])
subplot(222)
plot(t,y2);
subplot(224);
plot(ftx,unwrap(theta2));xlim([0 20]),ylim([-20 60])
The unwrapped phases of y2 and y1 aren't the same, but at least kind of have the same trend. But, in the center of the frequency range where the magnitude of the DFTs are large, the phase is the same, because the DFT of the noise is small amplitude at all frequencies.
figure
plot(ftx,theta1,ftx,theta2,'o'),xlim([9 11])
Try running the code above with zero-paded fft's, e.g., to 8192 points, and see how the results change (you'll have to adjust some axis limits) and if that change makes sense.
Jiayun Liu
Jiayun Liu le 16 Oct 2022
"I've already explained above: where the frequency samples of the DFTs end up relative to the DTFTs" Yeah I guess this is the best explanation. Thanks very much for the discussion :D

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by