mapsound() is poor and not reliable. It should be rewritten.
@sgougeon)
Reported by Samuel GOUGEON (bug_16530_mapsound.png (35.44 KB, image/png)
illustrated mapsound pitfalls (see the description)
BUG DESCRIPTION:
----------------
mapsound() is presently a raw prototype of a sound mapping function.
By the way, it is poorly documented and illustrated, as noted in the
reported bug 10490.
1) Its code computes an inverse FFT of the input signal, instead of the expected
direct FFT. This is not so disturbing, because the input signal is always real,
and so the expected spectrum of the absolute amplitudes is even. But still..
Here is a standard example that shows several mapsound bugs and unreliability,
looking quite blocking for actually using mapsound:
// 2 pure frequencies lasting 1 s each, one after the other, + a constant:
fs = 22050;
t = 0:1/fs:1*(1-%eps);
y = 0.4 + [1.5*sin(2*%pi*800*t) sin(2*%pi*1200*t)];
clf
gcf().color_map = hotcolormap(100); // for a decent map...
mapsound(y, 0.05, 100, 1500)
xgrid; gca().grid_position="foreground";
colorbar
What do we see (attached screenshot, part A)?
2) Illustrated spectra are shifted in frequencies, by an unknown offset (likely
one frequency bin).
We expect peak frequencies at exactly 800 and 1200 Hz, while they are displayed
around 830 and 1230 Hz.
3) Illustrated spectral amplitudes are wrong. We expect them at 1.5 and 1.
All absolute spectral amplitudes are opposed before being displayed, and so
are illustrated as negative. It is hard to understand why.
Because frequencies look managed only approximately, this may be a way
the author found to approximately get the illustrated signal at the
right frequencies.
4) The function is not very robust. For custom reasonnable input parameters,
it often yields an "Invalid index" error. This is always the case for instance
when entering fmin=0 to get the full "low pass" spectrum down to the average
level (0.4 (x2) in our standard signal):
clf
mapsound(y, 0.05, 0, 1500)
--> mapsound(y, 0.05, 0, 1500)
in builtin mapsound ( SCI\modules\sound\macros\mapsound.sci line 12 )
Invalid index.
So, presently, we can't map the first frequency bin.
5) The role of the simpl argument is quite obscur, and gives completely wrong
results (attached screenshot, part B).
Sticking to our standard example, let just set simpl=2 instead of
the default 1:
clf
mapsound(y, 0.05, 100, 3000, 2)
xgrid; gca().grid_position="foreground";
This shifts the frequencies of the displayed signal by the same factor.
The map is no longer related to the actual input signal.
simpl somewhat changes the numerical sampling rate, but this change is not
taken into account in the frequency scale for the display.
For a long sound record at a standard -- so quite high - sampling rate,
the raw signal coming from a soud file can have a huge number of points.
If the aim of simpl is to decrease this number, in our opinion, such a
preprocessing should be done *before* using mapsound, not inside it.
And then the new actual sampling rate should be set accordingly.
6) Default values for frequency bounds are set to fixed values. Yet, fmax_MAX
is a-priori related to the sampling rate due to the Shannon sampling condition.
Butthis is not considered at all.
7) The default dt value is also set to a fixed value, independently of the
full duration of the input signal. This is not very handy and relevant.
dt is related to the width df=1/dt of the frequency bin, and is the width
of the time's bin.
In our opinion, the default dt should be set in such a way that the numbers
of time and frequency bins are balanced, in order to get some ~square
(time, frequency) pixels.
8) No default titles are displayed for the time and frequency axes. This should
be done. A sound map has always the same meaning, as a Bode plot has always
the same "dedicated" meaning.
9) The scale for amplitudes is not displayed. This misses and is not an option.
The default colormap is meaningless (attached screenshot, part C).
clf reset
mapsound(y, 0.05, 100, 1500)
A meaningful graduated colorbar must be displayed. This is not an option,
to provide the actual amplitudes information. If the figure receiving
the mapsound does not yet exist, or if the axes is alone in the figure,
and empty, and with the default colormap, then a more relevant colormap
should be generated and used by mapsound.
10) Because the current historical mapsound version could hardly have been used,
we think that improving input arguments can be proposed, even if this partly
breaks the (theoretical) backward compatibility. Thus we could propose
a) to gather [fmin, fmax] as a single frequencyBounds argument
If it's only scalar, it represents fmax, with fmin=0 which is most often
useful
b) to remove the simpl argument
c) to change default values:
* for fmax : as 0.2 * sampleRate.
* for dt : such that we get a balanced resolution in time and frequency.
d) to become able to specify fmin and fmax as fractions of the sampling rate.
e) to become able to specify dt as a fraction of the total signal duration
(that comes from the sampling rate and length(w)).
ERROR LOG:
----------
See the above description
HOW TO REPRODUCE THE BUG:
-------------------------
See the above description