How to IFFT only frequency information
30 views (last 30 days)
I want to do IFFT but i got a problem , I have frequency information only
Give a full explanation..
1 30MHz 78
2 31MHz 48
3 33MHz 98
4 35MHz 78
I have a file like this.. they have only frequency and amplitude information.
Can I implement ifft using this file?
Jack on 27 Mar 2023
Yes, you can perform an Inverse Fast Fourier Transform (IFFT) in MATLAB using the frequency and amplitude information that you have. Here's an example code snippet that demonstrates how to do this:
% Load frequency and amplitude data from file
data = load('frequency_amplitude_data.txt');
freq = data(:, 1); % Frequency in Hz
amp = data(:, 2); % Amplitude
% Create complex frequency domain signal
fs = 1e9; % Sampling frequency in Hz
N = length(freq); % Number of frequency points
df = fs / N; % Frequency resolution in Hz
f = (0:N-1) * df; % Frequency vector
amp_norm = amp / max(amp); % Normalize amplitude to [0, 1]
signal_freq = zeros(1, N);
for ii = 1:N
[~, idx] = min(abs(f - freq(ii))); % Find closest frequency index
signal_freq(idx) = amp_norm(ii); % Set amplitude at frequency index
% Perform IFFT to obtain time-domain signal
signal_time = ifft(signal_freq, N);
% Plot results
subplot(2, 1, 1)
plot(freq / 1e6, amp, 'o-')
title('Frequency Domain Signal')
subplot(2, 1, 2)
plot((0:N-1) / fs * 1e6, abs(signal_time))
xlabel('Time (\mu s)')
title('Time Domain Signal')
In this example, we first load the frequency and amplitude data from a file called frequency_amplitude_data.txt. The data is assumed to have two columns, with the first column containing the frequency values in Hz and the second column containing the amplitude values.
We then create a complex frequency domain signal by normalizing the amplitude values to [0, 1] and setting the amplitude at the corresponding frequency index in the signal vector. The length of the signal vector is set to N, which is equal to the number of frequency points.
Finally, we perform the IFFT using the ifft function in MATLAB to obtain the time-domain signal. We also plot the frequency domain and time domain signals for visualization.
Note that the sampling frequency fs is assumed to be 1 GHz in this example. You should adjust the value of fs based on your specific application.
Walter Roberson on 27 Mar 2023
In the special case that the difference between frequencies is a multiple of a consistent fraction, then you can take diff() of the frequencies, and find the smallest difference. Now subtract the smallest frequency from the frequencies, and divide by the smallest frequency division and add 1 to get bin numbers. Use the bin numbers to index into an array and assign the amplitude information.
For example with the information you have you would get bin numbers [1 2 4 6] -- smallest difference is 1 MHz, first difference is 1*1MHz, second difference is 2*1MHz, third difference is 2*1MHz beyond that. Now take the smallest original frequency, divide by the smallest difference to get a bin number (30MHz / 1MHz = 30 in this case) and shift the array by that many places leaving room for an initial zero -- getting 30 zeros, then amplitude 78, then amplitude 48, then a gap of a zero, then amplitude 98, then a gap of one zero, then amplitude 78.
Now take the vector after the first zero and fliplr() and append that -- vector = [0 vector(2:end), fliplr(vector(2:end))] .
The result is a vector that you can ifft. The bin widths are the smallest frequency difference (1 MHz in this case). (But take into account nyquist effects -- an original frequency of 1 Hz would generate fft bins that are 2 Hz wide, so 1 MHz fft bins would imply a sampling frequency of 1/2 MHz .)