# Don´t know how to perform IFFT considering my frequency.

12 views (last 30 days)
Andriy Voshchenko on 19 Sep 2022
Commented: Andriy Voshchenko on 21 Sep 2022
Hi! I have a frequency domain data which I want to transform into time domain. I have the following file where the first column is the frequency in range [0 Nyquist frequency], second column is real component of the response and the 3rd colums is the imaginary part.
I know I have to use "ifft" function but I just don´t understand how to define it properly. I know the result should be time response doman with maximum value around 600-800 but when I launch the script I obtain peak values of 30. As far as I see there should be some way to input my frequency as the parameter. The help section includes this:
X = ifft(Y,n) returns the n-point inverse Fourier transform of Y by padding Y with trailing zeros to length n.
But I don´t understand what is the correlation between parameter "n" and my frequency, how do I know how many points to solve?
Part of my code as well as the attached data, keep in mind I have one sided spectra:
freq=Mreaction(:,1); % frequency of my response spectrum
hMoment=Mreaction(:,2)+i*Mreaction(:,3); % obtain complex number for the response moment
myTdata=ifft(hMoment,"symmetric"); % I´ve also tried with 1000 (and some others) points but the results just don´t
% make any sense to me
plot(myTdata) % Plot without time vector since I struggle to define it

Matt J on 19 Sep 2022
Edited: Matt J on 19 Sep 2022
But I don´t understand what is the correlation between parameter "n" and my frequency, how do I know how many points to solve?
The key relationship involving n is,
n=1/(dF*dT)
where dT and dF are the time and frequency sampling intervals . The choice of n depends on what dF you have (in your case dF=0.03) and what dT you want. Also, n must be an integer.
When using fft(x,n) you are telling the code to append zeros to x making it length n. However, in applications to time-frequency analysis (like yours) I find it is often better just to manually pad x to the length that you want, because the padding has to be done in a very specific way in conjunction with fftshift.
I illustrate all this below:
dT0=0.01; %maximum desired time sampling interval
dF=Mreaction(2)-Mreaction(1); %given frequency sampling interval
hMoment=complex( Mreaction(:,2) , Mreaction(:,3) );
n0=numel(hMoment);
n=max( ceil(1/dT0/dF) , n0 ); %ensures dT<=dT0=0.01
dT=1/dF/n; %actual time sampling interval
nAxis=( (0:n-1)-ceil((n-1)/2) ); %normalized axis
freqAxis=dF*nAxis;%frequency axis
timeAxis=dT*nAxis;%time axis
leftside=flip(conj(hMoment));
hMoment=[leftside(1:end-1); hMoment]; %two sided spectrum
hMoment(end+1:n)=0;
hMoment=fftshift(circshift(hMoment,1-n0)); %zero padding circulantly is complicated
myTdata=fftshift(real( ifft( ifftshift(hMoment)) ))/dT;
figure
plot(freqAxis,abs(hMoment));
xlabel Frequency
figure
plot(timeAxis, myTdata)
xlabel Time
Andriy Voshchenko on 21 Sep 2022
I see, as I stated in comment below the best way seems to be using another techniques instead of ifft. Thank you both for the contribution!

Paul on 20 Sep 2022
Hi Andriy
I would attack the problem this way, assuming throughout the original time-domain signal is real and the freq vector in the file is in Hz.
freq = Mreaction(:,1); % frequency of my response spectrum
hMoment = Mreaction(:,2) + 1i*Mreaction(:,3); % obtain complex number for the response moment
Check the first point in the freq vector
freq(1)
ans = 0.0300
It's not zero like it should be, so I'll synthesize a point at f = 0.
freq = [0;freq];
hMoment = [real(hMoment(1));hMoment];
The last point in the one-sided spectrum has a signficanct imaginary part
hMoment(end)
ans = 0.5224 + 0.7874i
If this point truly corresponded to the Nyquist frequency, then it would be real and N, the length of the time-domain signal, would be even. But it's not, so it looks like N must be odd.
N = 2*numel(freq) + 1;
The indices for the signal and the difference between successive frequency points are
n = 0:(N-1);
dF = 0.03; % assuming this is Hz?
Therefore, the sampling frequency and sampling period are
Fs = N*dF;
Ts = 1/Fs;
The time domain signal is then
myTdata = ifft(hMoment,N,"symmetric");
plot(n*Ts,myTdata)
xlabel('Time (sec)')
I know that you were expecting the signal to have a maximum value in the 600-800 range. The appropriate scaling, if any, would depend on how the original frequency domain data was collected and scaled in the first place.
Andriy Voshchenko on 21 Sep 2022
Oh I see, I think in this case in particular it would be better to avoid using ifft then since I don´t have enough data and only the output spectras. Thank you both for the contribution!

### Categories

Find more on Spectral Measurements in Help Center and File Exchange

R2022a

### Community Treasure Hunt

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

Start Hunting!