Inverse FFT of a matrix

Hello
I am trying to get the ifft of a S parameter matrix having frequency in the first column and the data in the second column.The code is below:
sp=sparameters('2Port.s2p');
freq=sp.Frequencies;
s=sp.Parameters;
s21=s(2,1,:);
%take s21 seperately
for i = 1:length(freq)
new_s21(i)=s21(:,:,i)
end;
s21_t=transpose(new_s21);
%ifft of S21
impulse_response1=ifft(s21_t);
I am getting a plot of IFFT with the x -axis having values from 0 to 1800 which I am not able to understand.Is the x-axis in seconds?
How to get the ifft() for the freq data that i have?

Answers (1)

Just looking at your attached figure, it is clear along x axis is time. inverse FFT gives back time domain data from freq domain data.
open('ifft.fig')

10 Comments

Should you need more elaborations, post your sample data.
What is the unit of the time axis?The plot is from 0 to 2000 but does not convey if it's seconds or millisec or nanoseconds.The impulse response matrix contains ifft values but not the time vector.I need the time vector of the ifft result to them convolve with another input signal. By sample data do you mean the impulse response matrix?
Please show all of the code, in particular the code that includes the plot command that made that plot.
Please see the code below:
sp=sparameters('2port.s2p');
freq=sp.Frequencies;
s=sp.Parameters;
s21=s(2,1,:);
for i = 1:length(freq)
new_s21(i)=s21(:,:,i)
end;
s21_t=transpose(new_s21);
impulse_response1=ifft(s21_t);
figure;
plot(impulse_response1);
title('impulse response');
Please let me know of the changes to be made.
Also,i have used the rationalfit to the s parameter file and then taken the impulse response.The code is below:
sp=sparameters('C:\Users\PrasadNGanes\Desktop\snp\QVR_MX0100A_InfMode_SldrInFlat_Zin_2Port.s2p');
S21=rfparam(sp,2,1);
freq=sp.Frequencies;
fit_data=rationalfit(freq,S21);
[resp,t]=impulse(fit_data,125e-12,2e3);
plot(t,resp);
How can the impulse response taking the ifft(s21) and using the impulse(fit_data) be so different?
This line:
plot(impulse_response1);
is plotting the elements of impulse_response1 agains the index vector 1:N, where N = numel(impulse_response1). If you want to plot against an actual time vector, the command would be
tvec = (0:(N-1))*Ts;
plot(tvec,impulse_response1);
where Ts is the sampling period of the signal.
Thanks Paul for the answer.
I have edited the code as suggested by you.A warning message saying that the imaginary components are ignored during processing is displayed.Why does this happen?
new code:
sp=sparameters('C:\Users\PrasadNGanes\Desktop\snp\QVR_MX0100A_InfMode_SldrInFlat_Zin_2Port.s2p');
freq=sp.Frequencies;
s=sp.Parameters;
S21=rfparam(sp,2,1);
impulse_response1=ifft(S21);
Ts=0.167e-3;%as the delta freq is 6kHz in S2P file
N=numel(impulse_response1);
tvec=(0:(N-1))*Ts;
figure;
plot(tvec,impulse_response1);
title('impulse response');
The attached snapshot has the warning message.
That means that impulse_response1 has a non-zero imaginary part. If you're expecting based on physics (or whatever) that impulse_response1 is a real-valued signal, then it's possible that ifft still returns a small imaginary part if S21 is not exactly conjugate symmetric. You can check this by
plot(tvec,real(impulse_response1))
plot(tvec,imag(impulse_response1))
If it looks like the imaginary part is just floating point error based on it's magnitude and you expect it to be exactly zero, then you can just get rid of it
impulse_response1 = real(impulse_response1);
or use the symmetric flag to force ifft to return a real-valued result.
impulse_response1=ifft(S21,'symmetric');
If S21 is, in fact, expected to have a non-negligible imaginary component, then you'll have to plot the real and imaginary parts separately (as shown above) or plot magnitude and phase, or whatever makes sense for your application.
Thanks a lot Paul for taking the time and explaining the solution in detail.
I am passing an input signal through an S matrix and observing the output signal in ADS simulation.
I am trying the same in MATLAB without using the rationalfit or using s2tf functions.
I see that the convolution output of MATLAB is not matching the ADS output.Not sure what the problem is.
The code is below:
sp=sparameters('C:\Users\PrasadNGanes\Desktop\snp\QVR_MX0100A_InfMode_SldrInFlat_Zin_2Port.s2p');
freq=sp.Frequencies;
s=sp.Parameters;
%Seperate S21 from S matrix
s21=s(2,1,:);
for i = 1:length(freq)
new_s21(i)=s21(:,:,i)
end
s21_t=transpose(new_s21);%%%%%%%%%%RI format
%Impulse response of S21
impulse_response1=ifft(s21_t);
Ts=0.167e-3;%as the delta freq is 6kHz in S2P file
N=numel(impulse_response1);
tvec=(0:(N-1))*Ts;
figure;
plot(tvec,abs(impulse_response1));
title('impulse response');
%%%%%%%%%%Convolution%%%%%%%%%%%%%%%%%%
%read input signal from xls
data=xlsread('C:\Users\PrasadNGanes\Desktop\probe.xlsx');
time1=data(:,1);
input=data(:,2);
%convolve input with the impulse response
convolution_result=conv(input,abs(impulse_response1));
convolution_time=linspace(min(time1)+min(tvec),max(time1)+max(tvec),length(convolution_result));
figure;
plot(convolution_time,convolution_result);
title('convolution output');
%read output file from ADS simulation and plot the output and input
data2=xlsread('C:\Users\PrasadNGanes\Desktop\probe_output.xlsx');
pr_out_time1=data(:,1);
pr_out_input=data(:,2);
figure;
plot(time1,input,'r');
title('input');
figure;
plot(pr_out_time1,pr_out_input,'b');
title('probe output');
I have attached the plots for reference.Could you help me in debugging the problem in the code.
Sorry, I don't have enought insight into how this is all suppsosed to work. I assume that the variables input and impulse_response1 have the same sampling period. Why is the convolution using abs(impulse_response1), i.e., why the abs? One other issue that you may want to look into is that you might need to use fftsfhift to get the impulse response:
impulse_response1=ifft(s21_t);
and then the corresponding tvec would be:
tvec = ((0:N-1)-floor(N/2))*Ts

Sign in to comment.

Categories

Find more on Fourier Analysis and Filtering in Help Center and File Exchange

Asked:

on 18 Feb 2024

Commented:

on 21 Feb 2024

Community Treasure Hunt

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

Start Hunting!