From what I gather, you are trying to find a faster way to roll through a set of indices into an array by using the ‘bitand’ operation.
To optimize the ‘bitand’ operation, you can use the following mathematical operations to replicate the behaviour of the same :
Here is an improved version of the ‘RxTask’ function:
function [R] = RxTaskOptimized()
c = uint32(zeros(1,4096));
Now to further optimize your code, you can check the following steps as well:
- You can recompute ‘x’ outside the loop as it stays the same in each iteration .
- Pre-allocation of ‘R’ can be done outside the loop to increase performance.
R(k) = RxTaskOptimized();
You can monitor the performance by using the MATLAB Profiler for both the methods:
Optimized function:
Original function:
Happy Coding!