1 ## Copyright (C) 2003 David Bateman
3 ## This program is free software; you can redistribute it and/or modify it under
4 ## the terms of the GNU General Public License as published by the Free Software
5 ## Foundation; either version 3 of the License, or (at your option) any later
8 ## This program is distributed in the hope that it will be useful, but WITHOUT
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 ## You should have received a copy of the GNU General Public License along with
14 ## this program; if not, see <http://www.gnu.org/licenses/>.
17 ## @deftypefn {Function File} {@var{y} =} amodce (@var{x},@var{Fs},'amdsb-tc',offset)
18 ## @deftypefnx {Function File} {@var{y} =} amodce (@var{x},@var{Fs},'amdsb-sc')
19 ## @deftypefnx {Function File} {@var{y} =} amodce (@var{x},@var{Fs},'amssb')
20 ## @deftypefnx {Function File} {@var{y} =} amodce (@var{x},@var{Fs},'amssb/time',@var{num},@var{den})
21 ## @deftypefnx {Function File} {@var{y} =} amodce (@var{x},@var{Fs},'qam')
22 ## @deftypefnx {Function File} {@var{y} =} amodce (@var{x},@var{Fs},'fm',@var{dev})
23 ## @deftypefnx {Function File} {@var{y} =} amodce (@var{x},@var{Fs},'pm',@var{dev})
24 ## @deftypefnx {Function File} {@var{y} =} amodce (@var{x},[@var{Fs},@var{iphs}],@var{...})
26 ## Baseband modulator for analog signals. The input signal is specified by
27 ## @var{x}, its sampling frequency by @var{Fs} and the type of modulation
28 ## by the third argument, @var{typ}. The default values of @var{Fs} is 1 and
29 ## @var{typ} is 'amdsb-tc'.
31 ## If the argument @var{Fs} is a two element vector, the the first element
32 ## represents the sampling rate and the second the initial phase.
34 ## The different types of modulations that are available are
39 ## Double-sideband with carrier
41 ## Double-sideband with suppressed carrier
43 ## Single-sideband with frequency domain Hilbert filtering
45 ## Single-sideband with time domain filtering. Hilbert filter is used by
46 ## default, but the filter can be specified
48 ## Quadrature amplitude modulation
50 ## Frequency modulation
55 ## Additional arguments are available for the modulations 'amdsb-tc', 'fm,
56 ## 'pm' and 'amssb/time'. These arguments are
60 ## The offset in the input signal for the transmitted carrier.
62 ## The deviation of the phase and frequency modulation
65 ## The numerator and denominator of the filter transfer function for the
66 ## time domain filtering of the SSB modulation
70 ## @seealso{ademodce,dmodce}
72 function y = amodce (x, Fs, typ, varargin)
89 if ((max(size(Fs)) != 2) || (min(size(Fs)) != 1))
90 error ("amodce: sampling frequency must be a scalar or 2-element vector");
96 ## Pass the optional arguments
103 error ("amodce: modulation type must be a string");
104 elseif (strcmp(typ,"am") || strcmp(typ,"amdsb-tc"))
105 if (length(varargin) > 0)
106 offset = varargin{1};
109 elseif (strcmp(typ,"fm") || strcmp(typ,"pm"))
110 if (length(varargin) > 0)
115 if (length(varargin) == narg)
116 error ("amodce: must specify must numerator and denominator of transfer function");
117 elseif (length(varargin) == narg+1)
118 num = varargin{narg};
119 den = varargin{narg+1};
120 elseif (length(varargin) != narg - 1)
121 error ("amodce: too many arguments");
124 if (strcmp(typ,"am") || strcmp(typ,"amdsb-tc"))
125 y = (x + offset) * exp(1i * iphs);
126 elseif (strcmp(typ,"amdsb-sc"))
127 y = x * exp(1i * iphs);
128 elseif (strcmp(typ,"amssb"))
130 error ("amodce: SSB modulated signal must be real");
132 ## Damn, must treat Hilbert transform row-by-row!!!
135 y(:,i) = hilbert(x(:,i)) * exp(1i * iphs);
137 elseif (strcmp(typ,"amssb/time"))
138 if (isempty(num) || isempty(dem))
139 error ("amodce: have not implemented Hilbert transform in time domain yet");
143 y(:,i) = filter(num, den, x(:,i));
144 y(:,i) = (x(:,i) + 1i*y(:,i)) * exp(1i * iphs);
146 elseif (strcmp(typ,"qam"))
148 if (floor(size(x,2)/2) != (size(x,2)/2))
149 error ("amodce: QAM modulation must have an even number of columns for real signals");
151 y = (x(:,1:2:size(x,2)) + 1i * x(:,2:2:size(x,2)));
155 y = y * exp(1i * iphs);
156 elseif (strcmp(typ,"pm"))
157 y = exp(1i * (dev*x + iphs));
158 elseif (strcmp(typ,"fm"))
159 ## To convert to PM signal, need to evaluate
160 ## p(t) = \int_0^t dev * x(T) dT
161 ## As x(t) is discrete and not a function, the only way to perform the
162 ## above integration is with Simpson's rule. Note \Delta T = 2 * pi / Fs.
163 pm = pi / Fs * dev * (cumsum([zeros(1,size(x,2));x(1:size(x,1)-1,:)]) ...
165 y = exp(1i * (pm + iphs));
167 error ("amodce: unknown modulation specified");