View Raw SPL
/*****************************************************************************
*                                                                            *
*   MODAM.SPL    Copyright (C) 2013 DSP Development Corporation              *
*                               All Rights Reserved                          *
*                                                                            *
*   Author:      Randy Race                                                  *
*                                                                            *
*   Synopsis:    AM modulation of an input series                            *
*                                                                            *
*   Revisions:   22 May 2013  RRR  Creation                                  *
*                                                                            *
*****************************************************************************/

#if @HELP_MODAM

    MODAM

    Purpose: Performs amplitude modulation of a series.

    Syntax:  MODAM(s, fc, p)

              s - the input series

             fc - Optional, a real. The carrier frequency. Defaults to
                  rate(s)/4.

              p - Optional, a real. The phase in radians. Defaults to
                  0.0.

    Returns: A series, the amplitude modulated output.

    Example:
             W1: gtriwave(1000,.001, 4)
             W2: modam(w1, 200)
             W3: demodam(w2, 200)
             W4: specgram(w2, 64, 63, 1024)

             The triangle series of W1 is amplitude modulated with a
             carrier frequency of 200 Hz in W2. W3 recovers the modulated
             series and W4 displays the joint time-frequency plot
             of the frequency modulated series.

    Remarks:
             The carrier frequency should be greater than or equal to the
             bandwidth of the input series, but less than or equal to
             rate(s)/2, the Nyquist frequency.

             See DEMODAM to demodulate an amplitude modulated series.

             See MODFM to frequency modulate a series.

    See Also:
             Demodam
             Demodfm
             Modfm
#endif


/* amplitude modulate a series */
ITERATE modam(s, fc, p)
{
        local am;

        if (argc < 3)
        {
                if (argc < 2)
                {
                        if (argc < 1) error("modam - input series required");
                        
                        fc = rate(s) / 4;
                }

                p = 0;
        }

        /* check Nyquist */
        if (fc > rate(s) / 2)
        {
                error(sprintf("modam - fc must be <= to %g, the Nyquist Frequency", rate(s) / 2));
        }

        /* simple amplitude modulation */
        am = gcos(length(s), deltax(s), fc, p) * s;
        
        return(am);
}