from time domain to frequency domain and back to time domain

조회 수: 4 (최근 30일)
buscuit
buscuit 2012년 5월 16일
댓글: Kacper Muszynski 2022년 3월 29일
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
buscuit
buscuit 2012년 5월 16일
sure, Elige. Thank you very much for the help so far.
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