function [y,t] = modulate(x,fc,fs,varargin)
    method = 'amdsb-sc';
    isopt = 0
    opt = 0;
    nargin = length(varargin);
    y = zeros(size(x));
    %disp(nargin);
    if nargin >= 1
        method=varargin{1};
    endif
    if nargin >= 2
        isopt = 1
        opt = varargin{2};
    endif
    if nargin > 2
        error('Too many arguments');
    endif
    
    if fc>=fs/2
        error('fc should be less than half of fs')
    endif
    
    t = 0:1/fs:1;
    res = size(x);
    
    %Make x column if it is a row vector%
    %Easier to broadcast                %
    if size(x)(1)==1
        x = x';
        opt = opt';
    endif
    
    if 1 == strcmp(method,'amdsb-sc')
        y = x.*(cos(2*pi*fc*t)');
        y = reshape(y,res);
    endif
        
        
    if 1 == strcmp(method,'amdsb-tc')
        if isopt == 0
            opt = min(min(x));
        endif
        y = (x-opt).*(cos(2*pi*fc*t)');
        y = reshape(y,res);
    endif
    
    if 1 == strcmp(method,'amssb')
        y = x.*(cos(2*pi*fc*t))'+(imag(hilbert(x)).*sin(2*pi*fc*t)');
        y = reshape(y,res);
    endif
    
    if 1 == strcmp(method,'fm')
        if isopt == 0
            opt = (fc/fs)*2*pi/(max(max(x)));
        endif
        y = cos((2*pi*fc*t)' + opt*cumsum(x));
        y = reshape(y,res);
    endif
    
    if 1 == strcmp(method,'pm')
        if isopt == 0
            opt = pi/(max(max(x)));
        endif
        y = cos(2*pi*fc*t' + opt*x);
        y = reshape(y,res);
    endif
    
    if 1 == strcmp(method,'qam')
        if isopt==0
            error('Needs an another argument with same size that of x');
        else if sum(size(opt) ~= size(x))~=0
            error('size of opt must be same as x')
        endif
        
        y = x.*cos(2*pi*fc*t)' + opt.*sin(2*pi*fc*t)';
        y = reshape(y,res);
    endif
    
endfunction