how to plot a phase-spectrum ?
- To: mathgroup at smc.vnet.net
- Subject: [mg41350] how to plot a phase-spectrum ?
- From: kroos059 at tref.nl (kroos059)
- Date: Thu, 15 May 2003 04:07:18 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
hello, i'm trying to plot a phase-spectrum, but it's giving me some problems. according to the example in the book, i should get a phase of -pi/2 at 1 and 16, pi/2 at 48 and 63 and the rest should be 0. unfortunaly i get a phase != 0 nearly everywhere. any help how to get a picture like the description above is very much appreciated. i'm using the following formulas: magitude=Sqrt[Re[a]^2+Im[a]^2] phase=ArcTan[ Im[a]/Re[a] ] with a as the spectral component what i've got: BigN=64; (* the signal: *) x[var_] := x[var] = Module[{n = Mod[var, BigN]},Sin[2*Pi*n/64] + Cos[2*Pi*n/16] +0.6*Cos[2*Pi*n/8] +0.5*Sin[2*Pi*n/4] ]; ReA[k_]:=ReA[k]=Module[{n},1/BigN*Sum[ ( x[n]*Cos[2*Pi*k*n/BigN] ),{n,0,BigN-1}] ]; ImA[k_]:=ImA[k]=Module[{n},1/BigN*Sum[ ( x[n]*-Sin[2*Pi*k*n/BigN] ),{n,0,BigN-1}] ]; magnitude[k_]:= magnitude[k]=Evaluate[Sqrt[ReA[k]^2 + ImA[k]^2 ] ]; phase[k_] := If[ReA[k] == 0, 0, ArcTan[ ImA[k]/ReA[k] ] ]; Plot[magnitude[n], {n, 0, 63}, PlotRange -> All] Plot[phase[n],{n,0,63}] i'm using a function to plot the 2 functions on integers only, but plot comes close enough for a general idea. -- Okke Experience is that marvelous thing that enables you recognize a mistake when you make it again. -- F. P. Jones