sinesc.s
<BLOCK>
<LICENSE>
/* Capsim (r) Text Mode Kernel (TMK) Block Library (Blocks)
Copyright (C) 2006-2007 Silicon DSP Corporation, Portland, Oregon
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
http://capsimtmk.sourceforge.net
*/
</LICENSE>
<BLOCK_NAME> sinesc </BLOCK_NAME>
<COMMENTS>
<![CDATA[
/* sinesc.s */
/***************************************************************************
sinesc()
*****************************************************************************
This block generates a sinusoid ( cosine for zero phase) .
If a second buffer is connected, the quadrature signal is output.
Parameters:
The first parameter, which defaults to 128, tells how many total samples
to send out.
The second parameter is the magnitude which defaults to one.
The third parameter is the sampling frequency.
The 4th parameter is the frequency.
The fifth parameter is the phase in degrees.
*/
]]>
</COMMENTS>
<DESC_SHORT>
This block generates a sinusoid ( cosine for zero phase).
</DESC_SHORT>
<DESCRIPTION>
</DESCRIPTION>
<PROGRAMMERS>
Programmer: Sasan Ardalan
Date: Nov. 1987
Modified: SystemC July 2006
</PROGRAMMERS>
<INCLUDES>
<![CDATA[
]]>
</INCLUDES>
<DEFINES>
#define PI 3.141592654
#define PIDIV2 1.570796327
#define PI2 6.283185307
</DEFINES>
<OUTPUT_BUFFERS>
<BUFFER>
<TYPE> float </TYPE>
<NAME> y </NAME>
</BUFFER>
</OUTPUT_BUFFERS>
<STATES>
<STATE>
<TYPE> float </TYPE>
<NAME> dt </NAME>
</STATE>
<STATE>
<TYPE> float </TYPE>
<NAME> phaseRad </NAME>
</STATE>
<STATE>
<TYPE> long </TYPE>
<NAME> samples_out </NAME>
<VALUE> 0 </VALUE>
</STATE>
<STATE>
<TYPE> double </TYPE>
<NAME> angle </NAME>
<VALUE> 0 </VALUE>
</STATE>
</STATES>
<DECLARATIONS>
long i,j;
float yy;
</DECLARATIONS>
<PARAMETERS>
<PARAM>
<DEF> total number of samples to output </DEF>
<TYPE> int </TYPE>
<NAME> num_of_samples </NAME>
<VALUE> 128 </VALUE>
</PARAM>
<PARAM>
<DEF> Enter Magnitude </DEF>
<TYPE> float </TYPE>
<NAME> magnitude </NAME>
<VALUE>1.0 </VALUE>
</PARAM>
<PARAM>
<DEF> Enter Sampling Rate </DEF>
<TYPE> float </TYPE>
<NAME> fs </NAME>
<VALUE> 32000.0 </VALUE>
</PARAM>
<PARAM>
<DEF> Enter Frequency </DEF>
<TYPE> float </TYPE>
<NAME> freq </NAME>
<VALUE> 1000.0 </VALUE>
</PARAM>
<PARAM>
<DEF> Enter Phase </DEF>
<TYPE> float </TYPE>
<NAME> phase </NAME>
<VALUE> 0.0 </VALUE>
</PARAM>
</PARAMETERS>
<INIT_CODE>
<![CDATA[
samples_out=0;
phaseRad = phase *PI/180.0;
dt = 2.*PI*freq/fs;
angle= -dt;
]]>
</INIT_CODE>
<MAIN_CODE>
<![CDATA[
angle= angle +dt;
angle=fmod(angle,PI2);
yy = magnitude*cos(angle+phaseRad);
y.write(yy);
samples_out += 1;
if(samples_out > num_of_samples) sc_stop();
]]>
</MAIN_CODE>
<WRAPUP_CODE>
<![CDATA[
]]>
</WRAPUP_CODE>
</BLOCK>