Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Continuous Relative Phase

Subject: Continuous Relative Phase

From: Alan Armstrong

Date: 29 Mar, 2011 15:28:03

Message: 1 of 2

Hi,

I am attempting to calculate continuous relative phase (CRP) using the equation: CRP(i) = atan (velocity(i)/displacement(i)). How ever when I run my code the plots do not appear to produce the correct results. From the raw plots of my original data the subject is clearly in anti-phase but according to the CRP plot the subject is basically at 0 degrees, in phase, for the entire test period.

I'm fairly certain that it is something basic in my equation but i have checked it several times and cannot seem to figure out what it is.


The code is below, Ignore the first section I just convert the data I have into degrees:

time = data(:,1);
signal_comp = data(:,2);
signal_subj = data(:,3);

% define angle

new_comp = zeros(size(time,1),1);
new_subj = zeros(size(time,1),1);

for row_counter = 1:size(time,1)
    
    new_comp(row_counter) = signal_comp(row_counter)+500;
    new_subj(row_counter) = signal_subj(row_counter)+500;
   
end


angle_comp = zeros(size(time,1),1);
angle_subj = zeros(size(time,1),1);

%convert the data into degrees

for row_counter = 1:size(time,1)
    
    angle_comp(row_counter) = new_comp(row_counter)*0.18;
    angle_subj(row_counter) = new_subj(row_counter)*0.18;
   
end

figure(1)
plot(time, angle_comp), hold on, plot(time, angle_subj, 'r')


angle_velocity_comp = zeros(size(time,1),1);
angle_velocity_subj = zeros(size(time,1),1);

for i = 2:size(angle_subj,1)
    
    angle_velocity_comp(i) = (angle_comp(i) - angle_comp(i-1)) / (time(i) - time(i-1));
    angle_velocity_subj(i) = (angle_subj(i) - angle_subj(i-1)) / (time(i) - time(i-1));
    
end

figure(2)
plot(time, angle_velocity_comp), hold on, plot (time, angle_velocity_subj, 'r')


%phase angle


phase_angle_comp = zeros(size(time,1),1);
phase_angle_subj = zeros(size(time,1),1);

for i = 1:size(angle_velocity_comp,1)
    
phase_angle_comp(i) = atan(angle_velocity_comp(i) / angle_comp(i));
phase_angle_subj(i) = atan(angle_velocity_comp(i) / angle_subj(i));

end

% Continuous Relative Phase (CRP)


CRP = (phase_angle_comp - phase_angle_subj);

figure(3)
plot(time, CRP)
title('CRP')



Thanks in advance,

Subject: Continuous Relative Phase

From: Roger Stafford

Date: 29 Mar, 2011 15:48:03

Message: 2 of 2

"Alan Armstrong" <alan.armstrong5@mail.dcu.ie> wrote in message <imstq3$ha$1@fred.mathworks.com>...
> Hi,
>
> I am attempting to calculate continuous relative phase (CRP) using the equation: CRP(i) = atan (velocity(i)/displacement(i)). How ever when I run my code the plots do not appear to produce the correct results. From the raw plots of my original data the subject is clearly in anti-phase but according to the CRP plot the subject is basically at 0 degrees, in phase, for the entire test period.
>
> I'm fairly certain that it is something basic in my equation but i have checked it several times and cannot seem to figure out what it is.
> .........
- - - - - - - - -
  The 'atan' function returns an angle in radians, not degrees, and they range only from -pi/2 to +pi/2. If you want angles that have a full circle range from -pi to +pi, you should use the 'atan2' function. If you want degrees, multiply these outputs by 180/pi.

Roger Stafford

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us