annotate src/matlab/rot_kernel.m @ 0:c52bc3e8d3ad tip

user: boblsturm branch 'default' added README.md added assets/.DS_Store added assets/playButton.jpg added assets/stopButton.png added assets/swapButton.jpg added data/.DS_Store added data/fiveoctaves.mp3 added data/glock2.wav added data/sinScale.mp3 added data/speech_female.mp3 added data/sweep.wav added nimfks.m.lnk added src/.DS_Store added src/matlab/.DS_Store added src/matlab/AnalysisCache.m added src/matlab/CSS.m added src/matlab/DataHash.m added src/matlab/ExistsInCache.m added src/matlab/KLDivCost.m added src/matlab/LoadFromCache.m added src/matlab/SA_B_NMF.m added src/matlab/SaveInCache.m added src/matlab/Sound.m added src/matlab/SynthesisCache.m added src/matlab/chromagram_E.m added src/matlab/chromagram_IF.m added src/matlab/chromagram_P.m added src/matlab/chromsynth.m added src/matlab/computeSTFTFeat.m added src/matlab/controller.m added src/matlab/decibelSliderReleaseCallback.m added src/matlab/drawClickCallBack.m added src/matlab/fft2chromamx.m added src/matlab/hz2octs.m added src/matlab/ifgram.m added src/matlab/ifptrack.m added src/matlab/istft.m added src/matlab/nimfks.fig added src/matlab/nimfks.m added src/matlab/nmfFn.m added src/matlab/nmf_beta.m added src/matlab/nmf_divergence.m added src/matlab/nmf_euclidean.m added src/matlab/prune_corpus.m added src/matlab/rot_kernel.m added src/matlab/templateAdditionResynth.m added src/matlab/templateDelCb.m added src/matlab/templateScrollCb.m
author boblsturm
date Sun, 18 Jun 2017 06:26:13 -0400
parents
children
rev   line source
boblsturm@0 1 function [Y] = rot_kernel(kernel, deg)
boblsturm@0 2
boblsturm@0 3 N = size( kernel, 1 );
boblsturm@0 4 max_rots = 4*(N-1);
boblsturm@0 5 deg_per_rot = 360 / max_rots;
boblsturm@0 6
boblsturm@0 7 % deg = deg - mod( deg, deg_per_rot );
boblsturm@0 8 deg = deg_per_rot * ( round( deg / deg_per_rot ) );
boblsturm@0 9 num_of_rots = ceil( deg / deg_per_rot );
boblsturm@0 10
boblsturm@0 11 if num_of_rots < 1
boblsturm@0 12 Y = kernel;
boblsturm@0 13 return
boblsturm@0 14 else
boblsturm@0 15 for r = 1:num_of_rots
boblsturm@0 16 if mod( r, 2 ) == 0
boblsturm@0 17 kernel = rot_outer_layer( kernel );
boblsturm@0 18 else
boblsturm@0 19 kernel = rot_inner_layer( kernel );
boblsturm@0 20 end
boblsturm@0 21 end
boblsturm@0 22 end
boblsturm@0 23
boblsturm@0 24 Y = kernel;
boblsturm@0 25
boblsturm@0 26 end
boblsturm@0 27
boblsturm@0 28 function [Y] = rot_outer_layer( A )
boblsturm@0 29 dim = size( A, 1 );
boblsturm@0 30 top = A( 1, : );
boblsturm@0 31 right = A( 2:dim, dim )';
boblsturm@0 32 bottom = fliplr( A( dim, 1:dim - 1 ) );
boblsturm@0 33 left = fliplr( A( 2:dim - 1, 1 )' );
boblsturm@0 34 shifted_layers = wshift('1D',[top,right,bottom,left],-1);
boblsturm@0 35
boblsturm@0 36 top = shifted_layers( 1:length(top));
boblsturm@0 37 last_ind = length( top );
boblsturm@0 38
boblsturm@0 39 right = shifted_layers( last_ind + 1 : last_ind + length(right));
boblsturm@0 40 last_ind = last_ind + length( right );
boblsturm@0 41
boblsturm@0 42 bottom = shifted_layers( last_ind + 1 : last_ind + length(bottom));
boblsturm@0 43 last_ind = last_ind + length( bottom );
boblsturm@0 44
boblsturm@0 45 left = shifted_layers( last_ind + 1 : end );
boblsturm@0 46
boblsturm@0 47 A( 1, : ) = top;
boblsturm@0 48 A( 2:dim, dim ) = right';
boblsturm@0 49 A( dim, 1:dim - 1 ) = fliplr( bottom );
boblsturm@0 50 A( 2:dim - 1, 1 ) = fliplr( left' );
boblsturm@0 51
boblsturm@0 52 Y = A;
boblsturm@0 53 end
boblsturm@0 54
boblsturm@0 55 function [Y] = rot_inner_layer( kernel )
boblsturm@0 56 % dim = size( kernel, 1 );
boblsturm@0 57 % if dim < 2
boblsturm@0 58 % Y = rot_outer_layer( kernel )
boblsturm@0 59 % return;
boblsturm@0 60 % else
boblsturm@0 61 % Y = rot_inner_layer( kernel( 2:dim - 1, 2:dim - 1 ) )
boblsturm@0 62 % end
boblsturm@0 63 dim = size( kernel, 1 );
boblsturm@0 64
boblsturm@0 65 if mod( dim / 2, 2 ) == 0
boblsturm@0 66 max_rots = dim / 2 - 1;
boblsturm@0 67 else
boblsturm@0 68 max_rots = dim / 2 - 0.5;
boblsturm@0 69 end
boblsturm@0 70
boblsturm@0 71 low = 2;
boblsturm@0 72 high = dim - 1;
boblsturm@0 73 for i = 1:max_rots
boblsturm@0 74 kernel( low:high, low:high ) = rot_outer_layer( kernel( low:high, low:high ) );
boblsturm@0 75 low = low + 1;
boblsturm@0 76 high = high - 1;
boblsturm@0 77 end
boblsturm@0 78
boblsturm@0 79 Y = kernel;
boblsturm@0 80 end