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