From c8924714ef4fad171121132b60349309d47694b7 Mon Sep 17 00:00:00 2001
From: Marek Blok <Marek.Blok@pg.edu.pl>
Date: Wed, 23 Jun 2021 16:13:25 +0200
Subject: [PATCH] matlab tools in Cw1 update

---
 Cw1/matlab/PERgraf.m       | 265 ++++++++++++++++++++++++++++++++++++-
 Cw1/matlab/perGUI.m        | 217 ++++++++++++++++--------------
 Cw1/matlab/readaudiofile.m |   2 +-
 3 files changed, 375 insertions(+), 109 deletions(-)

diff --git a/Cw1/matlab/PERgraf.m b/Cw1/matlab/PERgraf.m
index dc9c555..a231ec9 100644
--- a/Cw1/matlab/PERgraf.m
+++ b/Cw1/matlab/PERgraf.m
@@ -2,6 +2,14 @@ function PERgraf(Akcja, param)
 
 global supress_msgbox
 
+% \fixed 2021.04.09 fileread replaced with audiofileread
+%                   use addpath only when ont deployed
+%                   added rmpath on Exit and DeleteFcn
+% \fixed 2019.03.06 figure now uses IntegerHandle == 'off' so it does not
+%                   conflict with other tools
+% \fixed 2018.04.14 included readaudiofile (previously fileread)
+%                   replaced boxcar with rectwin
+%                   added selec_dir button
 % \fixed 2018.03.02 pwelch: warning for L < M
 % \fixed 2015.10.19 pwelch + detrend is now used instead of psd
 %
@@ -44,9 +52,11 @@ if nargin == 0  % LAUNCH GUI
   if isempty(findobj(0, 'tag', 'perGUI')) 
 %    set(0, 'DefaultFigureVisible', 'off'); 	   
     fig = perGUI;
+    set(fig, 'IntegerHandle','off');
 %    set(0, 'DefaultFigureVisible', 'on'); 	   
-    set(fig,'tag', 'perGUI', 'Visible', 'on', 'Units', 'pixels');
-    set(fig,'NumberTitle', 'off', 'Name','Periodogramowe estymatory widma gęstości mocy ver. 1.3e (dr inż. Marek Blok 02.03.2018)')    
+    set(fig,'tag', 'perGUI', 'Visible', 'on', 'Units', 'pixels', 'DeleteFcn', 'PERgraf(''Exit'')');
+    %set(fig,'NumberTitle', 'off', 'Name',['Periodogramowe estymatory widma gęstości mocy ver. 1.4 (dr inż. Marek Blok 16.04.2018) ', pwd])    
+    UpdateFigTitle();
 
     PERgraf('Init');
     PERgraf('signal');
@@ -101,18 +111,37 @@ h_lock=findobj(fig,'tag', 'lock_checkbox');
 
 
 if strcmp(Akcja, 'Exit')
+  if (~isdeployed)
+    path2rm = getappdata(fig, 'pwd');
+    rmpath(path2rm);
+  end
   close(fig);
+  disp('Closed PERgraf');
+  return;
+  
+elseif strcmp(Akcja, 'select_dir')
+  dir = uigetdir();
+  if ischar(dir),
+    cd(dir);
+    UpdateFigTitle();
+  end
   return;
+  
 elseif strcmp(Akcja, 'Init')
   % UserData przechowuje wartości domyślne
   supress_msgbox = 0;
+
+  if (~isdeployed)
+    setappdata(fig, 'pwd', pwd);
+    addpath(pwd,'-end');
+  end
   
   set(hEditX,'UserData','randn(1,L)');
   set(hEditX,'String','randn(1,L)');
   set(hEditX,'Max', 2);
 
-  set(hEditW,'UserData','boxcar(M)');
-  set(hEditW,'String','boxcar(M)');
+  set(hEditW,'UserData','rectwin(M)');
+  set(hEditW,'String','rectwin(M)');
 
   set(hEditL,'UserData','100');
   set(hEditL,'String','100');
@@ -219,7 +248,7 @@ elseif strcmp(Akcja, 'new')
   pom(Ktory,:)=pom(old_Ktory,:);
   set(hEditX,'UserData',pom);
   pom=get(hEditW,'UserData');
-%   pom(Ktory,1:10)=['boxcar(M)' 0];
+%   pom(Ktory,1:10)=['rectwin(M)' 0];
   pom(Ktory,:)=pom(old_Ktory,:);
   set(hEditW,'UserData',pom);
 
@@ -301,7 +330,7 @@ elseif strcmp(Akcja, 'Reset')
   pom(Ktory,1:11)=['randn(1,L)' 0];
   set(hEditX,'UserData',pom);
   pom=get(hEditW,'UserData');
-  pom(Ktory,1:10)=['boxcar(M)' 0];
+  pom(Ktory,1:10)=['rectwin(M)' 0];
   set(hEditW,'UserData',pom);
 
   pom=get(hEditL,'UserData');
@@ -1311,4 +1340,226 @@ for ind=1:size(pom, 1);
     Fs = 1;
   end;
   maxFs = max([maxFs, Fs]);
