Can I make sound and soundsc not make a sound when playing a constant value?

22 visualizaciones (últimos 30 días)
I was exploring what a ramp sounds like. Something like
1:10000
played in soundsc. To remove the click from snapping back to zero I left my vector as
ones(1,10000)*10000
afterwards. However, playing this sound, there is a humming even when the sound reaches the constant part. It is clearly heard in
wave = [ones(1,16000)];
soundsc(wave);
Why is this humming there? Does it have something to do with the hardware? Can I remove it?
  4 comentarios
Nikolaj Andreasen Klahn
Nikolaj Andreasen Klahn el 18 de Feb. de 2021
Using MATLAB R2020a on windows 10 - both headphones and loudspeaks have the issue.
Adam Danz
Adam Danz el 18 de Feb. de 2021
That means everything is working correctly. The issue is with the inputs or the expectation of what the inputs do, not with the sound function or with speakers or headphones.

Iniciar sesión para comentar.

Respuesta aceptada

Adam Danz
Adam Danz el 18 de Feb. de 2021
Editada: Adam Danz el 19 de Feb. de 2021
> I was exploring what a ramp sounds like [using 1:10000]
I think you're interpretting the audio data incorrectly but to your defense, Matlab's description of the audio data input y is terse. You're treating the input as though it represents pitch, hense values 1:10000 would be a ramp sound. But that's not what the audio data represents.
A quick intro to audio data
Consider this example of 3 notes followed by a chord.
duration = 1;
Fs = 10000;
t = 1/Fs : 1/Fs : duration;
A = sin(880*pi*t)';
Csh = sin(1100*pi*t)';
E = sin(1320*pi*t)';
chord = A + Csh + E;
chord = chord./max(chord);
wave = [A;Csh;E;chord];
sound(wave,Fs) % Play sound (4 sec.)
The first 200 samples of each note and the chord are shown below.
clf
T = table(A,Csh,E,chord,'VariableNames',{'Note 1','Note 2','Note 3','Chord'});
T(201:end,:) = [];
T.time = seconds(t(1:200)');
h = stackedplot(T,'XVariable','time');
ax = findobj(h.NodeChildren, 'Type','Axes');
set(ax, 'YLim', [-1,1], 'YTick', -1:.5:1)
grid on
The data you see above are the audio data played by the sound() function. The x-axis is time and the y-axis can be understood as amplitude or as a continuous sequence of pressure variation entering the ear. Pitch arises from the variation along the y axis through time or, more specificially, the frequency of the repeating patterns. If there is no variation, there are no tones. The amplitude also affects volume where larger amplitudes (+|-) across segments of data will be louder and amplitudes near 0 are quieter.
For example, compare the volume of the sound above and when its amplitudes are reduced to 1/10th.
sound(wave, Fs) % louder
sound(wave*.1, Fs) % quieter, same pitches
So when I play sound(ones(1,16000)) why do I hear a click at the beginning and end and some faint humming in between?
The clicks at the beginning and end are because that's the only part or your data that vary. The beginning goes from nothing (0) to 1 and the end goes from 1 to nothing. The faint humming is the sound of roundoff error due to floating point representation of computed values very close to 0 and other sources (see comments below).
So, how do I create a sound that ramps-up in pitch?
Ramp up in frequency.
x = 1:.2:5000;
f = x/1e+5;
y = cos(10*pi*f.*x);
sound(y,5000) % Play sound (~5 sec)
  4 comentarios
Adam Danz
Adam Danz el 18 de Feb. de 2021
> ...so that a vector of ones would keep [the speakers] motionless thus generating no sound between the start and the end.
Yes, this is what my understanding is, too.
But that differs from the first part of your question where a ramp in pitch was trying to be produced using 1:10000, unless I misunderstood that pat.

Iniciar sesión para comentar.

Más respuestas (0)

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by