Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- % ***************************************************************
- % This script is used for deterioration calculatoins and plots
- % ***************************************************************
- close all;
- addpath('input');
- % Files to be processed
- files = { 'ClayColoredRobin.wav', 'drumloop1.wav', 'tapestry.wav' };
- % Filters to be applied
- filters = {'mean_filter', 'median_filter', 'mode_filter'};
- % Windows at which slight deterioration and complete degradation occur.
- critical_window_sizes = zeros(length(files), length(filters), 2);
- % indexing of critical_window_sizes :
- % (file_index, filter_index,[slight_deterioration, complete_deterioration])
- % ClayColoredRobin :
- critical_window_sizes(1,1,:) = [7, 230401]; % mean
- critical_window_sizes(1,2,:) = [3, 501]; % median
- critical_window_sizes(1,3,:) = [3, 51]; % mode
- % drumloop1:
- critical_window_sizes(2,1,:) = [21, 115001];% mean
- critical_window_sizes(2,2,:) = [31, 701]; % median
- critical_window_sizes(2,3,:) = [7, 1001]; % mode
- % tapestry:
- critical_window_sizes(3,1,:) = [11, 13001]; % mean
- critical_window_sizes(3,2,:) = [3, 1251]; % median
- critical_window_sizes(3,3,:) = [3, 11]; % mode
- for i = 1:length(files)
- % Reading the file
- cur_filename = files{i};
- [y, fs, bs] = wavread(cur_filename);
- [pathstr,name,ext] = fileparts(cur_filename);
- y = y(:,1);
- % Preparing plotting parameters
- t = linspace(0, length(y)/fs, length(y))';
- xmin = 0; xmax = max(t); ymin = -max(abs(y(:)))*1.05; ymax = -ymin;
- slight_det = zeros(size(y));
- complete_det = zeros(size(y));
- for j = 1:length(filters)
- % Calculation
- cur_filter = filters{j};
- cur_func = str2func(cur_filter);
- slight_det = cur_func(y, critical_window_sizes(i,j,1));
- complete_det = cur_func(y, critical_window_sizes(i,j,2));
- % Plotting slight deterioration
- figure('Visible', 'off');
- subplot(2,1,1);
- plot(t, slight_det);
- xlabel('t (s)'); ylabel('amplitude');
- axis([xmin xmax ymin ymax]);
- legend(sprintf('N = %d', critical_window_sizes(i,j,1)));
- legend('boxoff');
- grid on;
- plottitle = sprintf('Deterioration of %s with %s', name, strrep(cur_filter, '_', ' '));
- title(plottitle);
- % Plotting complete deterioration
- subplot(2,1,2);
- plot(t, complete_det);
- xlabel('t (s)'); ylabel('amplitude');
- axis([xmin xmax ymin ymax]);
- legend(sprintf('N = %d', critical_window_sizes(i,j,2)));
- legend('boxoff');
- grid on;
- % Saving the resulting plot
- result_filename = sprintf('%s_%s_det', name, cur_filter);
- set(gcf,'PaperUnits','inches','PaperPosition',[0 0 6.5 9]);
- print(gcf,'-dpng', '-r400',strcat('output/pics/', result_filename));
- % Saving the .wav files
- wavwrite(slight_det ,fs, ...
- sprintf('output/wav/%s_%s_slight.wav', name, cur_filter));
- wavwrite(complete_det ,fs, ...
- sprintf('output/wav/%s_%s_complete.wav', name, cur_filter));
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement