% ------------------------------------------------------------
% MATLAB example on how to import and plot an S-parameter data
% file obtained with a HP8753B Network Analyzer and Agilent VEE.
%
% NB: This script assumes that format of the data is frequencies
% in Hz and S-parameters in real and imaginary parts. As example
% this would be stated as # Hz S RI R 50 in the .s2p file.
%
% NB: Before running this script, open the .s2p file with a
% text editor and remove all lines starting with ! or # so that
% the file only contains data and save it.
% ------------------------------------------------------------

close all;
clear all;
clc;

data = importdata('S-parameters.s2p'); %<!-- Change to your filename
freq = data(:,1);
s11_real = data(:,2);
s11_imag = data(:,3);
s12_real = data(:,4);
s12_imag = data(:,5);
s21_real = data(:,6);
s21_imag = data(:,7);
s22_real = data(:,8);
s22_imag = data(:,9);

s11 = complex(s11_real,s11_imag);
s12 = complex(s12_real,s12_imag);
s21 = complex(s21_real,s21_imag);
s22 = complex(s22_real,s22_imag);

figure(1);
subplot(2,2,1);
plot(freq, 20*log10(abs(s11)));
title('S_{11}');
xlabel('Frequency [Hz]');
ylabel('dB');
subplot(2,2,2);
plot(freq, 20*log10(abs(s12)));
title('S_{12}');
xlabel('Frequency [Hz]');
ylabel('dB');
subplot(2,2,3);
plot(freq, 20*log10(abs(s21)));
title('S_{21}');
xlabel('Frequency [Hz]');
ylabel('dB');
subplot(2,2,4);
plot(freq, 20*log10(abs(s22)));
title('S_{22}');
xlabel('Frequency [Hz]');
ylabel('dB');

% [EOF]