Mercurial > hg > aimc
comparison trunk/matlab/bmm/carfac/SAI_RunLayered.m @ 676:edfe3a98504b
Add simplified function to compute a simple (i.e. single-layer) SAI.
author | ronw@google.com |
---|---|
date | Fri, 24 May 2013 20:22:16 +0000 |
parents | 920a5d853b97 |
children | be55786eeb04 |
comparison
equal
deleted
inserted
replaced
675:920a5d853b97 | 676:edfe3a98504b |
---|---|
19 | 19 |
20 function [frame_rate, num_frames] = SAI_RunLayered(CF, input_waves) | 20 function [frame_rate, num_frames] = SAI_RunLayered(CF, input_waves) |
21 % function [CF, SAI_movie] = CARFAC_RunLayered(CF, input_waves) | 21 % function [CF, SAI_movie] = CARFAC_RunLayered(CF, input_waves) |
22 % This function runs the CARFAC and generates an SAI movie, dumped as PNG | 22 % This function runs the CARFAC and generates an SAI movie, dumped as PNG |
23 % files for now. | 23 % files for now. |
24 | 24 % |
25 % Computes a "layered" SAI composed of images computed at several | |
26 % time scales. | |
27 % | |
25 % Layer 1 is not decimated from the 22050 rate; subsequent layers have | 28 % Layer 1 is not decimated from the 22050 rate; subsequent layers have |
26 % smoothing and 2X decimation each. All layers get composited together | 29 % smoothing and 2X decimation each. All layers get composited together |
27 % into movie frames. | 30 % into movie frames. |
28 | 31 |
29 n_ch = CF.n_ch; | 32 n_ch = CF.n_ch; |
33 end | 36 end |
34 fs = CF.fs; | 37 fs = CF.fs; |
35 | 38 |
36 seglen = round(fs / 30); % Pick about 30 fps | 39 seglen = round(fs / 30); % Pick about 30 fps |
37 frame_rate = fs / seglen; | 40 frame_rate = fs / seglen; |
41 n_segs = ceil(n_samp / seglen); | |
42 | |
38 | 43 |
39 % Design the composite log-lag SAI using these parameters and defaults. | 44 % Design the composite log-lag SAI using these parameters and defaults. |
40 n_layers = 15 | 45 n_layers = 15 |
41 width_per_layer = 36; | 46 width_per_layer = 36; |
42 [layer_array, total_width, lags] = ... | 47 [layer_array, total_width, lags] = ... |
57 | 62 |
58 | 63 |
59 % Make the composite SAI image array. | 64 % Make the composite SAI image array. |
60 composite_frame = zeros(n_ch, total_width); | 65 composite_frame = zeros(n_ch, total_width); |
61 | 66 |
62 n_segs = ceil(n_samp / seglen); | |
63 | |
64 % Make the history buffers in the layers_array: | 67 % Make the history buffers in the layers_array: |
65 for layer = 1:n_layers | 68 for layer = 1:n_layers |
66 layer_array(layer).nap_buffer = zeros(layer_array(layer).buffer_width, n_ch); | 69 layer_array(layer).nap_buffer = zeros(layer_array(layer).buffer_width, n_ch); |
67 layer_array(layer).nap_fraction = 0; % leftover fraction to shift in. | 70 layer_array(layer).nap_fraction = 0; % leftover fraction to shift in. |
68 % The SAI frame is transposed to be image-like. | 71 % The SAI frame is transposed to be image-like. |
76 future_lags = layer_array(1).future_lags; | 79 future_lags = layer_array(1).future_lags; |
77 % marginals_frame = zeros(total_width - future_lags + 2*n_ch, total_width); | 80 % marginals_frame = zeros(total_width - future_lags + 2*n_ch, total_width); |
78 marginals_frame = zeros(n_ch, total_width); | 81 marginals_frame = zeros(n_ch, total_width); |
79 | 82 |
80 for seg_num = 1:n_segs | 83 for seg_num = 1:n_segs |
81 % k_range is the range of input sample indices for this segment | 84 % seg_range is the range of input sample indices for this segment |
82 if seg_num == n_segs | 85 if seg_num == n_segs |
83 % The last segment may be short of seglen, but do it anyway: | 86 % The last segment may be short of seglen, but do it anyway: |
84 k_range = (seglen*(seg_num - 1) + 1):n_samp; | 87 seg_range = (seglen*(seg_num - 1) + 1):n_samp; |
85 else | 88 else |
86 k_range = seglen*(seg_num - 1) + (1:seglen); | 89 seg_range = seglen*(seg_num - 1) + (1:seglen); |
87 end | 90 end |
88 % Process a segment to get a slice of decim_naps, and plot AGC state: | 91 % Process a segment to get a slice of decim_naps, and plot AGC state: |
89 [seg_naps, CF] = CARFAC_Run_Segment(CF, input_waves(k_range, :)); | 92 [seg_naps, CF] = CARFAC_Run_Segment(CF, input_waves(seg_range, :)); |
90 | 93 |
91 seg_naps = max(0, seg_naps); % Rectify | 94 seg_naps = max(0, seg_naps); % Rectify |
92 | 95 |
93 if seg_num == n_segs % pad out the last result | 96 if seg_num == n_segs % pad out the last result |
94 seg_naps = [seg_naps; zeros(seglen - size(seg_naps,1), size(seg_naps, 2))]; | 97 seg_naps = [seg_naps; zeros(seglen - size(seg_naps,1), size(seg_naps, 2))]; |