Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

Revision 1dc429fc0da4cc5ff4f62617760447613f85980b authored by vbhandawat on 01 February 2021, 13:54:09 UTC, committed by GitHub on 01 February 2021, 13:54:09 UTC
Add files via upload
1 parent 17f20a6
  • Files
  • Changes
  • 345c390
  • /
  • Plotting
  • /
  • getAnalyticalSignal.m
Raw File Download
Permalinks

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • revision
  • directory
  • content
revision badge
swh:1:rev:1dc429fc0da4cc5ff4f62617760447613f85980b
directory badge Iframe embedding
swh:1:dir:ddb546bdf9afa165db506498058e495480e377c9
content badge Iframe embedding
swh:1:cnt:f1857876a1f87dd8cb6db8c299872d897413f70f
Citations

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • revision
  • directory
  • content
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
getAnalyticalSignal.m
%This function extracts analytical signal of leg position through hilbert
%transform.
%This function is called from cycle_analysis.m
%
%@Chanwoo Chun, <cc2465@cornell.edu> Jan. 18, 2019

function analyticalSignals=getAnalyticalSignal(legPosStruct,vStarts,vEnds)
legPosY(1,:)=legPosStruct.R1(:,2)';
legPosY(2,:)=legPosStruct.R2(:,2)';
legPosY(3,:)=legPosStruct.R3(:,2)';
legPosY(4,:)=legPosStruct.L1(:,2)';
legPosY(5,:)=legPosStruct.L2(:,2)';
legPosY(6,:)=legPosStruct.L3(:,2)';

allPhases = NaN(size(legPosY,1),size(legPosY,2));
%Get analytical signal in each valid section.
for i = 1:length(vStarts)
   %extract one valid section
   vLegPos=legPosY(:,vStarts(i):vEnds(i));
   phases=NaN(6,size(vLegPos,2));
   for legNum = 1:6
      %extract one leg
      stancePos=vLegPos(legNum,:);
      %find stance start and end times.
      %We first need to interpolate the swing phases.
      [starts, ends] = getStartsAndEnds(stancePos);
      if isempty(ends)
          continue
      end
      %loop through stance ends.
      for j = 1:length(ends)
         currentStanceEnd = ends(j); 
         nextStanceStart = min(starts(starts>currentStanceEnd));
         %for the last stance end, there could be no stance start after
         %that. In that case, omit the iteration.
         if isempty(nextStanceStart)
             continue
         end
         currentPos = stancePos(currentStanceEnd);
         nexPos = stancePos(nextStanceStart);
         numData = nextStanceStart-currentStanceEnd+1;
         %interpolate swing phase
         swingPos = interp1([1 numData],[currentPos nexPos],1:numData);
         
         %remove last and first frame because those are for stance phases.
         swingPos(end)=[];
         swingPos(1)=[];
         stancePos(currentStanceEnd+1:nextStanceStart-1)=swingPos;
      end
      cumsummed=cumsum(stancePos).*cumsum(stancePos,'reverse');
      stancePos(cumsummed==0)=nan;
      stancePos = stancePos - (max(stancePos,[],'omitnan')+min(stancePos,[],'omitnan'))/2;
      stancePos(cumsummed==0)=0;
      
      %Remember, this phase may include swing phases that couldn't be
      %interpolated, since they are at the beginning or end of the time
      %series. They were left as zeros. So do not believe the phase values
      %at the beginning or end. To fix this, we need the next step.
      phase = getPhases(stancePos);
      

      %Now we have leg position for stance and swing. However, if the time
      %series started with swing phase, the array will have one or more
      %zero(s) at the beginning. Also, if the time series ended with swing
      %phase, the array will have one or more zero(s) at the end. We will
      %replace these zeros will NaN. Once we do this for all the legs, we
      %will omit any time where at least one leg is in NaN state. We will
      %do that because we cannot get relative phase difference between the
      %legs, if one of the legs being compared is in NaN state.
      phase(cumsummed==0)=NaN;
      phases(legNum,:)=phase;
   end
   allPhases(:,vStarts(i):vEnds(i))=phases;
end

for legNum = 1:6
allPhases(legNum,isnan(sum(allPhases,1)))=NaN;
end

analyticalSignals=allPhases;
end

%% Get Phases of all six legs.
function phase = getPhases(signal)
    added = 1000;
    oriLength = length(signal);
    signal = padarray(signal, [0 added]);
    
    h = hilbert(signal);
    p = angle(h); % Instantaneous phase (wrapped)
    phase = p(added+1:oriLength+added);

end
The diff you're trying to view is too large. Only the first 1000 changed files have been loaded.
Showing with 0 additions and 0 deletions (0 / 0 diffs computed)
swh spinner

Computing file changes ...

Software Heritage — Copyright (C) 2015–2025, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Contact— JavaScript license information— Web API

back to top