Clipping a sound wave

5 vues (au cours des 30 derniers jours)
Keeks
Keeks le 21 Fév 2016
Hello everyone!
I have a soundwave (a 30000x2 vector) which I want to clip (cut off) at certain points. I calculated the maximum amplitude and now I want to cut off every value 60% above and below this value. So like if [value] > 0.6*maxamp or [value] < -0.6*maxamp, then set those values to [0.6*maxamp] and [-0.6*maxamp], respectively. I simply cannot figure out how to put this into a proper code/function. I'd be thankful for any suggestions on how to solve this!
Greetings

Réponses (1)

Star Strider
Star Strider le 21 Fév 2016
Something like this will work:
Fs = 44100;
L = 5;
t = linspace(0, Fs*L, Fs*L);
F0 = 440;
s = sin(2*pi*F0*t) + sin(2*pi*F0*3*t) + sin(2*pi*F0*5*t);
s_max = 0.6*max(abs(s));
pos_idx = (s > s_max);
neg_idx = (s < -s_max);
s_clipped(neg_idx) = -s_max;
s_clipped(pos_idx) = +s_max;
sound(s*10, Fs)
pause(L)
sound(s_clipped, Fs)
Make appropriate changes to work with your signal.

Catégories

En savoir plus sur Simulation, Tuning, and Visualization dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by