# Help for iFFT in Matlab

Status
Not open for further replies.

#### cmd

##### Member level 2
Hi everyone,

I have to make Distance to Fault measurement on cables. I have a source data from VNA return loss versus frequency. I have to transform the data into time domain with iFFT. In my data there are 301 frequency points (0.7GHz-1Ghz in 1Mhz steps) with their return loss values. How should i use iFFT function in MATLAB for this purpose?

Last edited:

#### cmd

##### Member level 2
Is there anyone who can help me about ifft function in matlab?
I need to transform the return loss data from frequency domain to time domain in order to calculate the distance to fault on coaxial cable

#### klystron

Can you send your data file

cmd

### cmd

Points: 2

#### klystron

I used Excel to do the IFFT

---------- Post added at 10:23 ---------- Previous post was at 10:22 ----------

The result IFFT

cmd

### cmd

Points: 2

The Excel file

#### Attachments

• rlos.zip
23.7 KB · Views: 50
cmd

### cmd

Points: 2

#### albbg

I think you should convert before RL in dB into linear RL. Simply RL(lin) = 10^[RL(dB)/10]
Then you can apply IFFT. Since IFFT assumes that your data are coming from an FFT starting from negative frequency I think you should restore the central DC frequency using the fftshift command and taking only the positive times, that is windowing the IFFT vector from N/2 to N. After that you can recover the time remembering that you can go up to 1/(sampling frequency).
Now if you know the propagation speed in your medium and the velocity of light (3e8 m/s) I think you can find the distance simply multiplying time*speed.
I wrote the following code (in Scilab but I think in Matlab is exactly the same), supposing you have as input, a two column vector called "a". First column contains the frequencies and the second the RL.

fs = a(2,1)-a(1,1);

c_speed = 3e8;
v_prop = 0.67;

timedata = fftshift(ifft(datalin));
timedata = timedata(N/2+1:N);

time=[0:2/(N*fs):1/fs-2/(N*fs)]./2;
distance = (c_speed*v_prop).*time;

plot(distance,timedata);

cmd

### cmd

Points: 2

#### cmd

##### Member level 2
I tried your code in matlab i became an error for ^power:" Inputs must be a scalar and square matrix." (why do i have to transfor dm to linear?)
I commented this part and run the code. I changed v_prop=0.88 for the cables the data came from.My return loss datas are reel values. iFFT of reel value is complex in time domain. Should i take abs function? If i take it i became peakes in 20,40,60,80 which they decrease periodicly. I think that its far from expected plot. IN the expected plot, RL_time values are in negative db and at 20m a peak to (-5db)- (-10db) and at 30 m near a peak to 0 db.

#### klystron

I have done the complex impedance IFFT on the simulated data with Excel. See the attached files and the notes.
The code that you need (you must write the Matlab):
Read real impedance data from file
Make complex impedance vector ( Imp = complex(R,I))
Do IFFT (IFFT(Imp)
Scale and plot

#### Attachments

• IFFT of complex impedance using simulated data.7z
24.2 KB · Views: 52
cmd

### cmd

Points: 2

#### cmd

##### Member level 2
Thank you klystron! You worked really hard to help me.

I will try to do this in Matlab. Does it can be done also amplitude and phase info instead of real and imaginary part?

#### klystron

I think Matlab requires the data in the format real + i magin (The Matlab complex function will combine the real and imagin parts of the impedance

cmd

### cmd

Points: 2

#### klystron

Herewith the Matlab code.

#### Attachments

• dtftrialupdated.rar
713 bytes · Views: 51
Shan Shan and cmd

Points: 2

### Shan Shan

Points: 2

#### cmd

##### Member level 2
Hi klystron,
I progressed my code for reel and imaginar input and also for magnitude and phase information. Here is the key part of code;
for reel and imaginer informations;
gamma_f = complex(re,img);
gamma_t = ifft(gamma_f,NFFT);
RL = 10*log(abs(gamma_t));

for magnitude and phase(angle) information;
gamma_f = complex;
gamma_t = ifft(gamma_f,NFFT);
RL = 10*log(abs(gamma_t));

But i have a different problem now. Yesterday i made some measurements with anritsu site master s311d about return los and dtf. I converted the data from site master to txt.file. But the values are with commas for ex;
700,1 -3,442 -70,7
700,6 -3,535 114,1
Matlab want numbers like belows and don't read my values with commas...
700.1 -3.442 -70.7
700.6 -3.535 114.1
How can fix this problem. Does i have to fix this with my hands

#### Attachments

• 1.JPG
62.7 KB · Views: 51
27.5 KB · Views: 58
Last edited:
jks

### jks

Points: 2

#### klystron

Import the test files into Excel (comma delimited), save the xls file and use the Matlab xlsread function to read the xls file

---------- Post added at 20:44 ---------- Previous post was at 20:07 ----------

You can use csvread in Matlab to read a comma separated variable file

cmd

### cmd

Points: 2

#### cmd

##### Member level 2
Thanks klystron!
Problem is resolved with excel :wink:
I can locate fault at fast similar point and with fast similar rl value ,but traces look different
What do you think what could be the problem?

#### Attachments

27.5 KB · Views: 49
• 1.JPG
62.7 KB · Views: 39

#### cmd

##### Member level 2
Anritsu Site Master use chirp z transform for transforming data from frequency domain to time domain in order to zoom the trace.
With ifft we create a time domain sequence with measurement points N between dt*[0:NFFT-1] and distance domain sequence until to max distance range 206meter. Then we limit the trace according to distance range we want axis([0 30 -60 0])
But if i look at data from site master it has 517 data points in 0 - 30 distance range.
It can be the reason for the difference of traces. What do you think? Do you know the way about chirp z trasform of the data?

#### cmd

##### Member level 2
Hi everyone,
There is a problem somewhere in the code. The time domain localization is true but return loss values doesn't match. In order to match return loss values i have to multiply the ifft result with a factor which changes in every experiment data. It shouldn't be so. Where is the problem?
For example in first experiment (far end of the cable is open)
I have to multiply the ifft with 2 to get true return loss values;
gamma_t = 2*ifft(gamma_f,NFFT);
So the traces is similar. I uploaded them here in last week (above)

In the second situation (cable far end terminated with load, and cable is bent in 19m)
I have to multiply the ifft with 30 to get true return loss values;
gamma_t = 30*ifft(gamma_f,NFFT);
Then the traces are more similar like below;

jks

### jks

Points: 2

#### jks

##### Newbie level 5
i think
RL = 10*log(abs(gamma_t)); should be RL = 10*log10(abs(gamma_t));

---------- Post added at 11:04 ---------- Previous post was at 11:03 ----------

i think
RL = 10*log(abs(gamma_t)); should be RL = 20*log10(abs(gamma_t));

#### jks

##### Newbie level 5
hi CMD
to explain you my project :
1) i have RL data Frequency and phase data separated in 401 points.
2) I need to plot IFFT from above inputs to locate fault.
3) after locating the fault in have to filter that RL value in time and
4) the filtered data in time domain is to be converted in frequency domain again.

i am unable to find the proper time scale ,
as my transmission line length is 16m and with speed of 3e8m/sec signal reaches at the end in 53nsec , but in my piloting and calculations i get the sample time as 1/400Khz and after 401 points total time is 2.5 µ sec which is much large than the actual time to reach the signal at the end.
thanks