% % Example of using relational and logical operators to create arrays % that represent signals with discontinuities, or with other signals % replacing a segment of the original signal. % % Main idea: Multiply the values in an array you want to keep by ones, % and multiply all the other values by zeros. Then you can replace % the zero-ed out entries with other values by adding into them % signals which themselves have zeros on the segments you want to keep. % % Confusing explanation? Good. Then insert intermediate plots for the % intermediate values of the arrays y and z to see how the desired % signal vector is created. % % % For A321 course % % Last Modified: Mon 04 Feb 2008, 11:16 AM % x = linspace(1,10,1000); y = sin(x); z = (y >= 0).*y; % Gives array same as y, but with negatives values % set to zero z = z + 0.5*(y < 0); % Where sin(x) is negative, add 1/2 z = (x <= 8) .* z; % Set values past x = 8 to be zero plot(x, z ); xlabel('x'); ylabel('z = f(x)'); title('Discontinuous Signal Example (mostly from Hanselman and Littlefield)')