Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 3.10 KB | None | 0 0
  1. % ***************************************************************
  2. % This script is used for deterioration calculatoins and plots
  3. % ***************************************************************
  4. close all;
  5. addpath('input');
  6.  
  7. % Files to be processed
  8. files = { 'ClayColoredRobin.wav', 'drumloop1.wav', 'tapestry.wav' };
  9.  
  10. % Filters to be applied
  11. filters = {'mean_filter', 'median_filter', 'mode_filter'};
  12.  
  13. % Windows at which slight deterioration and complete degradation occur.
  14. critical_window_sizes = zeros(length(files), length(filters), 2);
  15.  
  16. % indexing of critical_window_sizes :
  17. % (file_index, filter_index,[slight_deterioration, complete_deterioration])
  18.  
  19. % ClayColoredRobin :
  20. critical_window_sizes(1,1,:) = [7, 230401]; % mean
  21. critical_window_sizes(1,2,:) = [3, 501];    % median  
  22. critical_window_sizes(1,3,:) = [3, 51];     % mode
  23.  
  24. % drumloop1:
  25. critical_window_sizes(2,1,:) = [21, 115001];% mean
  26. critical_window_sizes(2,2,:) = [31, 701];   % median
  27. critical_window_sizes(2,3,:) = [7, 1001];   % mode
  28.  
  29. % tapestry:
  30. critical_window_sizes(3,1,:) = [11, 13001]; % mean
  31. critical_window_sizes(3,2,:) = [3, 1251];   % median
  32. critical_window_sizes(3,3,:) = [3, 11];     % mode
  33.  
  34. for i = 1:length(files)
  35.     % Reading the file
  36.     cur_filename = files{i};
  37.     [y, fs, bs] = wavread(cur_filename);
  38.     [pathstr,name,ext] = fileparts(cur_filename);
  39.     y = y(:,1);
  40.  
  41.     % Preparing plotting parameters
  42.     t = linspace(0, length(y)/fs, length(y))';
  43.     xmin = 0; xmax = max(t); ymin = -max(abs(y(:)))*1.05; ymax = -ymin;
  44.    
  45.     slight_det = zeros(size(y));
  46.     complete_det = zeros(size(y));
  47.  
  48.     for j = 1:length(filters)
  49.         % Calculation
  50.         cur_filter = filters{j};
  51.         cur_func = str2func(cur_filter);
  52.         slight_det = cur_func(y, critical_window_sizes(i,j,1));
  53.         complete_det = cur_func(y, critical_window_sizes(i,j,2));
  54.  
  55.         % Plotting slight deterioration
  56.         figure('Visible', 'off');
  57.         subplot(2,1,1);
  58.         plot(t, slight_det);
  59.         xlabel('t (s)'); ylabel('amplitude');
  60.         axis([xmin xmax ymin ymax]);
  61.         legend(sprintf('N = %d', critical_window_sizes(i,j,1)));
  62.         legend('boxoff');
  63.         grid on;
  64.  
  65.         plottitle = sprintf('Deterioration of %s with %s', name, strrep(cur_filter, '_', ' '));
  66.         title(plottitle);
  67.  
  68.         % Plotting complete deterioration
  69.         subplot(2,1,2);
  70.         plot(t, complete_det);
  71.         xlabel('t (s)'); ylabel('amplitude');
  72.         axis([xmin xmax ymin ymax]);
  73.         legend(sprintf('N = %d', critical_window_sizes(i,j,2)));
  74.         legend('boxoff');
  75.         grid on;
  76.  
  77.         % Saving the resulting plot
  78.         result_filename = sprintf('%s_%s_det', name, cur_filter);
  79.         set(gcf,'PaperUnits','inches','PaperPosition',[0 0 6.5 9]);
  80.         print(gcf,'-dpng', '-r400',strcat('output/pics/', result_filename));
  81.  
  82.         % Saving the .wav files
  83.         wavwrite(slight_det ,fs, ...
  84.             sprintf('output/wav/%s_%s_slight.wav', name, cur_filter));
  85.         wavwrite(complete_det ,fs, ...
  86.             sprintf('output/wav/%s_%s_complete.wav', name, cur_filter));
  87.     end
  88. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement