tomwalters@0: % tomwalters@0: % sig = function gen_ms_sc_ch(segment_len, carrier_fq, envelope_fq, halflife, d_r, sample_fq) tomwalters@0: % tomwalters@0: % The size of the vectors corresponds to the number of segments tomwalters@0: % All vectors must have the same size or must be a scalar instead tomwalters@0: % If a scalar is used, this value is the same for each segment tomwalters@0: % tomwalters@0: % INPUT VALUES: tomwalters@0: % segment_len length of each segment in s (vector/scalar) tomwalters@0: % carrier_fq carrier frequence (vector/scalar) tomwalters@0: % envelope_fq envelope frequence = modulator fq (vector/ scalar) tomwalters@0: % halflife Half life (vector/ scalar) in seconds !!! tomwalters@0: % d_r 0 = damped, tomwalters@0: % 1 = ramped (vector/scalar) tomwalters@0: % sample_fq the sample frequence tomwalters@0: % tomwalters@0: % RETURN VALUE: tomwalters@0: % sig the signal (object of class signal) tomwalters@0: % tomwalters@0: % REMARK: Sample frequence should be a multiple of both, the tomwalters@0: % carrier frequence as well as the envelope frequence tomwalters@0: % tomwalters@0: % (c) 2003-2008, University of Cambridge, Medical Research Council tomwalters@0: % Christoph Lindner bleeck@3: % (c) 2011, University of Southampton bleeck@3: % Maintained by Stefan Bleeck (bleeck@gmail.com) bleeck@3: % download of current version is on the soundsoftware site: bleeck@3: % http://code.soundsoftware.ac.uk/projects/aimmat bleeck@3: % documentation and everything is on http://www.acousticscale.org bleeck@3: tomwalters@0: tomwalters@0: tomwalters@0: function sig = gen_ms_sc_ch(segment_len, carrier_fq, envelope_fq, halflife, d_r, sample_fq) tomwalters@0: tomwalters@0: % sample_fq should be a multiple of carrier and envelope_fq tomwalters@0: if (mod(sample_fq, carrier_fq) ~= 0) tomwalters@0: warning('Sample frequence should be a multiple of carrier frequence for a smooth transition between the segemnts'); tomwalters@0: end tomwalters@0: if (mod(sample_fq, envelope_fq) ~= 0) tomwalters@0: warning('Sample frequence should be a multiple of envelope frequence for a smooth transition between the segemnts'); tomwalters@0: end tomwalters@0: tomwalters@0: % find out the number of segments tomwalters@0: nos = max([length(segment_len) length(carrier_fq) length(envelope_fq) length(halflife) length(d_r)]); tomwalters@0: tomwalters@0: sig = signal(0, sample_fq); tomwalters@0: % loop the segments tomwalters@0: for i =1:nos tomwalters@0: % vector vs scalar tomwalters@0: if length(segment_len) > 1 tomwalters@0: sl = segment_len(i); tomwalters@0: else tomwalters@0: sl = segment_len; tomwalters@0: end tomwalters@0: % Special workaround to avoid aliases at the trasition (one tomwalters@0: % point will be deleted) tomwalters@0: if length(carrier_fq) > 1 tomwalters@0: cf = carrier_fq(i); tomwalters@0: else tomwalters@0: cf = carrier_fq; tomwalters@0: end tomwalters@0: if length(envelope_fq) > 1 tomwalters@0: ef = envelope_fq(i); tomwalters@0: else tomwalters@0: ef = envelope_fq; tomwalters@0: end tomwalters@0: if length(halflife) > 1 tomwalters@0: hl = halflife(i); tomwalters@0: else tomwalters@0: hl = halflife; tomwalters@0: end tomwalters@0: if length(d_r) > 1 tomwalters@0: dr = d_r(i); tomwalters@0: else tomwalters@0: dr = d_r; tomwalters@0: end tomwalters@0: tomwalters@0: % generate object tomwalters@0: sig_obj = signal(sl, sample_fq); tomwalters@0: tomwalters@0: % generate signal tomwalters@0: if dr == 1 tomwalters@0: sig_tmp = generaterampsinus(sig_obj, cf, ef, 1, hl); tomwalters@0: else tomwalters@0: sig_tmp = generatedampsinus(sig_obj, cf, ef, 1, hl); tomwalters@0: end tomwalters@0: % add the segement to the main signal vector tomwalters@0: % Special workaround to avoid aliases at the trasition (one tomwalters@0: % point will be deleted) tomwalters@0: tomwalters@0: sig = append(sig, sig_tmp); tomwalters@0: end tomwalters@0: tomwalters@0: