Wrong output graph when using ifft on rectangular pulse?

14 visualizaciones (últimos 30 días)
Umar Ash-Shafi
Umar Ash-Shafi el 13 de Oct. de 2023
Editada: Matt J el 13 de Oct. de 2023
When doing an inverse fourier transform of a rectpuls function, the output in the time domain has a sinc that has been shifted and split. How canI fix this so that the output is a sinc centred at t=0 as you would expect. Here is my code:
--------------------------------------------
% Define the frequency axis
S = 1000; % Change this to your desired number of samples
f = linspace(-10, 10, S); % Frequency vector with a high sampling rate
% Define H(f)
H = rectpuls(f, 2);
% Perform the inverse Fourier transform to get the time signal
h = ifft(ifftshift(H));
% Calculate the time axis based on the new value of S
Fs = 1 / (f(2) - f(1));
dt = 1 / Fs;
t = (-Fs/2:dt:Fs/2-dt); % Time axis
% Create a figure with two subplots
figure;
% Plot H(f) in the frequency domain (blue)
subplot(2, 1, 1);
plot(f, H, 'b');
title('Frequency Domain');
xlabel('Frequency (f)');
ylabel('Magnitude');
grid on;
% Plot the corresponding time signal for H in the time domain (blue)
subplot(2, 1, 2);
plot(t, real(h), 'b');
title('Time Domain');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
-------------------------------------------
Here is the output plots I get, where the sinc is split and shifted:

Respuestas (1)

Matt J
Matt J el 13 de Oct. de 2023
Editada: Matt J el 13 de Oct. de 2023
h = fftshift(ifft(ifftshift(H)));
% Calculate the time axis based on the new value of S
t = ((0:S-1)-ceil((S-1)/2))/S/(f(2)-f(1)) ; % Time axis

Categorías

Más información sobre Fourier Analysis and Filtering en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by