Mercurial > hg > nimfks
comparison src/matlab/CSS.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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c52bc3e8d3ad |
---|---|
1 classdef CSS < handle | |
2 properties | |
3 NMF_features | |
4 Activations | |
5 Cost | |
6 Synthesis_method | |
7 Synthesis | |
8 end | |
9 | |
10 methods | |
11 function obj = CSS(varargin) | |
12 if nargin == 2 | |
13 obj.NMF_features = varargin{1}; | |
14 obj.Synthesis_method = varargin{2}; | |
15 end | |
16 end | |
17 end | |
18 | |
19 methods | |
20 function obj = nmf(obj, corpus_sound, target_sound, varargin) | |
21 if( nargin == 4 ) | |
22 pct_prune = varargin{1} | |
23 else | |
24 pct_prune = 1 | |
25 end | |
26 nmf_alg = obj.NMF_features.Algorithm; | |
27 target_spect = abs(target_sound.Features.STFT.S); | |
28 corpus_spect = abs(corpus_sound.Features.STFT.S); | |
29 [corpus_spect, pruned_frames, frames_to_keep] = prune_corpus( target_spect, corpus_spect, pct_prune ); | |
30 | |
31 switch nmf_alg | |
32 case 'Euclidean' | |
33 if length(fieldnames(obj.NMF_features)) > 1 | |
34 [H, obj.Cost] = nmf_euclidean(target_spect, corpus_spect, obj.NMF_features); | |
35 else | |
36 [H, obj.Cost] = nmf_euclidean(target_spect, corpus_spect); | |
37 end | |
38 case 'Divergence' | |
39 if length(fieldnames(obj.NMF_features)) > 1 | |
40 [H, obj.Cost] = nmf_divergence(target_spect, corpus_spect, obj.NMF_features); | |
41 else | |
42 [H, obj.Cost] = nmf_divergence(target_spect, corpus_spect); | |
43 end | |
44 case 'Sparse NMF' | |
45 if length(fieldnames(obj.NMF_features)) > 1 | |
46 [~, H, deleted, obj.Cost] = SA_B_NMF(target_spect, corpus_spect, 5, obj.NMF_features); | |
47 else | |
48 [~, H, deleted, obj.Cost] = SA_B_NMF(target_spect, corpus_spect, 5 ); | |
49 end | |
50 | |
51 H( deleted, : ) = 0; | |
52 obj.Activations = H; | |
53 end | |
54 | |
55 if size( frames_to_keep ) > 0 | |
56 tmp = zeros( size( corpus_sound.Features.STFT.S,2 ), size( target_spect,2 ) ); | |
57 for i = 1:length( frames_to_keep ) | |
58 tmp(frames_to_keep(i), :) = H(i,:); | |
59 end | |
60 H = tmp; | |
61 end | |
62 % H( pruned_frames, : ) = 0; | |
63 % % Pad activations to size of corpus frames | |
64 % % since pruned frames maximum can be < size of corpus | |
65 % H( setdiff( 1:( size( corpus_spect, 2 ) + length( pruned_frames ) ), 1:size( H, 1 ) ), : ) = 0; | |
66 obj.Activations = H; | |
67 end | |
68 | |
69 function obj = synthesize(obj, corpus_sound) | |
70 synth_method = obj.Synthesis_method; | |
71 win = corpus_sound.Features.window; | |
72 W = abs(corpus_sound.Features.STFT.S); | |
73 H = obj.Activations; | |
74 | |
75 switch synth_method | |
76 case 'ISTFT' | |
77 parameters = []; | |
78 parameters.synHop = win.Hop; | |
79 parameters.win = window(lower(win.Type), win.Length); | |
80 | |
81 reconstruction = W*H; | |
82 padding = size(reconstruction, 1)*2 - win.Length - 2; | |
83 if padding >= 0 | |
84 parameters.zeroPad = padding; | |
85 end | |
86 | |
87 obj.Synthesis = istft(reconstruction, parameters); | |
88 case 'Template Addition' | |
89 obj.Synthesis = templateAdditionResynth(corpus_sound.Signal, H, win); | |
90 end | |
91 end | |
92 | |
93 function plot_activations(obj, varargin) | |
94 if(nargin > 1) | |
95 maxDb = varargin{1}; | |
96 else | |
97 maxDb = -45; | |
98 end | |
99 | |
100 H = obj.Activations; | |
101 | |
102 HdB = 20*log10(H./max(max(H))); | |
103 HdB = HdB - maxDb; | |
104 HdB(HdB < 0) = 0; | |
105 imagesc(HdB); | |
106 cmap = colormap('gray'); | |
107 cmap(1,:) = 0*ones(1,3); | |
108 colormap(flipud(cmap)) | |
109 colorbar | |
110 axis xy; grid on; | |
111 set(gca, 'Layer', 'top'); | |
112 ylabel('Template'); | |
113 xlabel('Time'); | |
114 grid on; | |
115 set(gca,'FontSize',16); | |
116 end | |
117 | |
118 function plot_cost(obj) | |
119 plot(obj.Cost); | |
120 xlabel('Iteration'); | |
121 ylabel('Cost'); | |
122 title('Cost vs. Iteration'); | |
123 grid on | |
124 end | |
125 end | |
126 end |