annotate aim-mat/tools/gen_ms_mc_ch.m @ 4:537f939baef0 tip

various bug fixes and changed copyright message
author Stefan Bleeck <bleeck@gmail.com>
date Tue, 16 Aug 2011 14:37:17 +0100
parents 20ada0af3d7d
children
rev   line source
tomwalters@0 1 %
tomwalters@0 2 % function sig = gen_ms_mc_ch(segment_len, carrier_fq, envelope_fq, halflife, d_r, sample_fq)
tomwalters@0 3 %
tomwalters@0 4 % generates a multi segment, multi carrier, changing half-life, damped or ramped sound
tomwalters@0 5 %
tomwalters@0 6 % The size of the matrices corresponds to the number of segments
tomwalters@0 7 % All vectors must have the same size or must be a scalar instead
tomwalters@0 8 % If a scalar is used, this value is the same for each segment
tomwalters@0 9 %
tomwalters@0 10 % Matrix convention:
tomwalters@0 11 % ----> column: each column contains the parameter for one segment
tomwalters@0 12 % |
tomwalters@0 13 % v 1st row contains the parameter for the 1st carrier etc.
tomwalters@0 14 %
tomwalters@0 15 %
tomwalters@0 16 %
tomwalters@0 17 % INPUT VALUES:
tomwalters@0 18 % segment_len length of each segment in s (vector/scalar)
tomwalters@0 19 % carrier_fq carrier frequence (matrix/vector)
tomwalters@0 20 % envelope_fq envelope frequence = modulator fq (vector/scalar)
tomwalters@0 21 % halflife Half life (matrix/vector) in seconds !!!
tomwalters@0 22 % d_r 0 = damped,
tomwalters@0 23 % 1 = ramped (vector, scalar)
tomwalters@0 24 % sample_fq the sample frequence
tomwalters@0 25 %%
tomwalters@0 26 % RETURN VALUE:
tomwalters@0 27 % sig the signal (object of class signal)
tomwalters@0 28 %
tomwalters@0 29 % REMARK: Sample frequence should be a multiple of both, the
tomwalters@0 30 % carrier frequence as well as the envelope frequence
tomwalters@0 31 %
tomwalters@0 32 %
tomwalters@0 33 % (c) 2003-2008, University of Cambridge, Medical Research Council
tomwalters@0 34 % Christoph Lindner
bleeck@3 35 %% (c) 2011, University of Southampton
bleeck@3 36 % Maintained by Stefan Bleeck (bleeck@gmail.com)
bleeck@3 37 % download of current version is on the soundsoftware site:
bleeck@3 38 % http://code.soundsoftware.ac.uk/projects/aimmat
bleeck@3 39 % documentation and everything is on http://www.acousticscale.org
bleeck@3 40
tomwalters@0 41
tomwalters@0 42 function sig = gen_ms_mc_ch(segment_len, carrier_fq, envelope_fq, halflife, d_r, sample_fq)
tomwalters@0 43
tomwalters@0 44 % sample_fq should be a multiple of carrier and envelope_fq
tomwalters@0 45 if (mod(sample_fq, carrier_fq) ~= 0)
tomwalters@0 46 warning('Sample frequence should be a multiple of carrier frequence for a smooth transition between the segemnts');
tomwalters@0 47 end
tomwalters@0 48 if (mod(sample_fq, envelope_fq) ~= 0)
tomwalters@0 49 warning('Sample frequence should be a multiple of envelope frequence for a smooth transition between the segemnts');
tomwalters@0 50 end
tomwalters@0 51 % find out the number of segments
tomwalters@0 52 nos = max([length(segment_len) size(carrier_fq,2) length(envelope_fq) size(halflife,2) length(d_r)]);
tomwalters@0 53
tomwalters@0 54 sig = signal(0, sample_fq);
tomwalters@0 55 % loop the segments
tomwalters@0 56 for i =1:nos
tomwalters@0 57 % vector vs scalar
tomwalters@0 58 if length(segment_len) > 1
tomwalters@0 59 sl = segment_len(i);
tomwalters@0 60 else
tomwalters@0 61 sl = segment_len;
tomwalters@0 62 end
tomwalters@0 63 if size(carrier_fq, 2) > 1
tomwalters@0 64 cf = carrier_fq(:, i);
tomwalters@0 65 else
tomwalters@0 66 cf = carrier_fq;
tomwalters@0 67 end
tomwalters@0 68 if length(envelope_fq) > 1
tomwalters@0 69 ef = envelope_fq(i);
tomwalters@0 70 else
tomwalters@0 71 ef = envelope_fq;
tomwalters@0 72 end
tomwalters@0 73 if size(halflife, 2) > 1
tomwalters@0 74 hl = halflife(:, i);
tomwalters@0 75 else
tomwalters@0 76 hl = halflife;
tomwalters@0 77 end
tomwalters@0 78 if length(d_r) > 1
tomwalters@0 79 dr = d_r(i);
tomwalters@0 80 else
tomwalters@0 81 dr = d_r;
tomwalters@0 82 end
tomwalters@0 83
tomwalters@0 84 % generate signal
tomwalters@0 85 if dr == 1
tomwalters@0 86 sig_tmp = gen_multiramp(cf, hl, ef, sl, sample_fq);
tomwalters@0 87 else
tomwalters@0 88 sig_tmp = gen_multidamp(cf, hl, ef, sl, sample_fq);
tomwalters@0 89 end
tomwalters@0 90 % add the segement to the main signal vector
tomwalters@0 91 sig = append(sig, sig_tmp);
tomwalters@0 92 end