%% Authors  : Manuel LUQUE <Mluque5130@aol.com>
%%            Christophe JORSSEN <Christophe.Jorssen@wanadoo.fr>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\fileversion{2.7}
\def\filedate{99/11/02}

\message{`PST-osci' v\fileversion, \filedate\space (Manuel LUQUE & Christophe
JORSSEN)}

\csname PSTOscilloLoaded\endcsname
\let\PSTOscilloLoaded\endinput

% Require PSTricks, pstcol,pstplot and multido packages
\ifx\PSTplotLoaded\endinput\else\input pst-plot.tex\fi
\ifx\MultidoLoaded\endinput\else\input multido.tex\fi

% DPC interface to the `keyval' package (until keyval based version of PSTricks)
\input pst-key.tex

\edef\PstAtCode{\the\catcode`\@} \catcode`\@=11\relax

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\font\ssf=cmss10
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newrgbcolor{Beige}{0.96 0.96 0.86}
\newrgbcolor{LightGray}{0.8 0.8 0.8}
\newrgbcolor{VeryLightGray}{0.9 0.9 0.9}
\newcmykcolor{PaleOrange}{0 0.2 0.4 0}
\newcmykcolor{LightBlue}{0.1 0 0 0}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\define@key{psset}{period1}{\edef\psk@Oscillo@PeriodA{#1}}
\define@key{psset}{period2}{\edef\psk@Oscillo@PeriodB{#1}}
\define@key{psset}{periodmodulation1}{\edef\psk@Oscillo@PeriodModulationA{#1}}
\define@key{psset}{freqmod1}{\edef\psk@Oscillo@FreqModA{#1}}
\define@key{psset}{periodmodulation2}{\edef\psk@Oscillo@PeriodModulationB{#1}}
\define@key{psset}{freqmod2}{\edef\psk@Oscillo@FreqModB{#1}}
\define@key{psset}{amplitude1}{\edef\psk@Oscillo@AmplitudeA{#1}}
\define@key{psset}{amplitude2}{\edef\psk@Oscillo@AmplitudeB{#1}}
\define@key{psset}{CC1}{\edef\psk@Oscillo@ContinuousComponentA{#1}}
\define@key{psset}{CC2}{\edef\psk@Oscillo@ContinuousComponentB{#1}}
\define@key{psset}{timediv}{\edef\psk@Oscillo@TimeDiv{#1}}
\define@key{psset}{phase1}{\edef\psk@Oscillo@PhaseA{#1}}
\define@key{psset}{phase2}{\edef\psk@Oscillo@PhaseB{#1}}
\define@key{psset}{sensivity1}{\edef\psk@ChannelA{#1}}
\define@key{psset}{sensivity2}{\edef\psk@ChannelB{#1}}
\define@key{psset}{damping1}{\edef\psk@Oscillo@dampingA{#1}}
\define@key{psset}{damping2}{\edef\psk@Oscillo@dampingB{#1}}
\define@key{psset}{Fourier}{\edef\psk@Oscillo@Fourier{#1}}
\define@key{psset}{offset1}{\edef\psk@Oscillo@OffsetA{#1}}
\define@key{psset}{offset2}{\edef\psk@Oscillo@OffsetB{#1}}
\define@key{psset}{offset3}{\edef\psk@Oscillo@OffsetC{#1}}
\define@key{psset}{plotstyle1}{\edef\psk@Oscillo@PlotStyleA{#1}}
\define@key{psset}{plotstyle2}{\edef\psk@Oscillo@PlotStyleB{#1}}
\define@key{psset}{plotstyle3}{\edef\psk@Oscillo@PlotStyleC{#1}}
\define@key{psset}{plotstyle4}{\edef\psk@Oscillo@PlotStyleD{#1}}
\define@key{psset}{operation}{%
\def\@tempa{#1}%
\let\psk@Oscillo@Operation\@tempa}

\define@key{psset}{Wave1}{%
\def\@tempa{#1}%
\let\psk@Oscillo@WaveA\@tempa}

\define@key{psset}{Wave2}{%
\def\@tempa{#1}%
\let\psk@Oscillo@WaveB\@tempa}

\newif\ifPst@Oscillo@Lissajous
\define@key{psset}{Lissajous}[true]{%
\@nameuse{Pst@Oscillo@Lissajous#1}}

\newif\ifPst@Oscillo@Combine
\define@key{psset}{combine}[true]{%
\@nameuse{Pst@Oscillo@Combine#1}}

\setkeys{psset}{period1=20,period2=20,amplitude1=2,amplitude2=0,%
phase1=0,phase2=0,timediv=5,Lissajous=false,sensivity1=1,%
sensivity2=1,damping1=0,damping2=0,combine=false,%
offset1=0,offset2=0,plotstyle1=GreenContA,Fourier=100,%
plotstyle2=BlueContB,plotstyle3=RedContLissajou,%
plotstyle4=MagentaContAddSub,operation=\relax,Wave1=\SinusA,Wave2=\SinusB,%
periodmodulation1=100,freqmod1=0,periodmodulation2=100,freqmod2=0,CC1=0,CC2=0,offset3=0}

\newpsstyle{GreenContA}{linecolor=green,%
linewidth=0.05,plotpoints=360}
\newpsstyle{BlueContB}{linecolor=blue,%
linewidth=0.05,plotpoints=360}
\newpsstyle{RedContLissajou}{linecolor=red,%
linewidth=0.05,plotpoints=1000}
\newpsstyle{MagentaContAddSub}{linecolor=magenta,%
linewidth=0.05,plotpoints=1000}

\def\TriangleA{%
/Cste 0.4050284 def % 4/pi^2
/A1 \psk@Oscillo@AmplitudeA\space 2 mul def % Amplitude peak to peak
0 1 2 fourier{
/n exch def
t 10 mul T1 div BT mul
n mul cos
n n mul div  Cste mul A1 mul add
}for  e t AR1 mul neg exp mul SA div CC1 add}

\def\TriangleB{%
/Cste 0.4050284 def % 4/pi^2
/A2 \psk@Oscillo@AmplitudeB\space 2 mul def
0 1 2 fourier{
/n exch def
t 10 mul T2 div BT mul
n mul cos
n n mul div  Cste mul A2 mul add
}for e t AR2 mul neg exp mul SB div CC2 add}

\def\RectangleA{
/Cste 0.6366 def
/A1 \psk@Oscillo@AmplitudeA\space 2 mul def
0 1 2 fourier{ %
/n exch def
t 10 mul T1 div BT mul
n mul sin
n div Cste mul A1 mul add %
}for
e t AR1 mul neg exp mul SA div CC1 add}

\def\RectangleB{
/Cste 0.6366 def
/A2 \psk@Oscillo@AmplitudeB\space 2 mul def
0 1 2 fourier{ %
/n exch def
t 10 mul T2 div BT mul
n mul sin
n div Cste mul A2 mul add %
}for
e t AR2 mul neg exp mul SB div CC2 add}

\def\RDogToothA{
/Cste 0.6366 def /timediv 5 def
0 1 1 fourier{ %
/n exch def
t 10 mul T1 div BT mul
n mul sin
n div -1 1 n add exp mul Cste mul A1 mul add%
}for
e t AR1 mul neg exp mul SA div CC1 add}

\def\RDogToothB{
/Cste 0.6366 def /timediv 5 def
0 1 1 fourier{%
/n exch def
t 10 mul T2 div BT mul
n mul sin
n  div -1 1  n add exp mul Cste mul A2 mul add%
}for
SB div CC2 add}

\def\LDogToothA{
/Cste 0.6366 def /timediv 5 def t
0 1 1 fourier{%
/n exch def
t 10 mul T1 div BT mul
n mul sin
n  div 180 n mul cos mul Cste mul A1 mul add%
}for
e t AR1 mul neg exp mul SA div CC1 add}

\def\LDogToothB{
/Cste 0.6366 def /timediv 5 def
0 1 1 fourier{%
/n exch def
t 10 mul T2 div BT mul
n mul sin
n div 180 n mul cos mul Cste mul A2 mul add%
}for
e t AR2 mul neg exp mul SB div CC2 add}

\def\SinusA{%
t 10 mul T1 div BT mul
mod1 57.3 mul t 10 mul Tm1 div BT mul sin mul add
phaseA add sin A1 mul
e t AR1 mul neg exp mul SA div CC1 add}

\def\SinusB{%
t 10 mul T2 div BT mul
mod2 57.3 mul t 10 mul Tm2 div BT mul sin mul
add phaseB add sin A2 mul
e t AR2 mul neg exp mul SB div CC2 add}

\def\Oscillo{\@ifnextchar[{\pst@Oscillo}{\pst@Oscillo[]}}

\def\pst@Oscillo[#1]{{%
\setkeys{psset}{#1}

\pspicture(0,-5)(10,5) \psframe*[linecolor=LightBlue](0,-4)(10,4)
\psgrid[gridlabels=0,subgriddiv=0](0,-4)(10,4)
\multido{\nxDiv=0+0.2}{50}{%
\psline(\nxDiv,-.1)(\nxDiv,0.1)}
\multido{\nyDiv=-4.0+0.2}{40}{%
\psline(4.9,\nyDiv)(5.1,\nyDiv)}

%%%%%%%%%%%% Tuning %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\psframe[fillcolor=VeryLightGray,fillstyle=solid,dimen=middle](0,4)(10,5)
\rput(1.5,4.8){\ssf timeDiv :} \rput(1.5,4.3){\ssf\psk@Oscillo@TimeDiv{}ms/div}
\rput(4,4.8){\ssf Channel A :} \rput(4,4.3){\ssf\psk@ChannelA{} V/div}
\rput(7,4.8){\ssf Channel B :} \rput(7,4.3){\ssf\psk@ChannelB{} V/div}
\rput(9,4.8){\ssf XY} \rput(9,4.3){\ifPst@Oscillo@Lissajous\red ON\else\green OFF\fi}
\psframe[fillcolor=VeryLightGray,fillstyle=solid,dimen=middle](0,-5)(10,-4)
\ifPst@Oscillo@Combine
\rput(2,-4.3){\ssf\psk@Oscillo@Operation:}
\rput(2,-4.8){\ssf\magenta ON}
\fi
\rput(6.5,-4.3){\ssf OffsetB}
\rput(6.5,-4.8){\ssf \psk@Oscillo@OffsetB}
\rput(8.5,-4.3){\ssf OffsetC}
\rput(8.5,-4.8){\ssf \psk@Oscillo@OffsetC}
\rput(4.5,-4.3){\ssf OffsetA}
\rput(4.5,-4.8){\ssf \psk@Oscillo@OffsetA}
\ifPst@Oscillo@Lissajous

\psclip{\psframe(0,-4)(10,4)}
\parametricplot[style=\psk@Oscillo@PlotStyleC]{0}{360}{%
/fourier \psk@Oscillo@Fourier\space def
/T1 \psk@Oscillo@PeriodA\space def
/T2 \psk@Oscillo@PeriodB\space def
/Tm1 \psk@Oscillo@PeriodModulationA\space def
/mod1 \psk@Oscillo@FreqModA\space def
/Tm2 \psk@Oscillo@PeriodModulationB\space def
/mod2 \psk@Oscillo@FreqModB\space def
/CC1 \psk@Oscillo@ContinuousComponentA\space def
/CC2 \psk@Oscillo@ContinuousComponentB\space def
/BT T1 def
/A1 \psk@Oscillo@AmplitudeA\space def
/A2 \psk@Oscillo@AmplitudeB\space def
/phaseA \psk@Oscillo@PhaseA\space def
/phaseB \psk@Oscillo@PhaseB\space def
%/K 36 T div def
/e 2.718 def
/AR1 \psk@Oscillo@dampingA\space def
/AR2 \psk@Oscillo@dampingB\space def
/SA \psk@ChannelA\space def
/SB \psk@ChannelB\space def
/offset1 \psk@Oscillo@OffsetA\space def
/offset2 \psk@Oscillo@OffsetB\space def
\psk@Oscillo@WaveA\space 5 add
\psk@Oscillo@WaveB\space}
\endpsclip
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\else
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\psclip{\psframe(0,-4)(10,4)}\psset{xunit=0.02777}
\parametricplot[style=\psk@Oscillo@PlotStyleA]{0}{360}{%
/fourier \psk@Oscillo@Fourier\space def
/T1 \psk@Oscillo@PeriodA\space def
/Tm1 \psk@Oscillo@PeriodModulationA\space def
/mod1 \psk@Oscillo@FreqModA\space def
/BT \psk@Oscillo@TimeDiv\space def
/A1 \psk@Oscillo@AmplitudeA\space def
/phaseA \psk@Oscillo@PhaseA\space def
/CC1 \psk@Oscillo@ContinuousComponentA\space def
/e 2.718 def
/AR1 \psk@Oscillo@dampingA\space def
/offset1 \psk@Oscillo@OffsetA\space def
/SA \psk@ChannelA\space def
t \psk@Oscillo@WaveA\space
offset1 add
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\parametricplot[style=\psk@Oscillo@PlotStyleB]{0}{360}{%
/fourier \psk@Oscillo@Fourier\space def
/T2 \psk@Oscillo@PeriodB\space def
/Tm2 \psk@Oscillo@PeriodModulationB\space def
/mod2 \psk@Oscillo@FreqModB\space def
/BT \psk@Oscillo@TimeDiv\space def
/A2 \psk@Oscillo@AmplitudeB\space def
/phaseB \psk@Oscillo@PhaseB\space def
/CC2 \psk@Oscillo@ContinuousComponentB\space def
/e 2.718 def
/AR2 \psk@Oscillo@dampingB\space def
/offset2 \psk@Oscillo@OffsetB\space def
/SB \psk@ChannelB\space def
t \psk@Oscillo@WaveB\space
offset2 add
}
\ifPst@Oscillo@Combine
%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\parametricplot[style=\psk@Oscillo@PlotStyleD]{0}{360}{%
/fourier \psk@Oscillo@Fourier\space def
/T1 \psk@Oscillo@PeriodA\space def
/T2 \psk@Oscillo@PeriodB\space def
/Tm1 \psk@Oscillo@PeriodModulationA\space def
/mod1 \psk@Oscillo@FreqModA\space def
/Tm2 \psk@Oscillo@PeriodModulationB\space def
/mod2 \psk@Oscillo@FreqModB\space def
/BT \psk@Oscillo@TimeDiv\space def
/A1 \psk@Oscillo@AmplitudeA\space def
/A2 \psk@Oscillo@AmplitudeB\space def
/phaseA \psk@Oscillo@PhaseA\space def
/phaseB \psk@Oscillo@PhaseB\space def
/CC1 \psk@Oscillo@ContinuousComponentA\space def
/CC2 \psk@Oscillo@ContinuousComponentB\space def
/offset3 \psk@Oscillo@OffsetC\space def
/e 2.718 def
/AR1 \psk@Oscillo@dampingA\space def
/AR2 \psk@Oscillo@dampingB\space def
/SA \psk@ChannelA\space def
/SB \psk@ChannelB\space def
/offset1 \psk@Oscillo@OffsetA\space def
/offset2 \psk@Oscillo@OffsetB\space def
t \psk@Oscillo@WaveA\space
\psk@Oscillo@WaveB\space
\psk@Oscillo@Operation%
\space offset3 add}
\fi
\endpsclip\fi
\endpspicture}}
\catcode`\@=\PstAtCode\relax
\endinput
