fft and ifft: problem with amplitude scaling after removing noise

8 views (last 30 days)
Dear Forum,
I want to do the following:
1) transfer data vector (containing two sine waves) in the frequency domain using fft
2) only select the frequency of one of the sine waves
3) transfer this single sine wave back into the time domain using ifft
Somehow I have a problem in regaining the proper amplitude of the original sine wave. I am not sure which scaling I should use. These are the steps:
x = load('data.dat'); % has two oscillations: f1=2/year and f2=3/year
time = 1:length(x); % 1200 monthly measurements
ntime = length(x);
Fs = 12; % to get frequency unit [1/years]
nfft = 2048;
% Foward FFT:
X = fft(x,nfft);
Xhalf = X(1:nfft/2); % discard the second half of the FFT
mx = abs(Xhalf); % magnitude of X
f = (0:nfft/2-1)*Fs/nfft; % frequency vector
% only search for one wave with defined frequency:
fsearch = 2.00; % [1/year]
tmp = abs(f-fsearch);
[idx idx] = min(tmp); %index of closest value
cindex = idx;
% set the rest of the spectrum to zero,
% only keep one oscillatory signal:
aaa = zeros(nfft,1);
aaa(cindex) = X(cindex);
X = aaa;
% inverse FFT to get the filtered data in the time domain:
y = ifft(X,'symmetric');
% realy = real(y); % only if 'asymmetric' is used
If I do the above approach and set everything to zero except the two frequency bins that I know are the original data, I still only recover ~40% of the original amplitude. I tried scaling the fft and ifft by Fs, but it doesn't change the results. Also using the symmetric or asymmetric option does not seem to have any impact. Any suggestions where I might assume something wrong?

Answers (0)

Community Treasure Hunt

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

Start Hunting!