function [x,y,n]=bs_generate_XY(N, example) % function [x,y,n]=bs_generate_XY(N, example ) % Generate to random variables with a non-zero linear relationship % Y = a*X + N % INPUTS: % N is the length of the generated vectors % example: there are 5 different examples % from class. % % EXAMPLE: % generate y using a Gaussian PDF for x and % a tringular PDF for n. Also enforce a signal % to noise of 2. % example_number=1; % N=1000; % [x,y,n]=bs_generate_XY(N, example_number) % % EAS-8803 - edl@gatech.edu if example ==1 x = bs_rand('norm', [0, 2 ], N, 1); n = bs_rand('norm', [0, 1 ], N, 1); n=n-mean(n); a=0.8; y = a*x; sn=2; n = n/std(n) * sqrt( var(y) / sn); y = a*x + n; disp(' '); disp( '- Generating X and Y with the following relationships:'); disp([' y = 0.8*x + n ']); disp([' PDF(X) = Gaussian (mean=0; var=2 )']); disp([' PDF(N) = Gaussian (mean=0; )']); disp([' Singal to noise ration SN=2 (SN=var(y)/var(n) )']); disp(' '); end if example ==2 x = bs_rand('norm', [0, 2 ], N, 1); n = bs_rand('tri', [-0.4, 0, 6], N, 1); n=n-mean(n); a=0.8; y = a*x; sn=2; n = n/std(n) * sqrt( var(y) / sn); y = a*x + n; disp(' '); disp( '- Generating X and Y with the following relationships:'); disp([' y = 0.8*x + n ']); disp([' PDF(X) = Gaussian (mean=0; var=2 )']); disp([' PDF(N) = Triangular (a=-0.4; b=6; c=0;)']); disp([' Singal to noise ration SN=2 (SN=var(y)/var(n) )']); disp(' '); end if example ==3 x = bs_rand('uniform', [0 18], N, 1); n = bs_rand('norm', [0, 15 ], N, 1); %n=n-mean(n); y = exp(x/2); sn=10; n = n/std(n) * sqrt( var(y) / sn); y = exp(x/2) + n; disp(' '); disp( '- Generating X and Y with the following relationships:'); disp([' y = exp(x/2) + n ']); disp([' PDF(X) = Uniform (a=0; b=18 )']); disp([' PDF(N) = Gaussian (mean=0; var=15 )']); disp([' Singal to noise ration SN=10 (SN=var(y)/var(n) )']); disp(' '); end if example ==4 x = bs_rand('norm', [2, 2 ], N, 1); n = bs_rand('lognormal', [], N, 1 ); %n=n-mean(n); a=0.8; y = a*x; sn=2; n = n/std(n) * sqrt( var(y) / sn); y = a*x + n; disp(' '); disp( '- Generating X and Y with the following relationships:'); disp([' y = 0.8*x + n ']); disp([' PDF(X) = Gaussian (mean=2; var=2 )']); disp([' PDF(N) = Lognormal (mean=0; )']); disp([' Singal to noise ration SN=2 (SN=var(y)/var(n) )']); disp(' '); end return