From 28a0595f3919cb79f1c248bc736c940d7a0a542c Mon Sep 17 00:00:00 2001
From: Erik Kooistra <kooistra@astron.nl>
Date: Fri, 8 Apr 2016 09:49:02 +0000
Subject: [PATCH] Updated header to show it with help.

---
 .../apertif/matlab/FIR_LPF_ApertifCF.m        |  6 +-
 applications/apertif/matlab/bsn_source.m      |  9 +--
 applications/apertif/matlab/dt.m              | 27 ++++-----
 applications/apertif/matlab/fringe.m          |  3 +-
 applications/apertif/matlab/fringe_stopping.m |  4 +-
 applications/apertif/matlab/pfft.m            | 31 ++++++-----
 applications/apertif/matlab/pfir.m            | 31 ++++++-----
 applications/apertif/matlab/pfir_coeff.m      |  5 +-
 applications/apertif/matlab/phase_tracking.m  |  3 +-
 applications/apertif/matlab/quantize.m        |  5 +-
 applications/apertif/matlab/run_pfir_coeff.m  |  2 +-
 applications/apertif/matlab/spec.m            |  2 +-
 applications/apertif/matlab/try_quantize.m    |  2 +-
 applications/apertif/matlab/try_uencode.m     |  2 +-
 applications/apertif/matlab/wg.m              | 55 ++++++++++---------
 15 files changed, 100 insertions(+), 87 deletions(-)

diff --git a/applications/apertif/matlab/FIR_LPF_ApertifCF.m b/applications/apertif/matlab/FIR_LPF_ApertifCF.m
index 68bd2d8b72..496056f22b 100644
--- a/applications/apertif/matlab/FIR_LPF_ApertifCF.m
+++ b/applications/apertif/matlab/FIR_LPF_ApertifCF.m
@@ -18,8 +18,12 @@
 % along with this program.  If not, see <http://www.gnu.org/licenses/>.
 %
 %-----------------------------------------------------------------------------
-% Author: R. de Wild, 2015
+% Author: R. de Wild, 2015 (Original)
 %         E. Kooistra, 2016
+%
+% Purpose : Calculate FIR filter coefficients for Apertif channel
+%           filterbank using fircls1.
+% Description :
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 % workspace initiation
diff --git a/applications/apertif/matlab/bsn_source.m b/applications/apertif/matlab/bsn_source.m
index 913e9d765f..d805ee11b2 100644
--- a/applications/apertif/matlab/bsn_source.m
+++ b/applications/apertif/matlab/bsn_source.m
@@ -19,12 +19,13 @@
 %
 %-----------------------------------------------------------------------------
 % Author: E. Kooistra, 2016
-
+%
 % Purpose : BSN source per block of data
 % Description :
 
 function [state] = bsn_source(ctrl)
-    % Increment BSN for next call
-    state = ctrl;
-    state.bsn = ctrl.bsn + 1;
+
+% Increment BSN for next call
+state = ctrl;
+state.bsn = ctrl.bsn + 1;
     
\ No newline at end of file
diff --git a/applications/apertif/matlab/dt.m b/applications/apertif/matlab/dt.m
index 7ad14f9d70..d6940b3939 100644
--- a/applications/apertif/matlab/dt.m
+++ b/applications/apertif/matlab/dt.m
@@ -19,7 +19,7 @@
 %
 %-----------------------------------------------------------------------------
 % Author: E. Kooistra, 2016
-
+%
 % Purpose : Delay tracking per block of data
 % Description :
 %
@@ -41,15 +41,16 @@
 % * Index = Time + 1, because for Matlab index starts at 1 instead of at 0.
 
 function [state, out_data] = dt(ctrl, in_data)
-    % Data processing
-    N = ctrl.block_size;
-    
-    % Append input data to the buffer
-    buffer = [ctrl.buffer in_data];
-    
-    % Extract output data for given DT
-    out_data = buffer(1 + (N:2*N-1) - ctrl.dt);
-    
-    % Keep buffer for next call
-    state = ctrl;
-    state.buffer = buffer(1 + (N:3*N-1));
+
+% Data processing
+N = ctrl.block_size;
+
+% Append input data to the buffer
+buffer = [ctrl.buffer in_data];
+
+% Extract output data for given DT
+out_data = buffer(1 + (N:2*N-1) - ctrl.dt);
+
+% Keep buffer for next call
+state = ctrl;
+state.buffer = buffer(1 + (N:3*N-1));
diff --git a/applications/apertif/matlab/fringe.m b/applications/apertif/matlab/fringe.m
index 516527f5f4..e41bed4e94 100644
--- a/applications/apertif/matlab/fringe.m
+++ b/applications/apertif/matlab/fringe.m
@@ -18,7 +18,8 @@
 % along with this program.  If not, see <http://www.gnu.org/licenses/>.
 %
 %-----------------------------------------------------------------------------
