Clipping a sound wave

8 次查看(过去 30 天)
Keeks
Keeks 2016-2-21
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

回答(1 个)

Star Strider
Star Strider 2016-2-21
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.

类别

Help CenterFile Exchange 中查找有关 Simulation, Tuning, and Visualization 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by