There are welldefined functions in mathematica/matlab to reverse whatever you want.Maybe you can look at their codes and develop for your use.