why do we get different values by angle command
Show older comments
When i run this code i am getting the result as shown below
clc;clear all; close all;
N=input('Enter the fundamental period of the signal (N)');
M=input('Enter how many points of Fourier series to compute(m>N and m=multiples of N) ')
n=0:N-1;
x=[sin(2*pi*n/6)];
for k=0:M-1;
Sum=0;
for n=0:N-1;
Ck(k+1)=x(n+1)*exp(-j*2*pi*k*n/N);
Sum=Sum+Ck(k+1);
end
Ck(k+1)=Sum/N;
end
Mag=abs(Ck);Phase_ang=angle(Ck);
disp(Ck);disp(Mag);disp(Phase_ang);
Output
Enter the fundamental period of the signal (N)6
Enter how many points of Fourier series to compute(M=N or M=multiples of N) 6
M =
6
0.0000 + 0.0000i 0.0000 - 0.5000i -0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.5000i
0.0000 0.5000 0.0000 0.0000 0.0000 0.5000
0 -1.5708 2.9229 1.5075 0.0588 1.5708
The values of phase angle are supposed to be
0 -1.5708 0 0 0 1.5708
But for the same array if i use command window i get the proper result
>>angle([0.0000 + 0.0000i 0.0000 - 0.5000i -0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.5000i])
ans =
0 -1.5708 0 0 0 1.5708
2 Comments
"But for the same array..."
No, that is a different array, with different values. The values displayed (by default with four decimal places) are not the same as those stored in memory. So if you simply copy the displayed data, then you will have different values.
N=6;
M=6;
n=0:N-1;
x=sin(2*pi*n/6); % got rid of the superfluous square brackets
for k=0:M-1;
Sum=0;
for n=0:N-1;
Ck(k+1)=x(n+1)*exp(-j*2*pi*k*n/N);
Sum=Sum+Ck(k+1);
end
Ck(k+1)=Sum/N;
end
format long G
Ck
Kavita Guddad
on 9 Jun 2023
Accepted Answer
More Answers (0)
Categories
Find more on Calendar in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!