% *****************************************************
% 3rd order amplifier distortion model on power vectors
% Markus Nentwig, 2010
% *****************************************************
close all; clear all;

% Number of samples over the whole bandwidth
n=300;
s_in=zeros(1, n);

% assign power to the input signal
s_in(145:154)=1;
s_in(175:184)=0.5;
s_in=s_in / sum(s_in); % normalize power to 1
s_dist3=conv(conv(s_in, s_in), fliplr(s_in));

% limit to original bandwidth, shift the origin back
s_in
s_dist3=s_dist3(n:2*n-1)

% a simple amplifier model
% a3 is the amplifier model, eyeball-calibrated to produce
% roughly -33 dBc adjacent channel power ratio for for sum(s_in=1)
a3=1.3e-2; 
s_model=s_in+a3*s_dist3
figure(); plot(10*log10([s_in; s_dist3; s_model]'+1e-6), '+-');
legend({'input', 'pure 3rd order distortion', 'model output'});
