diff --git a/applications/apertif/matlab/FIR_LPF_ApertifCF.m b/applications/apertif/matlab/FIR_LPF_ApertifCF.m
index 68bd2d8b72722a8ddde6724d39d1b38ed1e0659e..496056f22bab6621db33d61b9c3fe07a7336fa08 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 913e9d765ffa8cc06566aa01311c0458b6560cf1..d805ee11b2f354e6fdc6142154d88669a2997914 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 7ad14f9d70e551dc510c713c9d8d811e4e885696..d6940b39396e3c89bfb2a1799c4b80a6d088d543 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 516527f5f442d04e98d6a6dba42479aefc042521..e41bed4e941f9043f7efcdede11b9b64e23c06ff 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 bd49962732de73be46dd986dede8610de2907fab..c9bcf53dc64bf034ccdb541e43922b06bae35677 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 de868e147de51fb3d427b3526a21b2edd64c22e7..7826a703fa79dae8d72bb455606969d45cd23e05 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 1f2f70d28e370374c893c95ba873862cfbeee8dd..0a98ea43659e5aad12ebeef965105aab92f5f211 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 22b8bf8ea2488810d41454463c451a7f0227f5d0..8c2762f17e5830dba3ad51d388d5fd648f947c6b 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 32552bd55bd3041a5fe8bc81270ef158b8d69b1c..d0499ace6461eebd67a0e17c32d641d659fe4e46 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 8197c4cf753810da908e6e2a5ab23ff9b2d200d8..c84676aa17eb86b1605c318b8e538d3e4211d1db 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 5f5184aecb588571e7a05f5b323265ebd5f61ce4..1618c7caf76bc72710e656f8ae8ae5562b82a3ed 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 5051dc2c8cd475bd090bbbf521537984f56dfd7a..3c2584b65469bcbd09f40e519b3ee0f8619755be 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 9553b5fb3349caac1ec2d001639ec0707d27a516..d0696622d76493502bb94bd8bcd8d53c444bb590 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 6e3832eed36bfc482b6ba0641c54b9ac40d13c4a..78af6bb8703f8d513ae6242f9d6412d17713f9fd 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 62997e9cb72cd32afae9996c975afea24a5112ee..f447fe8999cf2913c8b0cdf5290606f82efdd047 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;