-end;
\ No newline at end of file
+end;
+
+function [x, Fs] = readaudiofile(filename, param)
+% [x, Fs] = readaudiofile(filename, param)
+%
+% returns vector x of the size SIZE=[samples channels].
+%  eg. x = x(:,1) + j*x(:,2);
+%
+% special uses:
+%  param == 'size': returns SIZE in x
+%  param == 'cplx': for stereo files returns x as a complex vector instead of matrix 
+%
+%  supported file types:
+%    *.flt
+%    *.wav
+%    *.tape
+% last modification: 2021.03.29
+% Author: Marek Blok
+
+return_cplx = 0;
+if nargin == 1,
+  param = inf;
+else
+  if strcmp(param, 'cplx') == 1,
+    return_cplx = 1;
+    param = inf;
+  end
+end
+
+ind = find(filename == '.');
+if length(ind) == 0,
+  file_type = 'w'; % *.wav
+else
+  ind = ind(end);
+  
+  temp = filename(ind+1:end);
+  
+  file_type = 'u'; % unknown format
+  if strcmp(temp, 'flt') == 1,
+    file_type = 'f'; % two channel floting point
+  elseif strcmp(temp, 'wav') == 1,
+    file_type = 'w'; % *.wav
+  elseif strcmp(temp, 'tape') == 1,
+    file_type = 't'; % *.tape
+  end
+end
+
+switch file_type,
+  case 'w',
+    if strcmp(param, 'size') == 1,
+      if exist('audioread','file') == 0
+        x = wavread(filename, 'size');
+        %  siz = [samples channels].
+      else
+        info = audioinfo(filename);
+        x = [info.TotalSamples, info.NumChannels];
+        Fs = info.SampleRate;
+      end      
+    else
+      if isfinite(param)
+        if exist('audioread','file') == 0
+          [x, Fs] = wavread(filename, param);
+        else
+          if length(param) == 1
+            param = [1, param];
+          end
+          [x, Fs] = audioread(filename, param);
+        end
+      else
+        if exist('audioread','file') == 0
+          [x, Fs] = wavread(filename);
+        else
+          [x, Fs] = audioread(filename);
+        end
+      end
+    end
+    
+  case 't'
+    plik = fopen(filename, 'rb');
+    if plik == -1,
+      error('File does not exist !!!');
+    end
+    
+    header.size = fread(plik, 1, 'uint32', 0) + 4;
+
+    header.fname      = char(fread(plik, 256, 'char', 0).');
+    header.cfg_fname  = char(fread(plik, 256, 'char', 0).');
+    header.sw_rev     = fread(plik, 1, 'uint32', 0);
+    header.hw_rev     = fread(plik, 1, 'uint32', 0);
+    header.file_      = fread(plik, 1, 'uint32', 0);
+    header.tape_type  = fread(plik, 1, 'uint32', 0);
+    header.start_time = fread(plik, 1, 'int32', 0); % time_t
+    header.end_time   = fread(plik, 1, 'int32', 0); % time_t
+    
+    header.total_samples  = fread(plik, 1, 'uint32', 0); 
+    file_length = header.total_samples * 4  + header.size
+    header.current_sample = fread(plik, 1, 'uint32', 0); 
+    header.loop_start     = fread(plik, 1, 'int64', 0); 
+    header.loop_end       = fread(plik, 1, 'int64', 0); 
+    header.loop           = fread(plik, 1, 'int32', 0); 
+    header.group_size_32  = fread(plik, 1, 'uint32', 0); 
+    header.block_size     = fread(plik, 1, 'uint32', 0); 
+    header.block_count    = fread(plik, 1, 'uint32', 0); 
+    header.fifo_size      = fread(plik, 1, 'uint32', 0); 
+
+
+    header.comment      = char(fread(plik, 256, 'char', 0).');
+    header.tmp  = char(fread(plik, 20, 'char', 0).'); % time_t
+    header.status       = fread(plik, 1, 'uint32', 0); 
+    header.timestamps   = fread(plik, 1, 'int32', 0); 
+    header.freq         = fread(plik, 1, 'float', 0); 
+    header.cplx_datarate = fread(plik, 1, 'float', 0); 
+    
+%     ftell(plik)
+    header.reserved = fread(plik, 128, 'uint32', 0);
+%     header.reserved.'
+    
+%    header
+    ftell(plik)
+
+    header.sample_type = 2;
+    header.ch_no = 2;
+    header.Fs = NaN;
+    
+    sample_type = 'int16';
+    sample_size = 2;
+
+    header_size = header.size;
+    if strcmp(param, 'size') == 1,
+      fseek(plik, 0, 'eof');
+      size = (ftell(plik) - header_size) / sample_size / header.ch_no; % sizeof(float) *2
+      x = size;
+    else
+      fseek(plik, header_size, 'bof');
+      
+      len = param(1);
+      if length(param) > 1,
+        fseek(plik, sample_size*header.ch_no*(param(1)-1), 'cof');
+        len = param(2) - param(1) + 1;
+      end
+        
+%       x = fread(plik, [header.ch_no, len], sample_type);
+      x = fread(plik, [header.ch_no, len], sample_type, 0);
+      x = x.';
+    end
+    fclose(plik);
+    
+  case 'f'
+    plik = fopen(filename, 'rb');
+    if plik == -1,
+      error('File does not exist !!!');
+    end
+    
+    % 3 B - wersja pliku (w tym typ próbek)
+    % 1 B - liczba kanałów
+    % 4 B - szybkość próbkowania
+    header_size = 8;
+    header.ver = fread(plik, 1, 'uint8');
+    header.sample_type = fread(plik, 1, 'uint16');
+    header.ch_no = fread(plik, 1, 'uint8');
+    header.Fs = fread(plik, 1, 'uint32');
+    
+    Fs = header.Fs;
+    
+    switch (header.ver),
+      case 0,
+        switch (header.sample_type),
+          case 0,
+            sample_type = 'float';
+            sample_size = 4;
+          case 1,
+            sample_type = 'uchar';
+            sample_size = 1;
+          case 2,
+            sample_type = 'short';
+            sample_size = 2;
+          case 3,
+            sample_type = 'int';
+            sample_size = 4;
+          otherwise
+            error('Unsupported *.flt sample type !!!');
+        end
+      otherwise
+        error('Unsupported *.flt file version !!!');
+    end
+        
+    
+    if strcmp(param, 'size') == 1,
+      fseek(plik, 0, 'eof');
+      size = (ftell(plik) - header_size) / sample_size / header.ch_no; % sizeof(float) *2
+      x = size;
+    else
+      len = param(1);
+      status = 0;
+      if length(param) > 1,
+        status = fseek(plik, sample_size*header.ch_no*(param(1)-1), 'cof');
+        len = param(2) - param(1) + 1;
+      end
+        
+      if (status == -1)
+        x = [];
+      else
+        x = fread(plik, [header.ch_no, len], sample_type);
+        x = x.';
+      end
+    end
+    
+    fclose(plik);
+  otherwise
+    error('Unsupported file format !!!');
+end
+
+if return_cplx == 1,
+  if length(x(1,:)) == 2,
+    x = x(:,1) + j*x(:,2);
+  end
+end
+
+function UpdateFigTitle
+fig=findobj(0, 'tag', 'perGUI');
+set(fig,'NumberTitle', 'off', 'Name',['Periodogram based power spectral desity estimators ver. 1.4.1 (Marek.Blok@pg.edu.pl 2021.04.09) ', pwd]);
+
+
diff --git a/Cw1/matlab/perGUI.m b/Cw1/matlab/perGUI.m
index b695a89..f40a00b 100644
--- a/Cw1/matlab/perGUI.m
+++ b/Cw1/matlab/perGUI.m
@@ -1,4 +1,4 @@
-function fig_h=DrawFig(state)
+function fig_h=perGUI(state)
 if nargin == 0, state = 'on'; end;
 
 fig_h=figure('Visible', state);
@@ -11,15 +11,15 @@ set(fig_h, ...
   );
 set(fig_h, ...
   'Units', 'Normalized',...
-  'Position', [0.1304687 0.1697917 0.7257813 0.6875000]...
+  'Position', [0.2391667 0.1807407 0.5420833 0.6392593]...
   );
 h=axes;
 set(h, ...
   'Units', 'Normalized',...
-  'Position', [0.2906351 0.6030303 0.6953714 0.1515152],...
+  'Position', [0.2905457 0.6030841 0.6951576 0.1515287],...
   'Color', [1.0000 1.0000 1.0000],...
-  'XColor', [0.0000 0.0000 0.0000],...
-  'YColor', [0.0000 0.0000 0.0000],...
+  'XColor', [0.1500 0.1500 0.1500],...
+  'YColor', [0.1500 0.1500 0.1500],...
   'FontSize', 10,...
   'Box', 'on',...
   'Tag', 'Signal_im_axes'...
@@ -27,10 +27,10 @@ set(h, ...
 h=axes;
 set(h, ...
   'Units', 'Normalized',...
-  'Position', [0.2938644 0.0424242 0.6932185 0.5015152],...
+  'Position', [0.2937740 0.0424280 0.6930054 0.5015599],...
   'Color', [1.0000 1.0000 1.0000],...
-  'XColor', [0.0000 0.0000 0.0000],...
-  'YColor', [0.0000 0.0000 0.0000],...
+  'XColor', [0.1500 0.1500 0.1500],...
+  'YColor', [0.1500 0.1500 0.1500],...
   'FontSize', 10,...
   'Box', 'on',...
   'Tag', 'per_axes'...
@@ -38,10 +38,10 @@ set(h, ...
 h=axes;
 set(h, ...
   'Units', 'Normalized',...
-  'Position', [0.2927879 0.8181818 0.6921421 0.1469697],...
+  'Position', [0.2926979 0.8182547 0.6919293 0.1469828],...
   'Color', [1.0000 1.0000 1.0000],...
-  'XColor', [0.0000 0.0000 0.0000],...
-  'YColor', [0.0000 0.0000 0.0000],...
+  'XColor', [0.1500 0.1500 0.1500],...
+  'YColor', [0.1500 0.1500 0.1500],...
   'FontSize', 10,...
   'Box', 'on',...
   'Tag', 'Signal_re_axes'...
@@ -50,8 +50,8 @@ h=uicontrol;
 set(h, ...
   'Style', 'frame',...
   'Units', 'Normalized',...
-  'Position', [0.0021529 0.2696970 0.2583423 0.1136364],...
-  'BackGroundColor', [0.9255 0.9137 0.8471],...
+  'Position', [0.0021522 0.2697210 0.2582629 0.1136465],...
+  'BackGroundColor', [0.9400 0.9400 0.9400],...
   'HorizontalAlignment', 'center',...
   'String', '',...
   'Value', 0,...
@@ -65,8 +65,8 @@ h=uicontrol;
 set(h, ...
   'Style', 'frame',...
   'Units', 'Normalized',...
-  'Position', [0.0021529 0.0500000 0.2583423 0.2127273],...
-  'BackGroundColor', [0.9255 0.9137 0.8471],...
+  'Position', [0.0021522 0.0500045 0.2582629 0.2127462],...
+  'BackGroundColor', [0.9400 0.9400 0.9400],...
   'HorizontalAlignment', 'center',...
   'String', '',...
   'Value', 0,...
@@ -80,8 +80,8 @@ h=uicontrol;
 set(h, ...
   'Style', 'frame',...
   'Units', 'Normalized',...
-  'Position', [0.0032293 0.8833333 0.2583423 0.1075758],...
-  'BackGroundColor', [0.9255 0.9137 0.8471],...
+  'Position', [0.0032283 0.8834121 0.2582629 0.1075853],...
+  'BackGroundColor', [0.9400 0.9400 0.9400],...
   'HorizontalAlignment', 'center',...
   'String', '',...
   'Value', 0,...
@@ -95,8 +95,8 @@ h=uicontrol;
 set(h, ...
   'Style', 'frame',...
   'Units', 'Normalized',...
-  'Position', [0.0032293 0.6590909 0.2583423 0.2181818],...
-  'BackGroundColor', [0.9255 0.9137 0.8471],...
+  'Position', [0.0032283 0.6591497 0.2582629 0.2182013],...
+  'BackGroundColor', [0.9400 0.9400 0.9400],...
   'HorizontalAlignment', 'center',...
   'String', '',...
   'Value', 0,...
@@ -110,8 +110,8 @@ h=uicontrol;
 set(h, ...
   'Style', 'frame',...
   'Units', 'Normalized',...
-  'Position', [0.0032293 0.3924242 0.2583423 0.2560606],...
-  'BackGroundColor', [0.9255 0.9137 0.8471],...
+  'Position', [0.0032283 0.3924592 0.2582629 0.2560834],...
+  'BackGroundColor', [0.9400 0.9400 0.9400],...
   'HorizontalAlignment', 'center',...
   'String', '',...
   'Value', 0,...
@@ -122,10 +122,25 @@ set(h, ...
   'Tag', 'frame4'...
   );
 h=uicontrol;
+set(h, ...
+  'Style', 'pushbutton',...
+  'Units', 'Normalized',...
+  'Position', [0.1898540 0.8424102 0.0630284 0.0301275],...
+  'BackGroundColor', [0.9400 0.9400 0.9400],...
+  'HorizontalAlignment', 'center',...
+  'String', 'Select dir',...
+  'Value', 0,...
+  'Visible', 'on',...
+  'FontName', 'MS Sans Serif',...
+  'Fontsize', 8,...
+  'Callback', 'PERgraf(''select_dir'')',...
+  'Tag', 'pushbutton7'...
+  );
+h=uicontrol;
 set(h, ...
   'Style', 'checkbox',...
   'Units', 'Normalized',...
-  'Position', [0.2927879 0.5500000 0.0538213 0.0348485],...
+  'Position', [0.2926979 0.5500490 0.0538048 0.0348516],...
   'BackGroundColor', [1.0000 1.0000 1.0000],...
   'HorizontalAlignment', 'center',...
   'String', 'lock',...
@@ -140,7 +155,7 @@ h=uicontrol;
 set(h, ...
   'Style', 'edit',...
   'Units', 'Normalized',...
-  'Position', [0.1743811 0.0575758 0.0807320 0.0393939],...
+  'Position', [0.1743274 0.0575809 0.0807071 0.0393975],...
   'BackGroundColor', [1.0000 1.0000 1.0000],...
   'HorizontalAlignment', 'center',...
   'String', 'Edit Text',...
@@ -155,8 +170,8 @@ h=uicontrol;
 set(h, ...
   'Style', 'text',...
   'Units', 'Normalized',...
-  'Position', [0.1001076 0.0606061 0.0699677 0.0333333],...
-  'BackGroundColor', [0.9250 0.9140 0.8470],...
+  'Position', [0.1000769 0.0606115 0.0699462 0.0333363],...
+  'BackGroundColor', [0.9400 0.9400 0.9400],...
   'HorizontalAlignment', 'left',...
   'String', 'Fs [Sa/s] =',...
   'Value', 0,...
@@ -170,7 +185,7 @@ h=uicontrol;
 set(h, ...
   'Style', 'popupmenu',...
   'Units', 'Normalized',...
-  'Position', [0.0086114 0.6106061 0.2475780 0.0318182],...
+  'Position', [0.0086088 0.6106605 0.2475019 0.0318210],...
   'BackGroundColor', [1.0000 1.0000 1.0000],...
   'HorizontalAlignment', 'center',...
   'String', ['Raw periodograph' ,...
@@ -189,7 +204,7 @@ h=uicontrol;
 set(h, ...
   'Style', 'edit',...
   'Units', 'Normalized',...
-  'Position', [0.1431647 0.2818182 0.0699677 0.0409091],...
+  'Position', [0.1431207 0.2818433 0.0699462 0.0409127],...
   'BackGroundColor', [1.0000 1.0000 1.0000],...
   'HorizontalAlignment', 'center',...
   'String', '2.0',...
@@ -204,8 +219,8 @@ h=uicontrol;
 set(h, ...
   'Style', 'text',...
   'Units', 'Normalized',...
-  'Position', [0.1108719 0.2878788 0.0322928 0.0272727],...
-  'BackGroundColor', [0.9255 0.9137 0.8471],...
+  'Position', [0.1108378 0.2879044 0.0322829 0.0272752],...
+  'BackGroundColor', [0.9400 0.9400 0.9400],...
   'HorizontalAlignment', 'left',...
   'String', 'max:',...
   'Value', 0,...
@@ -219,7 +234,7 @@ h=uicontrol;
 set(h, ...
   'Style', 'edit',...
   'Units', 'Normalized',...
-  'Position', [0.0365985 0.2803030 0.0699677 0.0409091],...
+  'Position', [0.0365872 0.2803280 0.0699462 0.0409127],...
   'BackGroundColor', [1.0000 1.0000 1.0000],...
   'HorizontalAlignment', 'center',...
   'String', '0.0',...
@@ -234,8 +249,8 @@ h=uicontrol;
 set(h, ...
   'Style', 'text',...
   'Units', 'Normalized',...
-  'Position', [0.0075350 0.2878788 0.0258342 0.0272727],...
-  'BackGroundColor', [0.9255 0.9137 0.8471],...
+  'Position', [0.0075327 0.2879044 0.0258263 0.0272752],...
+  'BackGroundColor', [0.9400 0.9400 0.9400],...
   'HorizontalAlignment', 'left',...
   'String', 'min:',...
   'Value', 0,...
@@ -249,8 +264,8 @@ h=uicontrol;
 set(h, ...
   'Style', 'radiobutton',...
   'Units', 'Normalized',...
-  'Position', [0.2185145 0.3030303 0.0322928 0.0257576],...
-  'BackGroundColor', [0.9255 0.9137 0.8471],...
+  'Position', [0.2184473 0.3030573 0.0322829 0.0257599],...
+  'BackGroundColor', [0.9400 0.9400 0.9400],...
   'HorizontalAlignment', 'center',...
   'String', '+',...
   'Value', 1,...
@@ -264,8 +279,8 @@ h=uicontrol;
 set(h, ...
   'Style', 'radiobutton',...
   'Units', 'Normalized',...
-  'Position', [0.2185145 0.2772727 0.0322928 0.0257576],...
-  'BackGroundColor', [0.9255 0.9137 0.8471],...
+  'Position', [0.2184473 0.2772974 0.0322829 0.0257599],...
+  'BackGroundColor', [0.9400 0.9400 0.9400],...
   'HorizontalAlignment', 'center',...
   'String', 'x',...
   'Value', 0,...
@@ -279,8 +294,8 @@ h=uicontrol;
 set(h, ...
   'Style', 'slider',...
   'Units', 'Normalized',...
-  'Position', [0.1173305 0.3287879 0.0193757 0.0469697],...
-  'BackGroundColor', [0.9255 0.9137 0.8471],...
+  'Position', [0.1172944 0.3288172 0.0193697 0.0469739],...
+  'BackGroundColor', [0.9400 0.9400 0.9400],...
   'HorizontalAlignment', 'center',...
   'String', '',...
   'Value', 0,...
@@ -294,7 +309,7 @@ h=uicontrol;
 set(h, ...
   'Style', 'edit',...
   'Units', 'Normalized',...
-  'Position', [0.1819160 0.3333333 0.0699677 0.0409091],...
+  'Position', [0.1818601 0.3333630 0.0699462 0.0409127],...
   'BackGroundColor', [1.0000 1.0000 1.0000],...
   'HorizontalAlignment', 'center',...
   'String', '0.1',...
@@ -309,8 +324,8 @@ h=uicontrol;
 set(h, ...
   'Style', 'text',...
   'Units', 'Normalized',...
-  'Position', [0.1506997 0.3424242 0.0269107 0.0272727],...
-  'BackGroundColor', [0.9255 0.9137 0.8471],...
+  'Position', [0.1506533 0.3424548 0.0269024 0.0272752],...
+  'BackGroundColor', [0.9400 0.9400 0.9400],...
   'HorizontalAlignment', 'left',...
   'String', 'dA =',...
   'Value', 0,...
@@ -324,7 +339,7 @@ h=uicontrol;
 set(h, ...
   'Style', 'edit',...
   'Units', 'Normalized',...
-  'Position', [0.0376749 0.3333333 0.0699677 0.0409091],...
+  'Position', [0.0376633 0.3333630 0.0699462 0.0409127],...
   'BackGroundColor', [1.0000 1.0000 1.0000],...
   'HorizontalAlignment', 'center',...
   'String', '1.0',...
@@ -339,8 +354,8 @@ h=uicontrol;
 set(h, ...
   'Style', 'text',...
   'Units', 'Normalized',...
-  'Position', [0.0107643 0.3409091 0.0258342 0.0272727],...
-  'BackGroundColor', [0.9255 0.9137 0.8471],...
+  'Position', [0.0107610 0.3409395 0.0258263 0.0272752],...
+  'BackGroundColor', [0.9400 0.9400 0.9400],...
   'HorizontalAlignment', 'left',...
   'String', 'A =',...
   'Value', 0,...
@@ -354,8 +369,8 @@ h=uicontrol;
 set(h, ...
   'Style', 'pushbutton',...
   'Units', 'Normalized',...
-  'Position', [0.0096878 0.0575758 0.0839612 0.0439394],...
-  'BackGroundColor', [0.9255 0.9137 0.8471],...
+  'Position', [0.0096849 0.0575809 0.0839354 0.0439433],...
+  'BackGroundColor', [0.9400 0.9400 0.9400],...
   'HorizontalAlignment', 'center',...
   'String', 'PSD redraw',...
   'Value', 0,...
@@ -369,8 +384,8 @@ h=uicontrol;
 set(h, ...
   'Style', 'text',...
   'Units', 'Normalized',...
-  'Position', [0.1313240 0.4500000 0.0301399 0.0318182],...
-  'BackGroundColor', [0.9255 0.9137 0.8471],...
+  'Position', [0.1312836 0.4500401 0.0301307 0.0318210],...
+  'BackGroundColor', [0.9400 0.9400 0.9400],...
   'HorizontalAlignment', 'left',...
   'String', '[%]',...
   'Value', 0,...
@@ -384,8 +399,8 @@ h=uicontrol;
 set(h, ...
   'Style', 'pushbutton',...
   'Units', 'Normalized',...
-  'Position', [0.0043057 0.0060606 0.0828848 0.0393939],...
-  'BackGroundColor', [0.9255 0.9137 0.8471],...
+  'Position', [0.0043044 0.0060611 0.0828593 0.0393975],...
+  'BackGroundColor', [0.9400 0.9400 0.9400],...
   'HorizontalAlignment', 'center',...
   'String', 'Exit',...
   'Value', 0,...
@@ -399,7 +414,7 @@ h=uicontrol;
 set(h, ...
   'Style', 'edit',...
   'Units', 'Normalized',...
-  'Position', [0.1829925 0.0045455 0.0807320 0.0393939],...
+  'Position', [0.1829362 0.0045459 0.0807071 0.0393975],...
   'BackGroundColor', [1.0000 1.0000 1.0000],...
   'HorizontalAlignment', 'center',...
   'String', 'Edit Text',...
@@ -414,7 +429,7 @@ h=uicontrol;
 set(h, ...
   'Style', 'text',...
   'Units', 'Normalized',...
-  'Position', [0.1141012 0.0075758 0.0667384 0.0333333],...
+  'Position', [0.1140661 0.0075764 0.0667179 0.0333363],...
   'BackGroundColor', [1.0000 1.0000 1.0000],...
   'HorizontalAlignment', 'left',...
   'String', 'dY [dB] =',...
@@ -429,7 +444,7 @@ h=uicontrol;
 set(h, ...
   'Style', 'checkbox',...
   'Units', 'Normalized',...
-  'Position', [0.9289559 0.5469697 0.0538213 0.0348485],...
+  'Position', [0.9286703 0.5470185 0.0538048 0.0348516],...
   'BackGroundColor', [1.0000 1.0000 1.0000],...
   'HorizontalAlignment', 'center',...
   'String', 'dB',...
@@ -444,8 +459,8 @@ h=uicontrol;
 set(h, ...
   'Style', 'checkbox',...
   'Units', 'Normalized',...
-  'Position', [0.1001076 0.2257576 0.0419806 0.0303030],...
-  'BackGroundColor', [0.9255 0.9137 0.8471],...
+  'Position', [0.1000769 0.2257777 0.0419677 0.0303057],...
+  'BackGroundColor', [0.9400 0.9400 0.9400],...
   'HorizontalAlignment', 'center',...
   'String', 'b',...
   'Value', 0,...
@@ -459,8 +474,8 @@ h=uicontrol;
 set(h, ...
   'Style', 'checkbox',...
   'Units', 'Normalized',...
-  'Position', [0.0538213 0.2257576 0.0419806 0.0303030],...
-  'BackGroundColor', [0.9255 0.9137 0.8471],...
+  'Position', [0.0538048 0.2257777 0.0419677 0.0303057],...
+  'BackGroundColor', [0.9400 0.9400 0.9400],...
   'HorizontalAlignment', 'center',...
   'String', 'g',...
   'Value', 0,...
@@ -474,8 +489,8 @@ h=uicontrol;
 set(h, ...
   'Style', 'checkbox',...
   'Units', 'Normalized',...
-  'Position', [0.0107643 0.2257576 0.0419806 0.0303030],...
-  'BackGroundColor', [0.9255 0.9137 0.8471],...
+  'Position', [0.0107610 0.2257777 0.0419677 0.0303057],...
+  'BackGroundColor', [0.9400 0.9400 0.9400],...
   'HorizontalAlignment', 'center',...
   'String', 'r',...
   'Value', 0,...
@@ -489,8 +504,8 @@ h=uicontrol;
 set(h, ...
   'Style', 'pushbutton',...
   'Units', 'Normalized',...
-  'Position', [0.0710441 0.8939394 0.0645856 0.0454545],...
-  'BackGroundColor', [0.9255 0.9137 0.8471],...
+  'Position', [0.0710223 0.8940191 0.0645657 0.0454586],...
+  'BackGroundColor', [0.9400 0.9400 0.9400],...
   'HorizontalAlignment', 'center',...
   'String', 'Delete',...
   'Value', 0,...
@@ -504,8 +519,8 @@ h=uicontrol;
 set(h, ...
   'Style', 'pushbutton',...
   'Units', 'Normalized',...
-  'Position', [0.0129171 0.8939394 0.0516685 0.0454545],...
-  'BackGroundColor', [0.9255 0.9137 0.8471],...
+  'Position', [0.0129131 0.8940191 0.0516526 0.0454586],...
+  'BackGroundColor', [0.9400 0.9400 0.9400],...
   'HorizontalAlignment', 'center',...
   'String', 'New',...
   'Value', 0,...
@@ -519,8 +534,8 @@ h=uicontrol;
 set(h, ...
   'Style', 'text',...
   'Units', 'Normalized',...
-  'Position', [0.0086114 0.1090909 0.2454252 0.0924242],...
-  'BackGroundColor', [0.9255 0.9137 0.8471],...
+  'Position', [0.0086088 0.1091006 0.2453497 0.0924325],...
+  'BackGroundColor', [0.9400 0.9400 0.9400],...
   'HorizontalAlignment', 'center',...
   'String', 'Static Text',...
   'Value', 0,...
@@ -534,8 +549,8 @@ h=uicontrol;
 set(h, ...
   'Style', 'text',...
   'Units', 'Normalized',...
-  'Position', [0.0075350 0.2015152 0.1786868 0.0272727],...
-  'BackGroundColor', [0.9255 0.9137 0.8471],...
+  'Position', [0.0075327 0.2015331 0.1786318 0.0272752],...
+  'BackGroundColor', [0.9400 0.9400 0.9400],...
   'HorizontalAlignment', 'left',...
   'String', 'Periodogram parameters',...
   'Value', 0,...
@@ -549,7 +564,7 @@ h=uicontrol;
 set(h, ...
   'Style', 'text',...
   'Units', 'Normalized',...
-  'Position', [0.1679225 0.4878788 0.0807320 0.0393939],...
+  'Position', [0.1678709 0.4879223 0.0807071 0.0393975],...
   'BackGroundColor', [1.0000 1.0000 1.0000],...
   'HorizontalAlignment', 'center',...
   'String', 'Edit Text',...
@@ -564,8 +579,8 @@ h=uicontrol;
 set(h, ...
   'Style', 'text',...
   'Units', 'Normalized',...
-  'Position', [0.1356297 0.4939394 0.0322928 0.0287879],...
-  'BackGroundColor', [0.9255 0.9137 0.8471],...
+  'Position', [0.1355880 0.4939834 0.0322829 0.0287904],...
+  'BackGroundColor', [0.9400 0.9400 0.9400],...
   'HorizontalAlignment', 'left',...
   'String', 'N =',...
   'Value', 0,...
@@ -579,7 +594,7 @@ h=uicontrol;
 set(h, ...
   'Style', 'edit',...
   'Units', 'Normalized',...
-  'Position', [0.0398278 0.6636364 0.0775027 0.0409091],...
+  'Position', [0.0398155 0.6636955 0.0774789 0.0409127],...
   'BackGroundColor', [1.0000 1.0000 1.0000],...
   'HorizontalAlignment', 'center',...
   'String', 'Edit Text',...
@@ -594,8 +609,8 @@ h=uicontrol;
 set(h, ...
   'Style', 'text',...
   'Units', 'Normalized',...
-  'Position', [0.0075350 0.6636364 0.0312164 0.0287879],...
-  'BackGroundColor', [0.9255 0.9137 0.8471],...
+  'Position', [0.0075327 0.6636955 0.0312068 0.0287904],...
+  'BackGroundColor', [0.9400 0.9400 0.9400],...
   'HorizontalAlignment', 'left',...
   'String', 'L =',...
   'Value', 0,...
@@ -609,8 +624,8 @@ h=uicontrol;
 set(h, ...
   'Style', 'checkbox',...
   'Units', 'Normalized',...
-  'Position', [0.1367061 0.5454545 0.1184069 0.0272727],...
-  'BackGroundColor', [0.9255 0.9137 0.8471],...
+  'Position', [0.1366641 0.5455032 0.1183705 0.0272752],...
+  'BackGroundColor', [0.9400 0.9400 0.9400],...
   'HorizontalAlignment', 'center',...
   'String', 'detrend',...
   'Value', 0,...
@@ -624,7 +639,7 @@ h=uicontrol;
 set(h, ...
   'Style', 'edit',...
   'Units', 'Normalized',...
-  'Position', [0.0409042 0.4454545 0.0807320 0.0393939],...
+  'Position', [0.0408916 0.4454943 0.0807071 0.0393975],...
   'BackGroundColor', [1.0000 1.0000 1.0000],...
   'HorizontalAlignment', 'center',...
   'String', 'Edit Text',...
@@ -639,8 +654,8 @@ h=uicontrol;
 set(h, ...
   'Style', 'text',...
   'Units', 'Normalized',...
-  'Position', [0.0096878 0.4454545 0.0301399 0.0318182],...
-  'BackGroundColor', [0.9255 0.9137 0.8471],...
+  'Position', [0.0096849 0.4454943 0.0301307 0.0318210],...
+  'BackGroundColor', [0.9400 0.9400 0.9400],...
   'HorizontalAlignment', 'left',...
   'String', 'O =',...
   'Value', 0,...
@@ -654,7 +669,7 @@ h=uicontrol;
 set(h, ...
   'Style', 'edit',...
   'Units', 'Normalized',...
-  'Position', [0.0538213 0.4000000 0.2012917 0.0363636],...
+  'Position', [0.0538048 0.4000357 0.2012298 0.0363669],...
   'BackGroundColor', [1.0000 1.0000 1.0000],...
   'HorizontalAlignment', 'center',...
   'String', 'Edit Text',...
@@ -669,8 +684,8 @@ h=uicontrol;
 set(h, ...
   'Style', 'text',...
   'Units', 'Normalized',...
-  'Position', [0.0118407 0.3984848 0.0430571 0.0318182],...
-  'BackGroundColor', [0.9255 0.9137 0.8471],...
+  'Position', [0.0118370 0.3985204 0.0430438 0.0318210],...
+  'BackGroundColor', [0.9400 0.9400 0.9400],...
   'HorizontalAlignment', 'left',...
   'String', 'w[n] =',...
   'Value', 0,...
@@ -684,7 +699,7 @@ h=uicontrol;
 set(h, ...
   'Style', 'edit',...
   'Units', 'Normalized',...
-  'Position', [0.1776103 0.6651515 0.0775027 0.0393939],...
+  'Position', [0.1775557 0.6652108 0.0774789 0.0393975],...
   'BackGroundColor', [1.0000 1.0000 1.0000],...
   'HorizontalAlignment', 'center',...
   'String', 'Edit Text',...
@@ -699,8 +714,8 @@ h=uicontrol;
 set(h, ...
   'Style', 'text',...
   'Units', 'Normalized',...
-  'Position', [0.1259419 0.6651515 0.0505920 0.0287879],...
-  'BackGroundColor', [0.9255 0.9137 0.8471],...
+  'Position', [0.1259032 0.6652108 0.0505765 0.0287904],...
+  'BackGroundColor', [0.9400 0.9400 0.9400],...
   'HorizontalAlignment', 'left',...
   'String', 'Noise=',...
   'Value', 0,...
@@ -714,7 +729,7 @@ h=uicontrol;
 set(h, ...
   'Style', 'edit',...
   'Units', 'Normalized',...
-  'Position', [0.0419806 0.4878788 0.0807320 0.0393939],...
+  'Position', [0.0419677 0.4879223 0.0807071 0.0393975],...
   'BackGroundColor', [1.0000 1.0000 1.0000],...
   'HorizontalAlignment', 'center',...
   'String', 'Edit Text',...
@@ -729,8 +744,8 @@ h=uicontrol;
 set(h, ...
   'Style', 'text',...
   'Units', 'Normalized',...
-  'Position', [0.0096878 0.4939394 0.0322928 0.0287879],...
-  'BackGroundColor', [0.9255 0.9137 0.8471],...
+  'Position', [0.0096849 0.4939834 0.0322829 0.0287904],...
+  'BackGroundColor', [0.9400 0.9400 0.9400],...
   'HorizontalAlignment', 'left',...
   'String', 'M =',...
   'Value', 0,...
@@ -744,7 +759,7 @@ h=uicontrol;
 set(h, ...
   'Style', 'edit',...
   'Units', 'Normalized',...
-  'Position', [0.1442411 0.8939394 0.1108719 0.0424242],...
+  'Position', [0.1441968 0.8940191 0.1108378 0.0424280],...
   'BackGroundColor', [1.0000 1.0000 1.0000],...
   'HorizontalAlignment', 'center',...
   'String', 'Edit Text',...
@@ -759,7 +774,7 @@ h=uicontrol;
 set(h, ...
   'Style', 'popupmenu',...
   'Units', 'Normalized',...
-  'Position', [0.0129171 0.9484848 0.2432723 0.0318182],...
+  'Position', [0.0129131 0.9485694 0.2431975 0.0318210],...
   'BackGroundColor', [1.0000 1.0000 1.0000],...
   'HorizontalAlignment', 'center',...
   'String', 'Popup Menu',...
@@ -774,8 +789,8 @@ h=uicontrol;
 set(h, ...
   'Style', 'checkbox',...
   'Units', 'Normalized',...
-  'Position', [0.1237890 0.8439394 0.1194833 0.0287879],...
-  'BackGroundColor', [0.9255 0.9137 0.8471],...
+  'Position', [0.1237510 0.8435689 0.066 0.0289687],...
+  'BackGroundColor', [0.9400 0.9400 0.9400],...
   'HorizontalAlignment', 'center',...
   'String', 'real',...
   'Value', 0,...
@@ -789,8 +804,8 @@ h=uicontrol;
 set(h, ...
   'Style', 'text',...
   'Units', 'Normalized',...
-  'Position', [0.0086114 0.5803030 0.1582347 0.0287879],...
-  'BackGroundColor', [0.9255 0.9137 0.8471],...
+  'Position', [0.0086088 0.5803548 0.1581860 0.0287904],...
+  'BackGroundColor', [0.9400 0.9400 0.9400],...
   'HorizontalAlignment', 'left',...
   'String', 'Peridograf parameters',...
   'Value', 0,...
@@ -804,7 +819,7 @@ h=uicontrol;
 set(h, ...
   'Style', 'edit',...
   'Units', 'Normalized',...
-  'Position', [0.0409042 0.5393939 0.0807320 0.0393939],...
+  'Position', [0.0408916 0.5394420 0.0807071 0.0393975],...
   'BackGroundColor', [1.0000 1.0000 1.0000],...
   'HorizontalAlignment', 'center',...
   'String', 'Edit Text',...
@@ -819,8 +834,8 @@ h=uicontrol;
 set(h, ...
   'Style', 'text',...
   'Units', 'Normalized',...
-  'Position', [0.0129171 0.5469697 0.0258342 0.0272727],...
-  'BackGroundColor', [0.9255 0.9137 0.8471],...
+  'Position', [0.0129131 0.5470185 0.0258263 0.0272752],...
+  'BackGroundColor', [0.9400 0.9400 0.9400],...
   'HorizontalAlignment', 'left',...
   'String', 'K =',...
   'Value', 0,...
@@ -834,7 +849,7 @@ h=uicontrol;
 set(h, ...
   'Style', 'edit',...
   'Units', 'Normalized',...
-  'Position', [0.0398278 0.7090909 0.2152853 0.1272727],...
+  'Position', [0.0398155 0.7091541 0.2152191 0.1272841],...
   'BackGroundColor', [1.0000 1.0000 1.0000],...
   'HorizontalAlignment', 'center',...
   'String', 'Edit Text',...
@@ -849,8 +864,8 @@ h=uicontrol;
 set(h, ...
   'Style', 'text',...
   'Units', 'Normalized',...
-  'Position', [0.0118407 0.8045455 0.0258342 0.0272727],...
-  'BackGroundColor', [0.9255 0.9137 0.8471],...
+  'Position', [0.0118370 0.8046172 0.0258263 0.0272752],...
+  'BackGroundColor', [0.9400 0.9400 0.9400],...
   'HorizontalAlignment', 'left',...
   'String', 'x =',...
   'Value', 0,...
@@ -864,8 +879,8 @@ h=uicontrol;
 set(h, ...
   'Style', 'text',...
   'Units', 'Normalized',...
-  'Position', [0.0107643 0.8439394 0.1087191 0.0257576],...
-  'BackGroundColor', [0.9255 0.9137 0.8471],...
+  'Position', [0.0107610 0.8440146 0.1086856 0.0257599],...
+  'BackGroundColor', [0.9400 0.9400 0.9400],...
   'HorizontalAlignment', 'left',...
   'String', 'Analysed signal',...
   'Value', 0,...
diff --git a/Cw1/matlab/readaudiofile.m b/Cw1/matlab/readaudiofile.m
index 3a87be2..825a9a8 100644
--- a/Cw1/matlab/readaudiofile.m
+++ b/Cw1/matlab/readaudiofile.m
@@ -1,5 +1,5 @@
 function [x, Fs] = readaudiofile(filename, param)
-% [x, Fs] = audiofileread(filename, param)
+% [x, Fs] = readaudiofile(filename, param)
 %
 % returns vector x of the size SIZE=[samples channels].
 %  eg. x = x(:,1) + j*x(:,2);
-- 
GitLab