Mercurial > hg > aimmat
annotate aim-mat/tools/@signal/changesr.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 % method of class @signal |
tomwalters@0 | 2 % function sig=changesr(sig,sr_neu) |
tomwalters@0 | 3 % changes the sample rate of the signal to the new samplerate. |
tomwalters@0 | 4 % the number of points of the signal change! |
tomwalters@0 | 5 % new values are interpolated |
tomwalters@0 | 6 % |
tomwalters@0 | 7 % INPUT VALUES: |
tomwalters@0 | 8 % sig1: first @signal |
tomwalters@0 | 9 % sr_new: new samplerate |
tomwalters@0 | 10 % |
tomwalters@0 | 11 % RETURN VALUE: |
tomwalters@0 | 12 % sigresult: @signal ` |
bleeck@3 | 13 % This external file is included as part of the 'aim-mat' distribution package |
bleeck@3 | 14 % (c) 2011, University of Southampton |
bleeck@3 | 15 % Maintained by Stefan Bleeck (bleeck@gmail.com) |
bleeck@3 | 16 % download of current version is on the soundsoftware site: |
bleeck@3 | 17 % http://code.soundsoftware.ac.uk/projects/aimmat |
bleeck@3 | 18 % documentation and everything is on http://www.acousticscale.org |
tomwalters@0 | 19 |
tomwalters@0 | 20 function sig=changesr(a,sr_neu) |
tomwalters@0 | 21 |
tomwalters@0 | 22 sr_alt=a.samplerate; |
tomwalters@0 | 23 if fround(sr_alt,5)==fround(sr_neu,5) %nichts zu tun |
tomwalters@0 | 24 sig=a; |
tomwalters@0 | 25 return; |
tomwalters@0 | 26 end |
tomwalters@0 | 27 |
tomwalters@0 | 28 |
tomwalters@0 | 29 if sr_neu > sr_alt |
tomwalters@0 | 30 r=round(sr_neu/sr_alt); |
tomwalters@0 | 31 % r=sr_neu/sr_alt; |
tomwalters@0 | 32 % y = interp(a.werte,r); |
tomwalters@0 | 33 x_val_new = a.start_time+1/sr_neu:1/sr_neu:getlength(a); |
tomwalters@0 | 34 x_val_old = a.start_time+1/sr_alt:1/sr_alt:getlength(a); |
tomwalters@0 | 35 y = interp1(x_val_old, a.werte, x_val_new, 'cubic'); |
tomwalters@0 | 36 else |
tomwalters@0 | 37 p=sr_neu; |
tomwalters@0 | 38 q=sr_alt; |
tomwalters@0 | 39 y = resample(a.werte,p,q); |
tomwalters@0 | 40 end |
tomwalters@0 | 41 |
tomwalters@0 | 42 sig=signal(y); |
tomwalters@0 | 43 sig.samplerate=sr_neu; |
tomwalters@0 | 44 sig.name=a.name; |
tomwalters@0 | 45 sig.unit_x=a.unit_x; |
tomwalters@0 | 46 sig.unit_y=a.unit_y; |
tomwalters@0 | 47 sig.start_time=a.start_time; |
tomwalters@0 | 48 sig.nr_x_ticks=a.nr_x_ticks; |
tomwalters@0 | 49 sig.x_tick_labels=a.x_tick_labels; |