%% Third-Order Intercept Point of a Two-Tone Nonlinear Signal with Noise
% Create a two-tone sinusoid with frequencies f_1=5 kHz and f_2=6 kHz, sampled at 48 kHz. Make the signal nonlinear by feeding it to a polynomial. Add noise. Set the random number generator to the default settings for reproducible results. Compute the third-order intercept point. Verify that the intermodulation products occur at 2f_2-f_1=4 kHz and 2f_1-f_2=7 kHz.

rng default
fi1 = 5e3;
fi2 = 6e3;
Fs = 48e3;
N = 1000;
x = sin(2*pi*fi1/Fs*(1:N))+sin(2*pi*fi2/Fs*(1:N));
y = polyval([0.5e-3 1e-7 0.1 3e-3],x)+1e-5*randn(1,N);

[myTOI,Pfund,Ffund,Pim3,Fim3] = toi(y,Fs);
myTOI,Fim3

% Copyright 2015 The MathWorks, Inc.