Clipping a sound wave

8 views (last 30 days)
Keeks
Keeks on 21 Feb 2016
Answered: Star Strider on 21 Feb 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

Answers (1)

Star Strider
Star Strider on 21 Feb 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.

Categories

Find more on Simulation, Tuning, and Visualization in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!