add legacy matlab code