phase plot no giving the correct plot

1 view (last 30 days)
Satish Khanal
Satish Khanal on 19 Jul 2019
Answered: dpb on 19 Jul 2019
%clc;
%clear all;
%close all;
N=6;
n=0:N-1;
x=sin(2*pi*n/6);
for k=0:N-1
sum=0;
for n=0:N-1
A=exp(-j*k*((2*pi)/N)*n);
B=A*x(n+1);
sum=sum+B;
end
a(k+1)=sum/N;
end
a
mag=abs(a);
phase=angle(a);
k=0:N-1
subplot(2,1,1);
stem(k,mag);
title('magnitude plot 73020')
grid on;
subplot(2,1,2);
stem(k,phase);
title('phase plot 73020')
grid on;
the figure shows the output but the phase plot is not correct.

Answers (1)

dpb
dpb on 19 Jul 2019
Don't forget floating point precision...
>> real(a)
ans =
1.0e-15 *
0.0555 0.1665 0.0555 0.0185 -0.1295 -0.9899
>> imag(a)
ans =
0 -0.5000 0.0000 0.0000 0.0000 0.5000
>> real(a)<3*eps
ans =
1×6 logical array
1 1 1 1 1 1
>>
Perhaps what you were expecting was on the order of...
>> angle(complex(zeros(size(a)),imag(a)))
ans =
0 -1.5708 1.5708 1.5708 1.5708 1.5708
>>
But, the plot is correct given the input; as is the result of angle -- just not the same as the analytic solution.

Categories

Find more on Line Plots in Help Center and File Exchange

Products


Release

R2017a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!