Skip to content
Snippets Groups Projects
Select Git revision
  • 28a0595f3919cb79f1c248bc736c940d7a0a542c
  • master default protected
  • L2SDP-LIFT
  • L2SDP-1113
  • HPR-158
5 results

wg.m

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    wg.m 1.74 KiB
    %-----------------------------------------------------------------------------
    %
    % Copyright (C) 2016
    % ASTRON (Netherlands Institute for Radio Astronomy) <http://www.astron.nl/>
    % P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
    %
    % This program is free software: you can redistribute it and/or modify
    % it under the terms of the GNU General Public License as published by
    % the Free Software Foundation, either version 3 of the License, or
    % (at your option) any later version.
    %
    % This program 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 General Public License for more details.
    %
    % You should have received a copy of the GNU General Public License
    % along with this program.  If not, see <http://www.gnu.org/licenses/>.
    %
    %-----------------------------------------------------------------------------
    % Author: E. Kooistra, 2016
    %
    % Purpose : Waveform generator per block of data
    % Description :
    %   The WG data is normalized to -1:1. Data outside this range is clipped,
    %   so use ampl >> 1 to create square wave.
    
    function [state, data] = wg(ctrl)
    
    % Data processing
    t = 0:ctrl.block_size-1;
    
    % Sinusoid
    data = ctrl.ampl * sin(2*pi*(ctrl.freq*t+ctrl.phase));
    
    % DC offset
    data = data + ctrl.offset;
    
    % Additive Gaussian White Noise
    if ctrl.agwn_sigma>0
        data = data + ctrl.agwn_sigma * randn(1, ctrl.block_size);
    end
    
    % Analogue full scale clipping
    data(data> 1) =  1;
    data(data<-1) = -1;
    
    % Quantization
    if ctrl.data_w>0
        data = quantize(data, 1, ctrl.data_w, 'half_up');
    end
    
    % Keep state for next call
    state = ctrl;
    state.phase = ctrl.freq*ctrl.block_size+ctrl.phase;