This page provides the computer code (written in MATLABTM) for Classwise Prinipal Component Analysis, as well as a tutorial on how to use the code. The original reference is:

K. Das, and Z. Nenadic, An efficient discriminant-based solution for small sample size problem, Pattern Recogn., vol. 42(5), pp. 857-866, 2009.

Therefore, if you end up using the code, I would expect you to give a proper credit by citing the reference above. The tutorial is provided in html and pdf formats.