Reconstructed Pulse Out of Phase

조회 수: 4 (최근 30일)
Doug
Doug 2022년 9월 6일
댓글: Paul 2022년 9월 6일
In my research I'm having a problem reconstructing some pulses, I've replicated the problem I'm having with a simple gaussian pulse. Essentially when I take the IFFT of the pulse, the reconstructed time domain signal is out of phase. I've included my code with the plots, I think the problem is within how I'm reconstructing the time space. Any help is appreciated, thank you!
clear variables
%% FFT Test on Gaussian Pulse
Fs = 100; %Sampling Frequency
t = -0.5:1/Fs:0.5; %Time Vector
L = length(t);
x = 1/(4*sqrt(2*pi*0.01))*(exp(-t.^2/(2*0.01))); %Gaussian pulse
plot(t,x) %plotting pulse
title('Gaussian Pulse')
xlabel('time(t)')
ylabel('Pulse')
n = 2^nextpow2(L);
Y = fft(x,n); %plotting frequency spectrum
P = abs(Y);
f = Fs*(0:(n/2))/n;
plot(f,P(1:n/2+1)
%% Reconstructing Pulse
recon = ifft(Y);
t2 = linspace(-0.5,0.5,128); %Reconstructing Time Space
figure()
plot(t,x)
hold on
plot(t2,recon,'--')
hold off
legend('Original','Reconstruction')

채택된 답변

Paul
Paul 2022년 9월 6일
Hi Doug,
I think the short answer is, don't use nextpow2.
Fs = 100; %Sampling Frequency
t = -0.5:1/Fs:0.5; %Time Vector
L = length(t);
x = 1/(4*sqrt(2*pi*0.01))*(exp(-t.^2/(2*0.01))); %Gaussian pulse
Y = fft(x);
xr = ifft(Y);
figure;
plot(t,x,t,xr,'o')
However, that answer seems too obvious.
If desired to use more points in the fft for some reason, then we just need to account for what that means on the time vector
N = 2^nextpow2(numel(x));
tr = (0:(numel(x)-1))/Fs + t(1);
xr = ifft(fft(x,N));
xr = xr(1:numel(tr));
In the plot below, I'm also including the what is effectively t2 and recon from the Question. We see that t2 isn't really the correct time vector becasue it effectively redefined the sampling frequency.
figure;
plot(t,x,tr,xr,'o',.1+linspace(-0.5,0.5,128),ifft(fft(x,128)))
legend('Original','Reconstructed','recon from Question')
  댓글 수: 2
Doug
Doug 2022년 9월 6일
Okay, thanks for this,I think this strikes at the core of my problem. I'll have to take another stab at my original code. Thanks again for your help.
Paul
Paul 2022년 9월 6일
Good luck. Keep in mind that
fft(x)
Only give the correct magnitude, but not the correct phase, because the first element of x corresponds to a negative time. In this case, since we're going to frequency and back to time, it doesn't matter, but keep it in mind.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Cris LaPierre
Cris LaPierre 2022년 9월 6일
I'm not an FFT expert, but it appears to be related to your value of n. At least the shift goes away when I use L instead (seethis example)
%% FFT Test on Gaussian Pulse
Fs = 100; %Sampling Frequency
t = -0.5:1/Fs:0.5; %Time Vector
L = length(t);
x = 1/(4*sqrt(2*pi*0.01))*(exp(-t.^2/(2*0.01))); %Gaussian pulse
plot(t,x) %plotting pulse
title('Gaussian Pulse')
xlabel('time(t)')
ylabel('Pulse')
% n = 2^nextpow2(L);
Y = fft(x); %plotting frequency spectrum
P = abs(Y/L);
f = Fs*(0:(L/2))/L;
plot(f,P(1:L/2+1))
Warning: Integer operands are required for colon operator when used as index.
%% Reconstructing Pulse
recon = ifft(Y);
t2 = linspace(-0.5,0.5,L); %Reconstructing Time Space
figure()
plot(t,x)
hold on
plot(t2,recon,'--')
hold off
legend('Original','Reconstruction')
  댓글 수: 1
Doug
Doug 2022년 9월 6일
I've noticed this as well, I think the problem lies in the fact that when reconstructing the pulse using n, the reconsctructed points will necessarily be out of phase due to n=/=L. In my original problem however, the ifft needs to be consctructed out of n due to some properties of the data. I'll have to look a bit deeper into this but thank you, it gives me some ideas where to look.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by