Phase angle is producing an error

6 views (last 30 days)
Nathan Kennedy
Nathan Kennedy on 13 Feb 2018
Commented: Nathan Kennedy on 14 Feb 2018
Hi, I am getting a phase error on my waveform it is not quite reaching +pi or -pi in some cases(not everytime which I find strange). I think its leading to significant problems in other modules of my code. I have pin point the error to display quite nicely below. What is causing that?
clear all
% -- Controls --
f=5
Fs =100*f;
Ts = 1/Fs;
dt = 0 : Ts : 10/f;
% -- Waveform --
waveform = exp(1*i*((2*pi .* f .* dt) )) ;
waveform = waveform';
% -- Inspect Phase --
for a=1:length(waveform)
waveform_phase(a) = angle(waveform(a)); %radians
end
plot shows theres an error in phase, it is sometimes off the correct value of +pi or -pi
The below code has hline and vline - remove them if you don't have them but its more difficult to see the error
figure(1);cla;clf;
ax=gca; set(gca,'Fontsize',7)
yyaxis left
plot(dt,waveform_phase,'b','displayname','input phase','MarkerSize',4)
set(gca,'YTick',-pi:pi/2:pi)
set(gca,'YTickLabel',{'-\pi',' ','0',' ','\pi'})
ylabel('Phase (Radians)','Fontsize',7);
hline(pi,'--b')
hline(-pi,'--b')
yyaxis right
hold on
plot(dt,waveform,'r','displayname','input waveform')
set(gca)
ylim([min(real(waveform)) max(real(waveform))])
ylabel('Amplitude (V)','Fontsize',7);
hline(min(real(waveform)),'--r')
hline(max(real(waveform)),'--r')
legend('show','Location','southeast')
xlim([0 dt(end)/2])
xlabel('Time ','Fontsize',7);
Also If I increase sampling frequency its not noticeable by eye on the plot and the error is small, but still has effects in my overall code. I cant be having a sampling frequency 10000 above the max frequency to just measure phase?
  4 Comments
Adam
Adam on 14 Feb 2018
Yes, I get that also, but the value for that point is at precisely -pi which is the same thing as +pi as an angle. As you can see, you have placed exactly one arrow per trough, because each has its result at either +pi or -pi, which is what I said in my previous comment. It is not consistent, probably down to the vagueries of the fact that it is a discrete signal and in floating point accuracy so flips between -pi and +pi can happen in the same way you sometimes see things like -0 as well as 0.
If you unwrap the phase then it would be perfectly consistent.
Nathan Kennedy
Nathan Kennedy on 14 Feb 2018
Hi I tried using the unwrap function and it was not giving me a smooth plot. how isit implemented with my code?

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!