i trying use persistent variable store previous samples in embedded matlab function. @ each step, 32 bit input storing persistent variable. output of embedded matlab function, once samples simulation time collected, trying send modulator. problem following: using random integer generator simulation time of 0.01s, block generates 626 integers spread 626x32 bits in embedded matlab function. 626x32 input current embedded matlab function persistent variables. output expect (626*32)x1 output getting 626x(626*32) i.e., there duplicate rows want avoid. can me this. code
function y = fcn(u) %#codegen persistent temp_store; persistent n; tsim = 0.01; sample_time = 1.6e-5; no_of_chips = 32; no_of_samples = round(tsim/sample_time); if isempty(n) %%initialize persistent variable n = 1; end if isempty(temp_store) %%initialize persistent variable temp_store = zeros(no_of_samples * no_of_chips,1); end %%storing samples persistent variable while(n <= no_of_samples) temp_store((n * no_of_chips)-(no_of_chips - 1): n * no_of_chips) = u; n = n + 1; end %% after collection of samples, output persistent variable if(n == no_of_samples + 1) y = uint8(temp_store); else y = uint8(zeros(no_of_samples * no_of_chips,1)); end end
Comments
Post a Comment