I'm trying to write in Matlab a script to create 3 signals, that have to be presented in the same graph (using plot). My code, in this moment, is
n = 0:80;
s = 2*n*(0.9).^n; %signal 1 (can be a real or an imaginary signal)
r = rand(1, 81) - 0.5; %signal 2 (can be a real or an imaginary signal)
x = s + r; %signal 3: it is supposed to be the sum of the other 2 signals
xr = real(x);
xi = imag(x);
x = xe + xi;
ER = XXX_A_B(x, s);
plot(n, s, n, r, n, x, n, ER); %plot
title('s[n], r[n], x[n], ER) %ER: Error related to the approximation of x to s
legend('s[n]', 'r[n]','x[n]', 'ER')
I had already done a function to compute ER, so I used it to calculate it now. The function is
function [ER] = XXX_A_B(x1, x2)
x = abs(x2-x1);
L2 = norm(x, 2);
L2_1 = norm(x1, 2);
ER = L2/L2_1;
end
It happens that already in the first line, it appears an error (not saying of what kind) and another on x = s + r. I'm not understanding the reason of these mistakes. Thanks.