%  example2.tex from ObjectProDSP 0.2
%  Copyright (C) 1994 1995, Mountain Math Software. All rights reserved.
%  
%  This file is part of ObjectProDSP, a tool for Digital Signal
%  Processing design, development and implementation. It is free
%  software provided you use and distribute it under the terms of
%  version 2 of the GNU General Public License as published
%  by the Free Software Foundation. You may NOT distribute it or
%  works derived from it or code that it generates under ANY
%  OTHER terms.  In particular NONE of the ObjectProDSP system is
%  licensed for use under the GNU General Public LIBRARY License.
%  Mountain Math Software plans to offer a commercial version of
%  ObjectProDSP for a fee. That version will allow redistribution
%  of generated code under standard commercial terms.
%  
%  This program is distributed in the hope that it will be useful,
%  but WITHOUT ANY WARRANTY; without even the implied warranty of
%  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
%  GNU General Public License for more details.
%  
%  You should have received a copy of version 2 of the GNU General
%  Public License along with this program. See file COPYING. If not
%  or if you wish information on commercial versions and licensing
%  write Mountain Math Software, P. O. Box 2124, Saratoga, CA 95070,
%  USA, or send us e-mail at: support@mtnmath.com.
%  
%  You may also obtain the GNU General Public License by writing the
%  Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
%  USA.  However if you received a copy of this program without the
%  file COPYING or without a copyright notice attached to all text
%  files, libraries and executables please inform Mountain Math Software.
%  
%  ObjectProDSP is a trademark of Mountain Math Software.
%  
\clearpage
\SectionIndex{FIR filter frequency response}
\markright{\headtitle}

\begin{figure}
\centerline{\psfig{figure=../psfig/Fir_resp_net.ps}}
\caption{Network to compute FIR filter response}
\label{fig:FirResponseNet}
\end{figure}

\begin{figure}
\centerline{\psfig{figure=../psfig/ex2_fft.ps}}
\caption{Complex plot of FIR filter frequency response}
\label{fig:FirResponseFft}
\end{figure}

\begin{figure}
\centerline{\psfig{figure=../psfig/ex2_fft_p.ps}}
\caption{Power plot of FIR filter frequency response}
\label{fig:FirResponseFftPower}
\end{figure}

\begin{figure}
\centerline{\psfig{figure=../psfig/ex2_fft_d.ps}}
\caption{Decibel plot of FIR filter frequency response}
\label{fig:FirResponseFftDecibel}
\end{figure}


Figure~\ref{fig:FirResponseNet} shows a network to compute and display
the \Index{frequency response} of a Finite
Impulse Response (FIR) filter.
A complex impulse signal (with real part 0) is
passed through a FIR filter and a complex FFT. The outputs of
the FIR filter and FFT are plotted. Figures~\ref{fig:FirResponseFft}
through \ref{fig:FirResponseFftDecibel} show complex magnitude, power
and decibel views of the frequency response. The latter two plots
were obtained by typing
\verb'ctrl-p' and \verb'ctrl-b' with the cursor over the first plot.
The program for this example is in
in figure~\ref{fig:FirResponseDesc}.

The steep descent at the right edge of Figure~\ref{fig:FirResponseFftDecibel}
is a consequence of processing the even symmetric impulse repsonse
of the FIR filter with the FFT. The largest/smallest frequency
bin convolves the signal with $e^{\pi i n}$ where $n$ is the
sample index. This is the real sequence 
$\{ -1, 1, -1, 1, ... \}$.
Convolving this sequence  with any even symmetric signal
produces 0. The decibel plot artificially limits the smallest value
to -200 db.

\begin{figure}
\centerline{\psfig{figure=../psfig/ex2_menu.ps}}
\caption{Menu for Fir\_resp\_cximp object}
\label{fig:FirResponseMenu}
\end{figure}


\begin{figure}
\centerline{\psfig{figure=../psfig/ex2_men_help.ps}}
\caption{Description of Fir\_resp\_cximp object}
\label{fig:FirResponseObjDesc}
\end{figure}


The \Index{impulse signal generator} used in this example
supports special
signals. You can hold the \verb'ctrl' key down and click the left mouse
button on the \verb'Fir_resp_cximp' object in the network display
to get the menu for
this object. Select \verb'desc' from this menu to get a description
\index{menu for node}
\index{node menu}
of the parameters and their values in this example. This menu is in
\index{node description}
figure~\ref{fig:FirResponseMenu} and the description is in
figure~\ref{fig:FirResponseObjDesc}.

\begin{figure}
\centerline{\psfig{figure=../psfig/ex2_desc.ps}}
\caption{Program for FIR filter response}
\label{fig:FirResponseDesc}
\end{figure}

