comparison aim-mat/modules/usermodule/pitchstrength/analyse_frequency_profile.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
children
comparison
equal deleted inserted replaced
3:20ada0af3d7d 4:537f939baef0
1 % function [result, center_c] = analyse_frequency_profiletunedDP(fq_profile, peaks, apFQP)
2 %
3 % To analyse the time frequency profile of the auditory image
4 % Returns value between 0 and 1 discribing the strength of the spectral
5 % pitch. Used for quantitative analysis of ramped and damped sinusoids
6 % and for sinusoidally amplitude modulated sinusoids
7 %
8 %
9 % INPUT VALUES:
10 % fq_profile frequency profile (signal class)
11 % peaks output of peakpicker
12 % apFQP a priori information where to find the peak
13 %
14 % RETURN VALUE:
15 % result all relevant information
16 %
17 %
18 % (c) 2011, University of Southampton
19 % Maintained by Stefan Bleeck (bleeck@gmail.com)
20 % download of current version is on the soundsoftware site:
21 % http://code.soundsoftware.ac.uk/projects/aimmat
22 % documentation and everything is on http://www.acousticscale.org
23
24 function result = analyse_frequency_profile(fq_profile, options)
25
26 % for debug reasons -
27 plot_switch = 0;
28
29
30 % these finally are the results, that we want back:
31 % 1:the hight at the highest point
32 result.free.highest_peak_hight=0;
33 result.free.highest_peak_frequency=0;
34 % hight to the region below value
35 result.free.height_width_ratio=0;
36
37 % now all these at a fixed frequency:
38 result.fixed.highest_peak_hight=0;
39 result.fixed.highest_peak_frequency=0;
40 result.fixed.height_width_ratio=0;
41
42 % other things useful for plotting
43 result.smoothed_signal=fq_profile; % no smoothing used here
44 result.peaks = [];
45
46
47 % first find the peaks of the frequency profile
48 peaks = PeakPicker(fq_profile);
49
50 % translate the time in the peaks back to a frequency
51 nap=options.nap; % ugly, but we need the frequency informatin somewhere
52 for i=1:length(peaks)
53 peaks{i}.t=1/chan2fre(nap,peaks{i}.x);
54 end
55
56 result.peaks = peaks;
57
58 fq_profile_vals = getdata(fq_profile);
59 if plot_switch
60 cf_save = gcf;
61 figure(13)
62 cla;
63 plot(fq_profile_vals,'r-');
64 hold on
65 axis auto
66 end
67 % stop if there are no peaks, e.g. in the first frames
68 if length(peaks)<1
69 return
70 end
71
72 % Peak of interest is highest peak of the profile
73 peaks_oi = peaks{1};
74
75 apFQP=options.target_frequency;
76 if apFQP>0
77 % no peak finding - peak is given a priori
78 % take nearest peak to a apriori frequency
79 dist=+inf;
80 indexOI = 1;
81 for p=1:length(peaks)
82 d=abs(apFQP-peaks{p}.t);
83 if d<dist
84 indexOI=p;
85 dist=d;
86 end
87 end %p
88 peak_oi = peaks{indexOI};
89 end
90
91
92 % %% Method --- works with SAM sounds
93 % %% Highest peak / number of neighbourgh channels which are bigger than -xdB
94 % max_attenuation_dB = -6;
95 % atten_fac = 10^(max_attenuation_dB/20); % attenuation as factor
96 % % Take highest Peak
97 % %poi = peaks2{1};
98 % %poi = peaks{1};
99 % poi = peaks_oi;
100 %
101 % fq_profile_vals = fq_profile_vals./poi.y;
102 % maxy =1;
103 % % maxy = poi.y;
104 % pwidth = 0;
105 % x = poi.x;
106 % while (x<=length(fq_profile_vals))&&(fq_profile_vals(x)>maxy*atten_fac)
107 % pwidth=pwidth+1; % one more channel
108 % x=x+1;
109 % end
110 % if plot_switch
111 % line([x x],[0 peaks_oi.y]);
112 % end
113 %
114 % x = poi.x-1;
115 % while (x>=1)&&(fq_profile_vals(x)>maxy*atten_fac)
116 % pwidth=pwidth+1; % one more channel
117 % x=x-1;
118 % end
119 % if plot_switch
120 % line([x x],[0 peaks_oi.y]);
121 % end
122 % result_width = 1-(pwidth/length(fq_profile_vals));
123 %
124
125 % ----------------------------
126 % Method developed with Roy 13/06
127 % Calculate the mean of the Channels in a 20 to 80 percent
128 % range left of the main peak
129
130 start_frequency_integration=options.start_frequency_integration;
131 stop_frequency_integration=options.stop_frequency_integration;
132
133 startx=floor(start_frequency_integration*peaks_oi.x);
134 if startx<=0
135 startx=1;
136 end
137 stopx=floor(stop_frequency_integration*peaks_oi.x);
138 ps_result = 1 - mean(fq_profile_vals(startx:stopx))/fq_profile_vals(peaks_oi.x);
139
140 center_c = peaks_oi.x;
141
142 if plot_switch
143 plot(peaks_oi.x,peaks_oi.y,'r.');
144 plot(startx,fq_profile_vals(startx),'bx');
145 line([startx startx],[0 fq_profile_vals(startx)])
146 plot(stopx,fq_profile_vals(stopx),'bx');
147 line([stopx stopx],[0 fq_profile_vals(stopx)])
148 figure(cf_save);
149 end
150
151 % % % For debug plot minima
152 % for i=1:nops
153 % plot(peaks{i}.left.x, peaks{i}.left.y, 'ob');
154 % plot(peaks{i}.right.x, peaks{i}.right.y, 'xb');
155 % end
156
157
158 % finally define the return values
159 result.free.highest_peak_hight=peaks_oi.y; % height of the first peak
160 result.free.highest_peak_frequency=chan2fre(nap,peaks_oi.x);
161
162 % hight to the region below value
163 result.free.height_width_ratio=ps_result;
164
165 % now all these at a fixed frequency:
166 result.fixed.highest_peak_hight=0;
167 result.fixed.highest_peak_frequency=0;
168 result.fixed.height_width_ratio=0;
169
170