# Help with calculation of IFFT in Matlab

Status
Not open for further replies.

#### rohitmalpani

##### Newbie level 1
matlab ifft

Hii,
I'm generating a text file in Labview which contains the real and imaginary parts of intensity of a signal and I wish to calculate it's IFFT and come in time domain.
I have 201 points in the frequency range of 0Ghtz to 10Ghtz.
I need to first create a complex conjucate signal in range of -10Ghtz to 10Ghtz, so that when I do IFFT I get a real signal in time domain.
But I'm stuck with the former problem itself and not able to create a complex conjucate signal from my original signal in positive frequency.
Can anyone help around,

#### echo47

ifft matlab

Try this -- copy and paste it into your MATLAB Command Window.

The middle section does the ifft. The other sections simply create some input data, and plot the results. You may want to modify the tweaks at DC and Nyquist, depending on how your measurement hardware behaves at those points.

Code:
% Generate input data: square wave built from the first few frequency/phase harmonics
fmax = 10;              % maximum frequency, GHz
Nf = 201;               % frequency points, from zero to fmax
data = zeros(1,Nf);
data(1) = 1;            % square wave DC offset
cycles = 4;             % square wave cycles
phase = 2.1;            % square wave phase shift, radians
for k = 1:2:15          % sum several harmonics
data(1 + k * cycles) = 1.27 / k * exp(1j * ((k-1)/2 * pi + k * phase));
end
freq = 0:fmax/(Nf-1):fmax;
subplot(3,1,1); plot(freq, abs(data)); xlabel('Input Spectrum [GHz]');

% Calculate ifft of half-spectrum data
h = [conj(data) fliplr(data(2:length(data)-1))];
h(1) = 2 * real(h(1));                          % DC tweak
h(length(data)) = 2 * real(h(length(data)));    % Nyquist tweak
y = ifft(h);

% Plot results
N = length(h);
freq = 2 * fmax * (-N/2 : N/2-1) / N;
time = (0 : N-1) / 2 / fmax;
subplot(3,1,2); plot(freq, abs(fftshift(h))); xlabel('Expanded Spectrum [GHz]');
subplot(3,1,3); plot(time, N / 2 * y); xlabel('Time-Domain [nanoseconds]');

Status
Not open for further replies.