From: jimmy mac on
Hello,
Im trying to go back and fourth with the ifft and fft.
Im having a hard time getting the orignal signal back.

To simplify. can we just look at the fft example which does a FFT of a sin wave.
http://www.mathworks.com/access/helpdesk/help/techdoc/ref/fft.html

so starting with this example, how do we get the orignal signal back.
at the very end of the the code i copied from the example, i added a plot(test) and the output of this looks nothing like the orignal sinwave and the magnitude is off by a around 1000


IFs = 1000; % Sampling frequency
T = 1/Fs; % Sample time
L = 1000; % Length of signal
t = (0:L-1)*T; % Time vector
% Sum of a 50 Hz sinusoid and a 120 Hz sinusoid
x = 0.7*sin(2*pi*50*t);
y = x + 2*randn(size(t)); % Sinusoids plus noise
plot(Fs*t(1:50),y(1:50))
title('Signal Corrupted with Zero-Mean Random Noise')
xlabel('time (milliseconds)')


NFFT = 2^nextpow2(L); % Next power of 2 from length of y
Y = fft(y,NFFT)/L;
f = Fs/2*linspace(0,1,NFFT/2+1);

% Plot single-sided amplitude spectrum.
plot(f,2*abs(Y(1:NFFT/2+1)))
title('Single-Sided Amplitude Spectrum of y(t)')
xlabel('Frequency (Hz)')
ylabel('|Y(f)|')


test = ifft(ifftshift(Y))
plot(test)
From: Matt J on
"jimmy mac" <jimmyinct(a)gmail.com> wrote in message <htm6b5$b13$1(a)fred.mathworks.com>...
> Hello,
> Im trying to go back and fourth with the ifft and fft.
> Im having a hard time getting the orignal signal back.
>
> To simplify. can we just look at the fft example which does a FFT of a sin wave.
> http://www.mathworks.com/access/helpdesk/help/techdoc/ref/fft.html
>
> so starting with this example, how do we get the orignal signal back.
> at the very end of the the code i copied from the example, i added a plot(test) and the output of this looks nothing like the orignal sinwave and the magnitude is off by a around 1000
>
>
> IFs = 1000; % Sampling frequency
> T = 1/Fs; % Sample time
> L = 1000; % Length of signal
> t = (0:L-1)*T; % Time vector
> % Sum of a 50 Hz sinusoid and a 120 Hz sinusoid
> x = 0.7*sin(2*pi*50*t);
> y = x + 2*randn(size(t)); % Sinusoids plus noise
> plot(Fs*t(1:50),y(1:50))
> title('Signal Corrupted with Zero-Mean Random Noise')
> xlabel('time (milliseconds)')
>
>
> NFFT = 2^nextpow2(L); % Next power of 2 from length of y
> Y = fft(y,NFFT)/L;
> f = Fs/2*linspace(0,1,NFFT/2+1);
>
> % Plot single-sided amplitude spectrum.
> plot(f,2*abs(Y(1:NFFT/2+1)))
> title('Single-Sided Amplitude Spectrum of y(t)')
> xlabel('Frequency (Hz)')
> ylabel('|Y(f)|')
>
>
> test = ifft(ifftshift(Y))
> plot(test)


Well, ifft(...,N) is the inverse of fft(...,N). Any other operations you do on top of that need to be inverted as well. So, if you transform using


Y = fft(y,NFFT)/L;

Then the inverse is

ifft(Y*L,NFFT); %Note - no ifftshift