How to convert s2p to Impulse Response?

27 ビュー (過去 30 日間)
Delbert
Delbert 2024 年 3 月 5 日
コメント済み: Delbert 2024 年 3 月 7 日
Hi All,
I am new to signal processing and was tasked to convert an s2p file of a signal channel, cable, into an FIR filter. This will allow us to simulate the response of input signals as if it went through those cables in MATLAB.
I did some digging and apparently the first step is to create an impulse response from the s2p file.
I have tried SParameterChannel function but it only works for s4p files.
I am currently trying to make convert the s2p file to a transfer function but that idea has yet to bear fruit.
Any advice is appreciated. If my approach to design this FIR filter is incorrect, please let me know as well.
  2 件のコメント
Manikanta Aditya
Manikanta Aditya 2024 年 3 月 6 日
Hey,
Your approach to designing an FIR filter based on the S-parameters from an S2P file is on the right track. The general idea is to convert the S-parameters into a frequency response and then transform that into an impulse response, which can be used as the coefficients of your FIR filter.
% Load the s2p file
s_params = read(rfdata.data,'Your_s2p_file.s2p');
% Convert the s2p file to a transfer function
tf = s2tf(s_params);
% Create an impulse response from the transfer function
impulse_response = ifft(tf);
% Design the FIR filter using the impulse response
N = 50; % You can adjust the order of the filter based on your requirements
b = fir1(N, impulse_response);
Just a rough idea of the steps and the code, Try it out and see if you can get what you require.
Thanks!
Mathieu NOE
Mathieu NOE 2024 年 3 月 6 日
NB we need the negative and positive frequency complex FRF

サインインしてコメントする。

回答 (1 件)

Mathieu NOE
Mathieu NOE 2024 年 3 月 6 日
hello
see example below :
%% create the FRF complex data
Fs = 1e3;
Freq = linspace(0,Fs/2,200); % make sure freq vector goes up to Fs/2
% example #1
b = fir1(48,[0.2 0.4]); % Window-based FIR band pass filter design
a = 1;
frf = freqz(b,a,Freq,Fs);
%% IR / FIR obtained with ifft method
if mod(length(frf),2)==0 % iseven
frf_sym = conj(frf(end:-1:2));
else
frf_sym = conj(frf(end-1:-1:2));
end
fir = real(ifft([frf frf_sym])); % NB we need the negative and positive frequency complex FRF
fir = fir(1:50); % truncation is possible if fir decays enough
frfid = freqz(fir,1,Freq,Fs);
%% IR / FIR obtained with invfreqz
ITER = 100;
% FIR filter design
NB = 50; %
NA = 0;
W = 2*pi*Freq/Fs;
Wt = ones(size(W));
TOL = 1e-2;
[fir2,A] = invfreqz(frf,W,NB,NA,Wt,ITER,TOL);
frfid2 = freqz(fir2,1,Freq,Fs);
figure(1)
subplot(311),plot(1:length(b),b,'-*',1:length(fir),fir,1:length(fir2),fir2);
legend('FIR model','identified FIR (fft)','identified FIR (invfreqz)');
xlabel('samples');
ylabel('amplitude');
subplot(312),plot(Freq,20*log10(abs(frf)),Freq,20*log10(abs(frfid)),Freq,20*log10(abs(frfid2)),'*');
legend('input model','identified FIR model (fft)','identified FIR model (invfreqz)');
xlabel('frequency (Hz)');
ylabel('FRF modulus (dB)');
subplot(313),plot(Freq,180/pi*angle(frf),Freq,180/pi*angle(frfid),Freq,180/pi*angle(frfid),'*');
legend('input model','identified FIR model (fft)','identified FIR model (invfreqz)');
xlabel('frequency (Hz)');
ylabel('FRF angle (°)');
  3 件のコメント
Mathieu NOE
Mathieu NOE 2024 年 3 月 7 日
tx for the reminder !
All the best
Delbert
Delbert 2024 年 3 月 7 日
Hi Mathieu, Manikanta, Paul
Thank you for responding to my problem.
I am several steps closer because of your comments.
I am stuck on a new problem now and am still reading into all the functions and theories you both have presented in your comments.
I have obtained a complex impulse response for my cable. Now my new problem is if MATLAB has a built it function than can make handle a complex input to design an FIR filter.
finite impulse response - FIR filter design for complex signal - Signal Processing Stack Exchange -> I found this web page and am still reading into the theories. I am just preparing myself in case I have to create my own algorithm.
Any suggestions, reading material would be appreciated.
Thank you very much for both of your time.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDigital and Analog Filters についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by