02-25-2019 11:32 AM
I am trying to write code to an mcode block with this function:
function [z] = spreading(din)
persistent pr_sig, pr_sig = xl_state(zeros(1, 9),din);
pr_sig(1) = 1;
pr_sig(2) = 1;
pr_sig(3) = 0;
pr_sig(4) = 1;
pr_sig(5) = 1;
pr_sig(6) = 0;
pr_sig(7) = 0;
pr_sig(8) = 1;
persistent data1, data1 = xl_state(ones(1, 9),din);
persistent data2, data2 = xl_state(zeros(1, 9),din);
if din == 1
data1(i) = xl_xor(data1(i),pr_sig(i));
z = data1(i);
data2(i) = xl_xor(data2(i),pr_sig(i));
z = data2(i);
Essentially I want to take the input bit and my pseudo-random array (pr_sig) and bitwise XOR them together. Then I want to send the output out. This performs Direct sequence spreading. I know you can't output arrays, but I thought maybe this code would work. However I get this error:
output z is not assigned through all possible paths. A misspelling or a switch statement without otherwise statement may cause this error.
Anyone know what I am doing wrong?
Thank you for your time!!
02-26-2019 10:32 AM
You should have one return value for z.
Note that, in the below code, the value of 'z' is constant, but it is inside the loop, therefore code will generate the same error.
function [z] = spreading(din) for i = 1:8 z = 1; end
There should be one return value at the end of execution e.g.
function [z] = spreading(din) y = 0 for i = 1:8 y = i; end z = y;
02-26-2019 10:46 AM
Thank you for the prompt response. Unfortunately that won't work for me because for every input (din) I would like to output 8 different bits (z(8)). I am trying to insert spread spectrum this way. Is there another way to do this? Based on the code edits I would only output 1 value...