MATLAB: Imaginary part of a discrete time signal

imaginary partmatlab problemsin plot

n=0:12;
x=exp(i*3*pi*n);
stem(n,imag(x))
This code wont give the correct answer. The problems come from matlab can't plot sine function in our imaginary part. That is really strange because it can plot cos term easily.

Best Answer

Your signal is not sufficiently sampled. That is basically a Nyquist frequency curve so the real part is just peak-trough-peak-trough, etc. The peaks and troughs of the imaginary part fall sub-sample on such a badly sampled grid and so what you get from the plot misses out most of the key points and just plots those that fall on your sample grid. In the case of a pure sin and cos pair, these points will be all the zero-crossings.
Try something more like
n = linspace( 0, 12, 1000 );