0
votes

I am trying to plot the following :

Im{X (e^jω)} = -a * sin(w) / (1 - 2*a*cos(w) + a^2) , where -1 < a < 0.

I am trying to plot it as a function of w. but for some reason I get only the line with 0 dots all along the y axes without any meaningful graph.

What is the best way to plot this function using Matlab?

Also how to properly plot a phase response if my response looks like this:

phase (X (ejω)) = tan^-1(-asin(w)/ 1 - acos(w)).

When I use angle() function the matlab throws error that X must be same length as Y. I am wondering if I do have to use functions such as imag() and angle() or just stem it without it. Currently my code is as follows:

a = -0.2;
N = 10;
w = -2*pi:2*pi/N:2*pi;
x_imag = - a.* sin(w)./(1 - 2 * a*cos(w) + a^2);
stem(w, imag(x_imag), 'filled')
x_phase = inv(tan(-a.*sin(w)./(1- a.*cos(w))))
stem(w, angle(x_phase), 'filled')

Where do I have a mistake?

2

2 Answers

1
votes

Since

Im{X (e^jω)} = -a * sin(w) / (1 - 2*a*cos(w) + a^2) , where -1 < a < 0.  

is the imaginary part of the equation, x_imag = - a.* sin(w)./(1 - 2 * a*cos(w) + a^2); doesn't have any imaginary part i.e. there's no i or j in the equation. For example consider the complex number:

c = 2 + 2i
% the imaginary part is 2 <- no i

Thus when you try to plot the imag of x_imag you will get all zeros since there's no imaginary part. In other words, just plot x_imag as is:

stem(w, x_imag, 'filled')

To get the phase of the number you need tan^-1 which in matlab is atan (inv is matrix inverse). Thus:

x_phase = atan(-a.*sin(w)./(1- a.*cos(w)))
stem(w, x_phase, 'filled')
1
votes

You do not need the imag operator in the plot. x_imag is the imaginary part and is not complex. So imag(x_imag) returns 0. Change

stem(w, imag(x_imag), 'filled')

to

stem(w, x_imag, 'filled')

For the phase you want to use atan for the arctangent. inv perofrms the matrix inverse. So change

x_phase = inv(tan(-a.*sin(w)./(1- a.*cos(w))))

to

x_phase = atan(-a.*sin(w)./(1- a.*cos(w))))