How to convert s2p to Impulse Response?
51 views (last 30 days)
Show older comments
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 Comments
Manikanta Aditya
on 6 Mar 2024
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!
Answers (1)
Mathieu NOE
on 6 Mar 2024
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 Comments
See Also
Categories
Find more on Filter Design 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!