-
+% Author: E. Kooistra, 2016
+%
 % Purpose:
 %   Plot the fringe due to the varying difference in geometrical delay.
 % Description:
diff --git a/applications/apertif/matlab/fringe_stopping.m b/applications/apertif/matlab/fringe_stopping.m
index bd49962732..c9bcf53dc6 100644
--- a/applications/apertif/matlab/fringe_stopping.m
+++ b/applications/apertif/matlab/fringe_stopping.m
@@ -19,8 +19,8 @@
 %
 %-----------------------------------------------------------------------------
 % Author: W. Lubberhuizen, 2015 (top.m for LOFAR Station, uses classes)
-%         Eric Kooistra, 2016
-
+%         Eric Kooistra, 2016 (for Apertif)
+%
 % Purpose : Model data path for delay tracking with polyphase filterbank
 % Description :
 % * General
diff --git a/applications/apertif/matlab/pfft.m b/applications/apertif/matlab/pfft.m
index de868e147d..7826a703fa 100644
--- a/applications/apertif/matlab/pfft.m
+++ b/applications/apertif/matlab/pfft.m
@@ -19,23 +19,24 @@
 %
 %-----------------------------------------------------------------------------
 % Author: E. Kooistra, 2016
-
+%
 % Purpose : FFT per block of data
 % Description :
 
 function [out_data] = pfft(ctrl, in_data)
-    % Data processing
-    out_data = fft(in_data, ctrl.fft_size);
-    
-    if ~ctrl.complex
-        % because we have real input, we can omit half of the fft result
-        out_data = out_data(1:ctrl.fft_size/2);
-    end
 
-    % Normalize output to [-1 1]
-    out_data = out_data / ctrl.gain;
-    
-    % Quantization
-    if ctrl.data_w>0
-        out_data = quantize(out_data, 1, ctrl.data_w, 'half_away');
-    end
+% Data processing
+out_data = fft(in_data, ctrl.fft_size);
+
+if ~ctrl.complex
+    % because we have real input, we can omit half of the fft result
+    out_data = out_data(1:ctrl.fft_size/2);
+end
+
+% Normalize output to [-1 1]
+out_data = out_data / ctrl.gain;
+
+% Quantization
+if ctrl.data_w>0
+    out_data = quantize(out_data, 1, ctrl.data_w, 'half_away');
+end
diff --git a/applications/apertif/matlab/pfir.m b/applications/apertif/matlab/pfir.m
index 1f2f70d28e..0a98ea4365 100644
--- a/applications/apertif/matlab/pfir.m
+++ b/applications/apertif/matlab/pfir.m
@@ -19,23 +19,24 @@
 %
 %--------------------------------------------------------------------------
 % Author: E. Kooistra, 2016
-
+%
 % Purpose : Polyphase FIR filter per block of data
 % Description :
 
 function [state, out_data] = pfir(ctrl, in_data)
-    % Data processing
-    for t = 1:ctrl.downsample_factor
-        [out_data(t), ctrl.Zdelays(t,:)] = filter(ctrl.coeff(t,:), 1, in_data(t), ctrl.Zdelays(t,:));   % range ctrl.nof_taps coefficients and range ctrl.nof_taps-1 Zdelays
-    end
-    
-    % Normalize output to [-1 1]
-    out_data = out_data / ctrl.gain;
 
-    % Quantization
-    if ctrl.data_w>0
-        out_data = quantize(out_data, 2^ctrl.scale_w, ctrl.data_w, 'half_away');
-    end
-    
-    % Keep state for next call
-    state = ctrl;
+% Data processing
+for t = 1:ctrl.downsample_factor
+    [out_data(t), ctrl.Zdelays(t,:)] = filter(ctrl.coeff(t,:), 1, in_data(t), ctrl.Zdelays(t,:));   % range ctrl.nof_taps coefficients and range ctrl.nof_taps-1 Zdelays
+end
+
+% Normalize output to [-1 1]
+out_data = out_data / ctrl.gain;
+
+% Quantization
+if ctrl.data_w>0
+    out_data = quantize(out_data, 2^ctrl.scale_w, ctrl.data_w, 'half_away');
+end
+
+% Keep state for next call
+state = ctrl;
diff --git a/applications/apertif/matlab/pfir_coeff.m b/applications/apertif/matlab/pfir_coeff.m
index 22b8bf8ea2..8c2762f17e 100644
--- a/applications/apertif/matlab/pfir_coeff.m
+++ b/applications/apertif/matlab/pfir_coeff.m
@@ -20,8 +20,7 @@
 %-----------------------------------------------------------------------------
 % Author: W. Lubberhuizen, 2005
 %         E. Kooistra, 2016
-
-function coeff = pfir_coeff(N, L, BWchan, r_pass, r_stop, nof_bits, config)
+%
 % pfir_coeff - compute polyphase filterbank coefficients
 %   Computes the coefficients for a polyphase filterbank with N fft
 %   channels, and subfilter length L and channel bandwidth BWchan.
