~ubuntu-branches/ubuntu/karmic/scilab/karmic

« back to all changes in this revision

Viewing changes to macros/auto/phasemag.sci

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2002-03-21 16:57:43 UTC
  • Revision ID: james.westby@ubuntu.com-20020321165743-e9mv12c1tb1plztg
Tags: upstream-2.6
ImportĀ upstreamĀ versionĀ 2.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
function [phi,db]=phasemag(z,mod)
 
2
//
 
3
// Copyright INRIA
 
4
mod_def='c'     //continuous representation
 
5
//mod_def='m'   //representation modulo 360 degrees
 
6
[lhs,rhs]=argn(0)
 
7
if lhs==2 then 
 
8
  db=20*log(abs(z))/log(10),
 
9
end
 
10
if rhs<>2 then 
 
11
  mod=mod_def
 
12
end
 
13
phi1=atan(-imag(z(:,1)),-real(z(:,1)))
 
14
[m,n]=size(z)
 
15
z=z(:,2:n)./z(:,1:n-1)
 
16
phi=[phi1 atan(imag(z),real(z))]
 
17
if n>1 then
 
18
  for l=1:m
 
19
    kk=find(abs(phi(l,2:n)-phi(l,1:n-1))>=2*%pi)
 
20
    if kk<>[] then phi(l,kk+ones(kk))=phi(l,kk),end
 
21
  end
 
22
end
 
23
 
 
24
phi=cumsum(phi,2)*(180/%pi)-180
 
25
 
 
26
//reset modulo 360
 
27
if part(mod,1)=='c' then
 
28
  mphi=maxi(phi)
 
29
  if mphi<=0 then 
 
30
    k=int(abs(mphi)/360)+1
 
31
    phi=phi+ones(phi)*360*k
 
32
  else
 
33
    k=int(mphi/360)+1
 
34
    phi=phi-ones(phi)*360*k
 
35
  end
 
36
else
 
37
  for l=1:m
 
38
    k=find(phi(l,:)>0)
 
39
    phi(l,:)=phi(l,:)-int(phi(l,:)/360)*360
 
40
    if k<>[] then phi(l,k)=phi(l,k)-360*ones(k),end
 
41
  end
 
42
end
 
43
 
 
44
 
 
45
 
 
46