# Problem with plotting the magnitude and phase response of a signal in Matlab

Status
Not open for further replies.

#### scdoro

##### Member level 5 Hi all,

Below section of code asks to plot the magnitude and the phase response graph of the signal xn.

a = 0.88 * exp( j*2*pi/5 );
nn = 0:40;
xn = a.^nn;
for n = 128.

Qn1) when i typed in this section of code and try to run it using Matlab, it just keeps looping and there is no output. How can i make use of the above information to obtain the magnitude and phase response of the signal?
The full question is provided in the attachment

Thanks

P.S: i am new to matlab so i hope someone could helped me with this

regards
scdoro

#### hr_rezaee new to matlab

hi
a = 0.88 * exp( j*2*pi/5 );
nn = 0:40;
xn = a.^nn;
for n = 128

for n=1:128
...
end

see function abs() and angle() in matlab help.

#### Roshdy

##### Member level 3 Re: new to matlab

Also no output function used, you said that you want to "plot the magnitude and the phase" you have to use a plot function (eg. plot, semilogx,.....).

#### Element_115 Re: new to matlab

There is no "n" variable.

a = 0.88 * exp( j*2*pi/5 ); % This is a Complex number
nn = 0:40; % This is an array [1,2,3...39,40]
xn = a.^nn; % "xn" is a Complx # raised to a power "nn"
for n = 128. % this looks like it wants to be a loop w/128 iterations
% but nothing is done. Or a statement and "n" should be "nn", but "nn" MAX = 40!

Type plot(nn,xn) or plot(xn), and see if this helps you understand your original
question.

#### MSGHP

##### Junior Member level 1 new to matlab

% your signal is alittle strange because it's complex and so your frequency response don't have symetri in magnitude an asymetry in phase

a=0.88*exp(i*2*pi/5); % matlab use i instead of j
nn=0:40;
xn=a.^n;
n=128;
Xw=fftshift(fft(xn,n)); % u have to compute the frequency reponse by n sample
plot(0:n-1,abs(Xw)); % plots the magnitude of frequency responce
figure;
plot(0:n-1,angle(Xw)); % plots the phase