Determining the input from the output using IFFT
Show older comments
Hello,
I have an output waveform y(t) after having passed through an S-matrix.I need to get the input signal x(t) and the method followed is:
1.Extract S21 from S-matrix and take IFFT of S21 to get the impulse response h(t)
2.convolve output waveform y(t) with 1/h(t) to get back input signal x(t).
The code is written below:
%Read the S parameter matrix and seperate the freq and s matrix data
sp=sparameters('C:\Users\PrasadNGanes\Desktop\snp_data\2Port.s2p');
freq=sp.Frequencies;
s=sp.Parameters;
%Seperate the S21 column from S-matrix and plot S21
S21=rfparam(sp,2,1);
rfwrite(S21,freq,'C:\Users\PrasadNGanes\Desktop\snp\newS21.s2p');
sp_inv=sparameters('C:\Users\PrasadNGanes\Desktop\snp\newS21.s2p');
figure;
rfplot(sp_inv);
title('S21 plot');
%Take IIFT of S21 to get impulse response h(t) and plot Impulse response
impulse_response=ifft(S21);
figure;
plot(impulse_response);
Fs = 2*max(freq);
Ts=1/Fs;
N=numel(impulse_response);
tvec=(0:(N-1))*Ts;
figure;
plot(tvec,impulse_response);
title('impulse response');
%convolve output y(t) with 1/h(t) to get back the input x(t)
inverse_impulse=1./impulse_response;
%read the output y(t)
data=xlsread('C:\Users\PrasadNGanes\Desktop\snp_data\probe_output.xlsx');
out_time=data(:,1);
output=data(:,2);
convolution_result=conv(output,inverse_impulse);
convolution_time=linspace(min(out_time)+min(tvec),max(out_time)+max(tvec),length(convolution_result));
figure;
plot(convolution_time,convolution_result);
title('input plot after convolution');
%Plot the real input and output
data=xlsread('C:\Users\PrasadNGanes\Desktop\probe.xlsx');
inp_time=data(:,1);
input=data(:,2);
figure;
plot(inp_time,input,'b');
hold on
plot(out_time,output,'r');
title('Actual output in red and input in blue');
However, I see that the input waveform got after running the code and the actual waveform do not match.I have attached the images for reference.
Can somebody help me what needs to be corrected to get the correct result.
11 Comments
Ganesh Prasad
on 26 Feb 2024
Edited: Walter Roberson
on 29 Feb 2024
Ganesh Prasad
on 26 Feb 2024
Edited: Walter Roberson
on 29 Feb 2024
William Rose
on 26 Feb 2024
Perhaps the output is not as expected because
b2 = s21a1 + S22a2
and your code does not account for the S22a2 contribution to the output. Perhaps that term is significant.
Ganesh Prasad
on 27 Feb 2024
Edited: Ganesh Prasad
on 27 Feb 2024
William Rose
on 27 Feb 2024
@Ganesh Prasad, I'm afraid I do not have time to assist on this question at this time.
Paul
on 27 Feb 2024
What is the justification for this?
% 2.convolve output waveform y(t) with 1/h(t) to get back input signal x(t).
inverse_impulse=1./impulse_response;
...
convolution_result=conv(output,inverse_impulse);
That doesn't seem right.
Sometimes it's helpful to verify code for a simple problem with a known solution.
Ganesh Prasad
on 27 Feb 2024
William Rose
on 27 Feb 2024
@Paul is right, as usual. It is not true that
"If x(t)*h(t)=y(t) then x(t)=1/h(t) * y(t) where * is convolution and h(t) is the impulse response."
When I say DFT below, I mean the discrete Fourier transform, which you can compute with fft().
I would do the deconvolution in the frequency domain. To do this, you will need the frequencies of the S21(f) response to be the same as the frequencies of Y(f)=DFT of y(t). Then you can estimate X(f)=Y(f)./S21(f), and x(t)=invDFT(X(f)). But remember that the DFT assumes that your recording of y(t) represents exactly one period of a periodic signal. Your recording of y(t) has about 3.5 periods. So there will be a lot of high frequency "noise" in the DFT, due to the mismatch between the beginning and the end. This is why you use a window such as Hamming or Hann. If you apply a window to Y(f) before computing its DFT, then the X(f) and x(t) you get from deconvolution will be the input that gives the windowed signal. Another option is to clip y(t) so that it wraps around smoothly, i.e. so that you have exactly 3 cycles of the signal, not 3.5. You may also need to apply a linear adjustment, i.e. a kind of "tilt", so that the beginning and the end of the signal line up smoothly. Then you can apply the opposite tilt to the final x(t) which you get from deconvolution.
Paul
on 28 Feb 2024
I think it would be helpful if you shared you s21 data (including the frequencies) or a representative example and the associated y(t). You can use the paperclip icon on the Insert menu to attach a file. And I think we need to better understand exactly how y(t) is generated.
Ganesh Prasad
on 28 Feb 2024
Taking a look at the data
copyfile S21.txt S21.s2p
S = sparameters('S21.s2p')
The frequency data does not start at zero. I think if you're going to use the IFFT approach, you'll have to figure out how to extrapolate S21 to zero.
format short e
S.Frequencies([1 end])
figure
semilogx(S.Frequencies,abs(squeeze(S.Parameters)))
The frequencies are not equally spaced (maybe they're spaced logarithmically?). Before taking using IFFT I think you'll have to do an interpoplation to an equally spaced frequency vector.
figure
plot(diff(S.Frequencies))
After those two issues are sorted out, you'll have to also account for the "upper half" of S21 in the frequency domain. Assuming that the impulse response is supposed to be real-valued, check this answer for a discussion on that topic.
I believe that all of these issues need to be addressed first to get the "full picture" of S21 before proceeding with the frequency domain approach suggested by @William Rose or with a time domain approach as you are attempting.
I didn't look at y(t), I suspect that there will be more work to do on that as well depending on decisions made on how you modify the S21 data.
There may be other options to to address this problem as well.
Accepted Answer
More Answers (0)
Categories
Find more on Bartlett in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

