% this is a module that will accept the frequency of the signal, amplitude, 
% noise variance (observation), and store the clean and the observation 
% signal 
% 
% Author: Sanjay Patil Nov 02, 2005. Wednesday. 1112 hours central
%

% this will the command line argument for the signal generation afterwards
%
function signal_generator_sine(amplitude, freq, R)

% if you are having a function all, do not free memory allocated to the 
% variables
%
% initial set-up
%
% clear all;
close all;
clc;

if(nargin < 3)
    disp('Please enter amplitude, frequency and noise variance');
    error('Not enough input arguments.');
else
    % details of the program
    %
    disp('The program to generate test signal for deterministic model');
    disp('Input Parameters (three parameters) :');
    disp('1. Amplitude 2. frequency');
    disp('3. Observation noise variance');
    disp('Output parameters (two files) :');
    disp( '1. clean file (clean_sine.raw)');
    disp('2. obsn file (obsn_sine.raw)');

    disp(' ');

    % % uncomment afterwards
    % %
    % disp('displaying all the values :');
    %
    % disp(['the amplitude                  : ', num2str(amplitude)]);
    % disp(['the frequency  [Hz]            : ', num2str(freq)]);
    % disp(['the Observation noise variance : ', num2str(R)]);
    %
    %
    % disp('displayed all the values :');

    % % accepting values from command window
    % %
    % amplitude = input('Enter amplitude of sinusoidal signal      : ');
    % freq = input('Enter frequency of sinosoidal signal [Hz] : ');
    % R = input('Enter the observation noise variance      : ');

    % % assuming sampling frequency to be 8000
    % % example values :
    % amplitude = 1;
    % R = 0.05;
    % freq = 100;

    % angle should be given in radians
    %
    for i = 1:100
        x(i)= cos(2 * pi * freq / 8000 * i);
        z(i)= x(i) + normrnd(0, sqrt(R)); %Adjust the noise variance here
    end;

    save ('clean_sine.raw', 'x', '-ascii', '-double');
    save ('obsn_sine.raw', 'z', '-ascii', '-double');

    figure;
    plot(x, 'b');
    hold on;
    plot(z, 'm');
    title(['Determinstic Signal : ', num2str(amplitude),...
        ' cos(2*{\pi}*', num2str(freq), '/', num2str(8000), ') + '...
        , 'noise {\sigma} =', num2str(R)]);
    legend('clean signal', 'observation signal');
    
end;
    


