from time domain to frequency domain and back to time domain

4 次查看(过去 30 天)
Hi to everybody,
I am trying to jump from a frequency response to an impulse response and I need to start from sth basic so I understand how it works.
Can someone please help me understand why the last plot doesn't look like the first (the one that is commented out in the code) one? I would expect them to be the same.
% N=100000; % the number of data points
% fs=44100; % sample rate, number of samples per second
% dt=1/fs;% time increment (in seconds per sample)
% t=dt*(0:N-1); % time domain (in seconds)
% fc=100; % carrier frequency
% x=sin(2*pi*fc*t); % sine
% figure()
% plot(t,x)
%spectrum
X=fftshift(fft(x)); % DFT and shift center to zero
df=fs/N; % the frequency increment
f=-fs/2:df:fs/2-df; % create the frequency axis
figure()
plot(f,abs(X))
% reverse procedure
y=ifft(X); % inverse fft
N2=length(X); % determine the length of the signal
dt2=1/fs; % determine the time increment
tim=0:dt2:(N2-1)*dt2; %create the time axis
figure()
plot(tim,y)

采纳的回答

Dr. Seis
Dr. Seis 2012-5-16
Your "X" has shifted the zero frequency amplitude to the center. You need to use ifftshift to get it back where Matlab expects... i.e.:
y = ifft(ifftshift(X));
  3 个评论
Kacper Muszynski
Kacper Muszynski 2022-3-29
Thank you very much for this, was stuck on it for the longest time. However, the signal I get appears to be shifted by pi/2, any ideas?
clear all;
clc;
n = -8*pi:0.01:8*pi;
x1 = 2*sin(2*n);
subplot(3,1,1); plot(n,x1,'-b'), grid on,axis([-8*pi 8*pi -2 2]);
L = length(x1);
X = fft(x1,L);
X_amp = abs(fftshift(X));
w = linspace(-pi,pi,L);
subplot(3,1,2), plot(w/pi, X_amp), grid on;
x2 = X_amp;
x2 = ifft(ifftshift(x2)); %shift back from centre
x2 = fftshift(x2);
subplot(3,1,3), stem(n,x2),grid on,axis([-8*pi 8*pi -2 2]);

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Spectral Measurements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by