======================3D_SPECTRUM================================ NEW FEATURES These are my personal cheatsheets designed to make access to detailed information much easier to find. In addition, some cut and paste code is being added to do the following. Calculate 3dB ---------Cut_and_Paste_Into_Formula Calculator-------------- Frequency_Hz=1/(2*3.14*R*C) R=1e3 =Resistance_Ohms C=1e-6=Capacitance_Farad ----------------------------------------------------------- Formula Calculator http://www.idea2ic.com/PlayWithJavascript/Formula_calculator.html Plot a graph ---------Cut_and_Paste_Into_A_SciLab_Window-------------- x = linspace(-10, 10, 5) // x = - 10. - 5. 0. 5. 10. x = linspace(-10, 10, 1000); // x from -10 to 10 in 1000 steps y = 2*sin(x) + 3*sin(2*x) ; plot2d(x,y) // x y plot ----------------------------------------------------------- SCILAB_Templates http://www.idea2ic.com/PlayWithFink/scilab_Picture/SCILAB%20Templates.html Don Sauer 10/17/09 dsauersanjose@aol.com -------------------------------------------------------------------------------------- 3D_Spectrum Tayler discovered that an alternative ways to express a function was to use a power series. This new way of looking at sine and cosine functions lead to the discovery that they were related to the exponental function. COS(X) = 1 - X^2/2 + X^4/(4*3*2) +..etc SIN(X) = + X + X^3/(3*2) +..etc EXP(X) = 1 + X + X^2/2 + X^3/(3*2) + X^4/(4*3*2) +..etc By using complex numbers, Euler was able to find the following relationship. EXP(j*X) = COS(X) -j*SIN(X) In the form below , this relationship effectly translates a time function into a spectrum function. COS(X) = EXP(j*X)/2 +EXP(-j*X)/2 SIN(X) = j*EXP(j*X)/2 -j*EXP(-j*X)/2 -------------------------------------------------------------------------------------- A sine wave really needs only three data points to completely define it. By looking at a spectrum, if you know the amplitude and frequency, you still can't relate it to time. You need to know when the sinewave crosses zero in terms of time. In other words, you need to know phase information. Suppose you have a 5Hz signal that has a peak amplitude of 3volts. That is saying that the X term will be 2*PI for every 1/5th of a second. This is expressed below. function(time) = 3*SIN(2*PI*5Hz*time) <--ignoring phase It is traditional to replace a the 2*PI*Freq term with a single unit call Omega or "w". w = 2*PI*Freq If the amplitude is expressed as the term AMP, then.. function(time) = AMP*SIN(2*PI*5Hz*time) <--ignoring phase ^ /_\ | __-----__ | __/ \ _ | _/ \_ _ _|/ _ _ _ _ _ _ _ _ _ \_ _ _ _ _ _ _ _ _ _ _ _ \ | \_ _/ / | \__ __/ | \__ ___/ | ----- To know phase, one has to know in time when the sinewave crosses zero. If at time "zero" the signal is zero, you have a "SINE" wave. Now with the three data points..(Frequency, Amplitude, Phase), you know the signal in terms of voltage versus time. function(time) = AMP*SIN(2*PI*5Hz*time) -------------------------------------------------------------------------------------- It is common to express the magnitude and phase of something in terms of a complex number. The ratio to the real to imaginary values of give the phase while the combine distance of the real and imaginary parts give the magnitude. REAL ^ X = valueR +jvalueI /_\ | valueR .|.. __ Magnitude | /| | / : | / __-- Phase | /_--: IMAGINARY |/-___:____________\ : / jvalueI By adding one more dimension to represent frequency, the Euler relationship shows an alternative way to view Frequency, Amplitude, and Phase. Remmenber SIN(X) = j*EXP(j*X)/2 -j*EXP(-j*X)/2 So the function of time can be viewed as a function of frequency. The sine wave is mapped as two vectors along the jw axis. function(time) = AMP*SIN(2*PI*5Hz*time) AMP*SIN(w*t) = j*AMP*EXP(j*w*t)/2 - j*AMP*EXP(-j*w*t)/2 REAL MAGNITUDE ^ /_\ | \ | \ | #### See SciLab_Templates below ##### \ | \ | \ | /______\ <--|- -j*AMP*EXP(-j*w*t)/2 \ \ | \ | \ | IMAGINARY MAGNITUDE \|__________________\ \ / \ \ j*AMP*EXP(j*w*t)/2---> \______\ <--Magnitude = AMP \ / <--Direction = Phase \ <--Position = Freq \ _V J_OMEGA These vectors always come in pairs ( jw and -jw). Where a vector is, how large it is, and which way it is pointed tells frequency, amplitude, and phase. -------------------------------------------------------------------------------------- If the phase of the signal happened to be a COSINE, then the 3D spectrum would look like... (Amplitude) REAL MAGNITUDE ^ /|\ | \ | \ | \ ^ | #### See SciLab_Templates below ##### \ /|\ | \ | | \| | AMP*EXP(-j*w*t)/2 \ | \ | (90degree Amplitude) \ | IMAGINARY MAGNITUDE \|__________________\ \ ^ / \ /|\ \ | \| AMP*EXP(j*w*t)/2 \ \ \ \ _V J_OMEGA (frequency) -------------------------------------------------------------------------------------- 3D_Amplitude_Modulation_COS ________________\_ _ _\_ _ _\ 1001KHz at 0 degrees / / / 1000KHz at 0 degrees 999KHz at 0 degrees _ /| / 1001KHz leads 45 degree ________________\/ 1000KHz at 0 degrees /\ 999KHz lag by 45 degrees \ _\| ^ /|\ | 1001KHz leads 90 degree ________________\| 1000KHz at 0 degrees /| 999KHz lag by 90 degrees | \|/ V _ /\ \ 1001KHz leads 135 degree ________________\ 1000KHz at 0 degrees / 999KHz lag by 135 degree / |/_ 1001KHz leads 180 degree ______/ _ _/ _ _\ 1000KHz at 0 degrees \ \ / 999KHz lag by 180 degree ^ (Amplitude) /|\ REAL MAGNITUDE \ | ^ \ ^ | /|\ \ /|\| | \ | | | \| | | \ | ^ | #### See SciLab_Templates below ##### \|/|\ | \ | | \| | \ | ~etc~| ^ \ | /|\ IMAGINARY \|_____|____________\ \ ^ | / \ /|\| MAGANITUDE ~etc~| | \| | \ | ^ \|/|\ \ | \| \ _V J_OMEGA (frequency) -------------------------------------------------------------------------------------- 3D_Amplitude_Modulation_SIN ^ /_\ | __--|--__ __-----__ Sine lags 90 cosine __/ | _\/_ \__ _/ | _/ \_ \_ _ _ / _ _ _ _ |/_ _ _ _ \_ _ _ _ _ \_ _ _ _ _ _ _ \ | \_ \ _/ / | \__ __/ | \__ ___/ ----- _ _ _/| | | | | _ _ | | | | | | | \ / | | | | | | | | | _ | | | | | | | | | | | \ _ | | | | | | | | | | | | _ / | | | | | | | | | | | | | | | | __ _/| | | | | | | | | | | | | | | | | | | | --- | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | -- |_| | | | | | | | | | | | | | | | | | |/ |_| | | | | | | | | | | | | | |_/ | | | | | | | | | | | | | \_| | | | | | | | | |_/ \_| | | | | | | |_| |_| |/ ^ /|\ | 1001KHz lags 90 degree ________________\| 1000KHz at 0 degrees /| 999KHz leads by 90 degrees | \|/ V _ /| / 1001KHz lags 45 degree ________________\/ 1000KHz at 0 degrees /\ 999KHz leads by 45 degrees \ _\| ________________\_ _ _\_ _ _\ 1001KHz at 0 degrees / / / 1000KHz at 0 degrees 999KHz at 0 degrees ^ (Amplitude) /|\ REAL MAGNITUDE \ | ^ \ | /|\ \ | | \ | | /____\ | | #### See SciLab_Templates below ##### \ \ | | \| | \ | \____|\ \ |/ ~etc~| ^ \ | /|\ IMAGINARY \|_____|____________\ \ | / \ | MAGANITUDE ~etc~ | /____\ | \ \ | \| \ \____\ \ / _V J_OMEGA (frequency) ---------------3DS_Phase_Modulation--------------------- ^ /|\ | __--|--__ __-----__ Sine lags 90 cosine __/ | _\/_ \__ _/ | _/ \_ \_ _ _ / _ _ _ _ |/_ _ _ _ \_ _ _ _ _ \_ _ _ _ _ _ _ \ | \_ \ _/ / | \__ __/ | \__ ___/ ----- _________________\ /| 1000KHz at 0 degrees | 1001KHz lags 90 degrees \|/ 999KHz lags 90 degrees V | | \|/ V __________________\ 1000KHz at 0 degrees /\ 1001KHz lags 45 degrees / \ 999KHz lags 135 degrees |/_ _\| ___________/_ _ _\_ _ _\ 1000KHz at 0 degrees \ / / 1001KHz lags 0 degrees 999KHz lags 180 degree _ _ |\ /| \ / 1001KHz leads 45 degrees ________________\/ 1000KHz at 0 degrees / 999KHz lags 225 degree ^ /|\ | 1001KHz leads 90 degrees | 1000KHz at 0 degrees ^ 999KHz lags 270 degree /|\ | ________________\| / ^ (Amplitude) /|\ REAL MAGNITUDE \ | ^ \ | /|\ \ | | \ | | /____\ | | \ \ | | #### See SciLab_Templates below ##### \| | \ | /____\ | \ \ | ~etc~| ^ \ | /|\ IMAGINARY \|_____|____________\ \ | / \ | MAGANITUDE ~etc~ | \__|_\ \ | / \| \ \____\ \ / _V J_OMEGA (frequency) ----------------FM_2_PM------------------- _ _ _ _ _ _ _ _ _ _ _ _ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| | Pure sign wave (no FM) _ _ __ __ _ _ _ _ _ _ | | | | | | | | | | | | | | [|[| | | | | | | | | | | | | | | | | | | | |||| | | | | | | | | | | | | | | | | | | | |||| | | | | | | | | | | | | | | | | | | | |||| | | | | | | |_| |_| |__| |_| |_| |_| |_|L||_| |_| |_| A Moving sign wave Frequency Modulate a 1kHz carrier with a 1Hz signwave Freq(t) = [ 1000 + sin(2*PI*t) ] Signal= sin( (Freq(t))*2*PI*t) <--FM format at time = 1/4 The Frequency is 1001 Hz at time = 3/4 The Frequency is 999 Hz Another way to think of it is Phase Modulation... Signal= sin( (1000)*2*PI*t +Phase(t)) <-- PM format the phase will be Integral of FM ... _ / Phase(t) = | 2*PI*sin(2*PI*t)*dt = -cos(2*PI*t) _/ So 1Hz peak FM over 1Hz will generate 1radian peak of PM And to convert FM to PM, just integrate and One Hz FM at One Hz equals One radian PM The PM will lag the FM which causes it. ^ /|\ Freq=1001Hz| Phase= +1radian __--|--__ __-----__ __/ | _\/_ \__ _/ | _/ \_ \_ _ _ / _ _ _ _ |/_ _ _ _ \_ _ _ _ _ \_ _ _ _ _ _ _ \ _/| \_ \_ _/ / __/ | \__ \__ __/ TIME __/ | \__ ___/___ ---- ----- ---- Phase= -1radian Freq=999Hz -------------------------------------------------------------------------------------- FFT_SINE Using Excel to FFT signwaves ^ /|\ Signal = SIN(2*P()*Num/8) | __--S--__ | __S \S_ | _/ \_ _ _S/ _ _ _ _ _ _ _ _ _ \S _ _ _ _ _ _ _ _ _ _ _ \ | \_ _/ / | \__ __/ | S__ ___S | --S-- Num Samp FFt 0 0 0 1 .71 -4i 2 1 0 3 .71 0 4 0 0 5 -.71 0 6 -1 0 7 -.71 4i REAL MAGNITUDE ^ /|\ | \ | \ | /______\ | \ \ | \ | #### See SciLab_Templates below ##### Nyq\__ | \ | \ | \_|____\ \|____/_____________\ -4j /______\ / @bin1 \ \ IMAGINARY MAGNITUDE \ Nyq\__ \ \ \______\ +4j \ / @bin7 _V J_OMEGA -------------------------------------------------------------------------------------- FFT_NYQ ^ /|\ Signal = SIN(2*P()*Num/8) S_ S S S | \ / \ / \ / \ | \ / \ / \ / \ _ _|_ _|_ _|_ _|_ _|_ _|_ _| _ \ _ _ _ \ | | | | | | | | | / | \ / \ / \ / \ / | \S/ \S/ \S/ \S/ | Num Samp FFt 0 1 0 Real \ 1 -1 0 Complex | 2 1 0 Complex | 8 data points in/out 3 -1 0 Complex | 4 1 8 Real / 5 -1 0 6 1 0 7 -1 4 ^ REAL MAGNITUDE ^ /|\ /|\ | | | \ | | \ | | \ | | #### See SciLab_Templates below ##### \ | | \ | | Nyq\| | ^ \ | /|\ \ | | 8 at @bin4 \ | | \|___|_________________\ \ | / \ | IMAGINARY MAGNITUDE \ | Nyq\| \ \ \ \ _V J_OMEGA -------------------------------------------------------------------------------------- SciLab_Templates Cut and paste into a SciLab command window to run 3D plots of the FFT (Use mouse to view better) Plot_Cos_In_3D =================SciLab_Template========================= ns =10000; // set sample rate @ 10K samples/sec x = linspace(0,1,ns ); // make 1000 x points from 0-> 1 secs [nc,nr]=size(x); // find size of array yc = cos(2*%pi*50*x) ; // make carrier signal 50Hz for i=1:nr, y(i)= yc(i) ; end; // modulate here yfft = fft(y); // fft retain only first N/2 points f = nr*(0:(nr/2))/nr; // create frequency vector nf=size(f,'*') // check size of freq vector fr= real(yfft(1:nf)/nr); // find real of fft fi= imag(yfft(1:nf)/nr); // find imag of fft for i=1:100, b(i) =i ; end; // make a bin array to plot first 100 bins param3d( b/100, fi(b),fr(b),-35,57,"jw_Hz/100@imag@real",[1,4],[-1,1,-1,1,-1,1]); param3d(-b/100,-fi(b),fr(b),-35,57,"jw_Hz/100@imag@real",[1,4],[-1,1,-1,1,-1,1]); for i=1:100, zer(i) =0 ; end; //make a zero array param3d(zer(b),b/100,zer(b),-35,57,"jw_Hz/100@imag@real",[1,4],[-1,1,-1,1,-1,1]); e=gce(); e.foreground=color('red'); //the handle on the 3D polyline param3d(zer(b),-b/100,zer(b),-35,57,"jw_Hz/100@imag@real",[1,4],[-1,1,-1,1,-1,1]); e=gce(); e.foreground=color('red'); //the handle on the 3D polyline param3d(zer(b),zer(b),-b/100,-35,57,"jw_Hz/100@imag@real",[1,4],[-1,1,-1,1,-1,1]); e=gce(); e.foreground=color('red'); //the handle on the 3D polyline param3d(zer(b),zer(b),b/100,-35,57,"jw_Hz/100@imag@real",[1,4],[-1,1,-1,1,-1,1]); e=gce(); e.foreground=color('red'); //the handle on the 3D polyline xtitle("cos(w) = exp(jw)/2 +exp(-jw)/2 w = radians/sec w = 2*Pi*freq sin(w) = -j*exp(jw)/2 +j*exp(-jw)/2") Plot_Sine_In_3D =================SciLab_Template========================= ns =10000; // set sample rate @ 10K samples/sec x = linspace(0,1,ns ); // make 1000 x points from 0-> 1 secs [nc,nr]=size(x); // find size of array yc = sin(2*%pi*50*x) ; // make carrier signal 50Hz for i=1:nr, y(i)= yc(i) ; end; // modulate here yfft = fft(y); // fft retain only first N/2 points f = nr*(0:(nr/2))/nr; // create frequency vector nf=size(f,'*') // check size of freq vector fr= real(yfft(1:nf)/nr); // find real of fft fi= imag(yfft(1:nf)/nr); // find imag of fft for i=1:100, b(i) =i ; end; // make a bin array to plot first 100 bins param3d( b/100, fi(b),fr(b),-35,57,"jw_Hz/100@imag@real",[1,4],[-1,1,-1,1,-1,1]); param3d(-b/100,-fi(b),fr(b),-35,57,"jw_Hz/100@imag@real",[1,4],[-1,1,-1,1,-1,1]); for i=1:100, zer(i) =0 ; end; //make a zero array param3d(zer(b),b/100,zer(b),-35,57,"jw_Hz/100@imag@real",[1,4],[-1,1,-1,1,-1,1]); e=gce(); e.foreground=color('red'); //the handle on the 3D polyline param3d(zer(b),-b/100,zer(b),-35,57,"jw_Hz/100@imag@real",[1,4],[-1,1,-1,1,-1,1]); e=gce(); e.foreground=color('red'); //the handle on the 3D polyline param3d(zer(b),zer(b),-b/100,-35,57,"jw_Hz/100@imag@real",[1,4],[-1,1,-1,1,-1,1]); e=gce(); e.foreground=color('red'); //the handle on the 3D polyline param3d(zer(b),zer(b),b/100,-35,57,"jw_Hz/100@imag@real",[1,4],[-1,1,-1,1,-1,1]); e=gce(); e.foreground=color('red'); //the handle on the 3D polyline xtitle("cos(w) = exp(jw)/2 +exp(-jw)/2 w = radians/sec w = 2*Pi*freq sin(w) = -j*exp(jw)/2 +j*exp(-jw)/2") Plot_Cos_AM_3D =================SciLab_Template========================= ns =10000; // set sample rate @ 10K samples/sec x = linspace(0,1,ns ); // make 1000 x points from 0-> 1 secs [nc,nr]=size(x); // find size of array ym = 1+cos(2*%pi*5*x); // make modulation signal 5Hz yc = cos(2*%pi*50*x); // make carrier signal 50Hz for i=1:nr, y(i)=ym(i)*yc(i) ; end; // Amplitude modulate yfft = fft(y); // fft retain only first N/2 points f = nr*(0:(nr/2))/nr; // create frequency vector nf=size(f,'*') // check size of freq vector fr= real(yfft(1:nf)/nr); // find real of fft fi= imag(yfft(1:nf)/nr); // find imag of fft for i=1:100, b(i) =i ; end; // make a bin array to plot first 100 bins param3d( b/100, fi(b),fr(b),-35,57,"jw_Hz/100@imag@real",[1,4],[-1,1,-1,1,-1,1]); param3d(-b/100,-fi(b),fr(b),-35,57,"jw_Hz/100@imag@real",[1,4],[-1,1,-1,1,-1,1]); for i=1:100, zer(i) =0 ; end; //make a zero array param3d(zer(b),b/100,zer(b),-35,57,"jw_Hz/100@imag@real",[1,4],[-1,1,-1,1,-1,1]); e=gce(); e.foreground=color('red'); //the handle on the 3D polyline param3d(zer(b),-b/100,zer(b),-35,57,"jw_Hz/100@imag@real",[1,4],[-1,1,-1,1,-1,1]); e=gce(); e.foreground=color('red'); //the handle on the 3D polyline param3d(zer(b),zer(b),-b/100,-35,57,"jw_Hz/100@imag@real",[1,4],[-1,1,-1,1,-1,1]); e=gce(); e.foreground=color('red'); //the handle on the 3D polyline param3d(zer(b),zer(b),b/100,-35,57,"jw_Hz/100@imag@real",[1,4],[-1,1,-1,1,-1,1]); e=gce(); e.foreground=color('red'); //the handle on the 3D polyline xtitle("cos(w) = exp(jw)/2 +exp(-jw)/2 w= radians/sec w = 2*Pi*freq sin(w) = -j*exp(jw)/2 +j*exp(-jw)/2") Plot_Sine_AM_3D =================SciLab_Template========================= ns =10000; // set sample rate @ 10K samples/sec x = linspace(0,1,ns ); // make 1000 x points from 0-> 1 secs [nc,nr]=size(x); // find size of array ym = 1+sin(2*%pi*5*x); // make modulation signal 5Hz yc = cos(2*%pi*50*x); // make carrier signal 50Hz for i=1:nr, y(i)=ym(i)*yc(i) ; end; // Amplitude modulate yfft = fft(y); // fft retain only first N/2 points f = nr*(0:(nr/2))/nr; // create frequency vector nf=size(f,'*') // check size of freq vector fr= real(yfft(1:nf)/nr); // find real of fft fi= imag(yfft(1:nf)/nr); // find imag of fft for i=1:100, b(i) =i ; end; // make a bin array to plot first 100 bins param3d( b/100, fi(b),fr(b),-35,57,"jw_Hz/100@imag@real",[1,4],[-1,1,-1,1,-1,1]); param3d(-b/100,-fi(b),fr(b),-35,57,"jw_Hz/100@imag@real",[1,4],[-1,1,-1,1,-1,1]); for i=1:100, zer(i) =0 ; end; //make a zero array param3d(zer(b),b/100,zer(b),-35,57,"jw_Hz/100@imag@real",[1,4],[-1,1,-1,1,-1,1]); e=gce(); e.foreground=color('red'); //the handle on the 3D polyline param3d(zer(b),-b/100,zer(b),-35,57,"jw_Hz/100@imag@real",[1,4],[-1,1,-1,1,-1,1]); e=gce(); e.foreground=color('red'); //the handle on the 3D polyline param3d(zer(b),zer(b),-b/100,-35,57,"jw_Hz/100@imag@real",[1,4],[-1,1,-1,1,-1,1]); e=gce(); e.foreground=color('red'); //the handle on the 3D polyline param3d(zer(b),zer(b),b/100,-35,57,"jw_Hz/100@imag@real",[1,4],[-1,1,-1,1,-1,1]); e=gce(); e.foreground=color('red'); //the handle on the 3D polyline xtitle("cos(w) = exp(jw)/2 +exp(-jw)/2 w =radians/sec w = 2*Pi*freq sin(w) = -j*exp(jw)/2 +j*exp(-jw)/2") -------------------------------------------------------------------------------------- FM_2_PM _ _ _ _ _ _ _ _ _ _ _ _ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| | Pure sign wave _ _ __ __ _ _ _ _ _ _ | | | | | | | | | | | | | | [|[| | | | | | | | | | | | | | | | | | | | |||| | | | | | | | | | | | | | | | | | | | |||| | | | | | | | | | | | | | | | | | | | |||| | | | | | | |_| |_| |__| |_| |_| |_| |_|L||_| |_| |_| A Moving sign wave Frequency Modulate a 1kHz carrier with a 1Hz signwave Freq(t) = [ 1000 + sin(2*PI*t) ] Signal= sin( (Freq(t))*2*PI*t) <--FM format at time = 1/4 The Frequency is 1001 Hz at time = 3/4 The Frequency is 999 Hz Another way to think of it is Phase Modulation... Signal= sin( (1000)*2*PI*t +Phase(t)) <-- PM format the phase will be Integral of FM ... _ / Phase(t) = | 2*PI*sin(2*PI*t)*dt = -cos(2*PI*t) _/ So 1Hz peak FM over 1Hz will generate 1radian peak of PM And to convert FM to PM, just integrate and One Hz FM at One Hz equals One radian PM The PM will lag the FM which causes it. ^ /|\ Freq=1001Hz| Phase= +1radian __--|--__ __-----__ __/ | _\/_ \__ _/ | _/ \_ \_ _ _ / _ _ _ _ |/_ _ _ _ \_ _ _ _ _ \_ _ _ _ _ _ _ \ _/| \_ \_ _/ / __/ | \__ \__ __/ TIME __/ | \__ ___/___ ---- ----- ---- Phase= -1radian Freq=999Hz --------------------------------------------------------------------------------------