\clearpage
\SectionIndex{Multi-stage FIR filter}
\markright{\headtitle}

\begin{figure}
\centerline{\psfig{figure=../psfig/Fir_net.ps}}
\caption{Network for multiple stage filter}
\label{fig:FirStageNet}
\end{figure}

Figure~\ref{fig:FirStageNet} is a spectral analysis example using
a three stage filter. Each stage has a resampling factor of 2.
This structure can significantly reduce the total number of multiplies over
that required for a single stage filter with the same resampling ratio.
The input is Gaussian noise and
two complex sine waves at frequencies of .2 and
.02 hz. Both of the cosine signals are visible
in the spectral plot of
the filter input in figure~\ref{fig:FirStageInput}. The higher frequency
signal is outside the pass band of the filter as seen in the filter
output spectral plot in figure~\ref{fig:FirStageOutput}. The frequency axis of
these plots are on the same scale. \Dpp{} automatically computes
the sampling rate ratios of every node in a network and uses
\index{node sample rates}
\index{plot frequency axis}
these ratios in labeling the plots.


\begin{figure}
\centerline{\psfig{figure=../psfig/ex3_fft_1024_d.ps}}
\caption{Spectral plot of multi-stage filter input}
\label{fig:FirStageInput}
\end{figure}

\begin{figure}
\centerline{\psfig{figure=../psfig/ex3_fft_256_d.ps}}
\caption{Spectral plot of multi-stage filter output}
\label{fig:FirStageOutput}
\end{figure}

To create code for a supported target position
the cursor over the bar containing
the edit button in the \verb'FFT_net' window and click the left mouse
\index{network menu}
\index{menu for network}
button while holding the \verb'ctrl' key down. Select the \verb'exec'
and then the \verb'other' options in the \verb'Menu Fir_net' window that
appears. Now select \verb'MakeTarget'. This menu is in 
\index{MakeTarget}
\index{target code generation}
figure~\ref{fig:FirStageNetMenu}.


\begin{figure}
\centerline{\psfig{figure=../psfig/ex3_net_menu.ps}}
\caption{Menu for Fir\_net object}
\label{fig:FirStageNetMenu}
\end{figure}

You will now be prompted
for three parameters. First is the target type. If you select the default
\verb'generic_cpp' code will be generated to run on the computer you
are using. This version only provides direct support for generic
\Cpp{} code.
\index{generic\_cpp}
Next enter `1' to compile and link the code to be generated. If you select 0 you
can compile and link it later by doing a \verb'make' in a subdirectory
of the one in which the code will be written. Finally you are
prompted for a directory name. If you select the default, a directory
will be created under your current working directory that has the
same name as the network you are making the target for.

Code will be written and a make file generator process will
be started. The output from this 
and execution of the make (if you selected create) will
be written to file \DppNm{msgs\_FFT\_Net\_FFT\_Net.out}
in your current directory.
The \verb`Makefile` and the executable image will be in subdirectory
\index{Makefile}\index{tarflt}
DppNm{tarflt}\index{generic\_cpp} of the directory you specified.


\begin{figure}
\centerline{\psfig{figure=../psfig/ex3_tar_big.ps}}
\caption{Target code generation with large buffers}
\label{fig:FirStageTargetLarge}
\end{figure}

The result of analyzing the network and generating the target code
is in the `help information' window shown in
figure~\ref{fig:FirStageTargetLarge}. The \verb'Replacement complete'
\index{replace target node}
\index{target node replacement}
lines refer to the replacement of nodes not supported on the selected
target. For example no targets support nodes for plotting. These
are replaced by nodes that write a file that can be read and plotted
later.

First an attempt is made to create a deterministic scheduling scheme for
\index{scheduling on target}
\index{target scheduling}
the network. This is a a list of what nodes to execute in what
order and how many samples to process at each execution. If this requires
excessive buffer space or the lists become too long a dynamic scheduling
\index{dynamic scheduling}
\index{scheduling dynamically}
scheme is used. 

If you want to change the buffer sizes or other parameters of this
scheduling process you can assign a new buffer descriptor to the
\index{buffer assignment}
\index{scheduling parameters}
network. First click the mouse on the
\verb'Edit' button of the network you want to change.
Then enter the command
\DppNm{network} in the menu database text entry window or make
the menu selections \DppNm{objects} and \DppNm{network}.
Hold the \verb'shift' key down and click the right mouse button
over the \DppNm{CircBufDes} button.
You will be prompted for the new buffer parameters.
You can now select \verb'MakeTarget' to generate code based on these
parameters.

