How to write audio without data clipping?

10 views (last 30 days)
Hello,
I want to write audio without data clipping. I tried by multiplying audio coefficients with float number (e.g. 0.1, 0.5, 0.001, etc.) to get the value within the range of -1 to +1. But this error are still occurred Warning: Data clipped when writing file. In audiowrite>clipInputData In audiowrite . I would be grateful if someone help me in this error.

Accepted Answer

Star Strider
Star Strider on 15 Feb 2018
Try this to normalise the signals before you write them:
t = 0:99; % Time Vector (For Plotting)
V1 = randi([-9 9], 100, 1); % Create Out-Of-Range Data
V2 = V1 / max(abs(V1)); % Normalise To ±1
figure(1)
plot(t, V1, t, V2)
hold on
plot(xlim, [1 1], '--k')
plot(xlim, [-1 -1], '--k')
hold off
grid
legend('Original', 'Normalised', '±1')
The code simply divides all the data by the maximum of the absolute value (so it is not necessary to test both the positive and negative values). The plot illustrates the input and output of the normalisation.
Experiment to get the result you want.
  3 Comments
Star Strider
Star Strider on 16 Feb 2018
My pleasure.
If my Answer helps you solve your problem, please Accept it!
Pham Xuan Trung
Pham Xuan Trung on 9 Jul 2020
It works perfectly. You are amazing!

Sign in to comment.

More Answers (0)

Categories

Find more on Audio I/O and Waveform Generation in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!