rewritten SWT in matlab m language