@@ -38,6 +37,8 @@ function coeff = pfir_coeff(N, L, BWchan, r_pass, r_stop, nof_bits, config)
 %   The returned value is a matrix of dimension (NxL)
 %   The run_pfir_coeff.m shows how this pfir_coeff.m can be used.
 
+function coeff = pfir_coeff(N, L, BWchan, r_pass, r_stop, nof_bits, config)
+
 % requested filter length
 M2=N*L;
 if strcmp(config.design, 'fir1')
diff --git a/applications/apertif/matlab/phase_tracking.m b/applications/apertif/matlab/phase_tracking.m
index 32552bd55b..d0499ace64 100644
--- a/applications/apertif/matlab/phase_tracking.m
+++ b/applications/apertif/matlab/phase_tracking.m
@@ -18,7 +18,8 @@
 % along with this program.  If not, see <http://www.gnu.org/licenses/>.
 %
 %-----------------------------------------------------------------------------
-
+% Author: E. Kooistra, 2016
+%
 % Purpose:
 %   Plot the phase tracking (PT) phase and phase erroras function of the
 %   varying geometrical delay.
diff --git a/applications/apertif/matlab/quantize.m b/applications/apertif/matlab/quantize.m
index 8197c4cf75..c84676aa17 100644
--- a/applications/apertif/matlab/quantize.m
+++ b/applications/apertif/matlab/quantize.m
@@ -19,8 +19,7 @@
 %
 %-----------------------------------------------------------------------------
 % Author: E. Kooistra, 2016
-
-function out_data = quantize(in_data, in_max, nof_bits, direction, overflow)
+%
 % quantize - quantize signed input data
 %     The output has nof_bits.
 %     Internally in_max maps to 2^(nof_bits-1)-1.
@@ -33,6 +32,8 @@ function out_data = quantize(in_data, in_max, nof_bits, direction, overflow)
 %     . 'wrap' : Wrap within nof_bits signed integer range
 %     The output data range is scaled back to the original in_max.
 
+function out_data = quantize(in_data, in_max, nof_bits, direction, overflow)
+
 if ~exist('direction', 'var'); direction = 'half_away'; end;
 if ~exist('overflow', 'var'); overflow = 'clip'; end;
     
diff --git a/applications/apertif/matlab/run_pfir_coeff.m b/applications/apertif/matlab/run_pfir_coeff.m
index 5f5184aecb..1618c7caf7 100644
--- a/applications/apertif/matlab/run_pfir_coeff.m
+++ b/applications/apertif/matlab/run_pfir_coeff.m
@@ -19,7 +19,7 @@
 %
 %-----------------------------------------------------------------------------
 % Author: E. Kooistra, 2016
-
+%
 % Purpose : Run pfir_coeff
 % Description :
 %   Plot FIR filter coefficients and transfer function.
diff --git a/applications/apertif/matlab/spec.m b/applications/apertif/matlab/spec.m
index 5051dc2c8c..3c2584b654 100644
--- a/applications/apertif/matlab/spec.m
+++ b/applications/apertif/matlab/spec.m
@@ -19,7 +19,7 @@
 %
 %-----------------------------------------------------------------------------
 % Author: E. Kooistra, 2016
-
+%
 % Purpose : Image spectrum per block of data
 % Description :
 
diff --git a/applications/apertif/matlab/try_quantize.m b/applications/apertif/matlab/try_quantize.m
index 9553b5fb33..d0696622d7 100644
--- a/applications/apertif/matlab/try_quantize.m
+++ b/applications/apertif/matlab/try_quantize.m
@@ -19,7 +19,7 @@
 %
 %-----------------------------------------------------------------------------
 % Author: E. Kooistra, 2016
-
+%
 % Purpose : Try quantize.m
 % Description :
 
diff --git a/applications/apertif/matlab/try_uencode.m b/applications/apertif/matlab/try_uencode.m
index 6e3832eed3..78af6bb870 100644
--- a/applications/apertif/matlab/try_uencode.m
+++ b/applications/apertif/matlab/try_uencode.m
@@ -19,7 +19,7 @@
 %
 %-----------------------------------------------------------------------------
 % Author: E. Kooistra, 2016
-
+%
 % Purpose : Try uencode to determine optimum quantisation
 % Description :
 % Remark : It seems more appropriate to use round() instead of uencode(),
diff --git a/applications/apertif/matlab/wg.m b/applications/apertif/matlab/wg.m
index 62997e9cb7..f447fe8999 100644
--- a/applications/apertif/matlab/wg.m
+++ b/applications/apertif/matlab/wg.m
@@ -19,36 +19,37 @@
 %
 %-----------------------------------------------------------------------------
 % 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;
+
+% 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;
-- 
GitLab