How can I fix this? Warning: Data clipped when writing file. > In audiowrite>clipInputData (line 407) In audiowrite (line 187) In generator (line 100)

15 次查看(过去 30 天)
function [dtmf_output] = generator(dial_num)
%
% Function to generate the DTMF signals
%
% Author: Pranam Janney Date: 15/05/04 Time: 17:50
% Email: pranamjanney@yahoo.com
%
% Usage:
% [dtmf_output,Num_of samples] = generator(dial_num,Num_of_samples,NoisePow);
% Inputs:
% dial_num = Number that is dialled
% Num_of_samples = Number of samples
% NoisePow = Noise power used to corrupt the signal
% Outputs:
% dtmf_output = the combination of two sinesoids corresponding to the
% number dialled
% Num_of_samples = Number of samples
% SNR = Signal to Noise Ratio
%
%
NoisePow=0;
Num_of_samples=4000;
Fs = 8000; % Sampling frequency
Ts = 1/Fs;
T = Ts*(0:Num_of_samples-1)';
x = (dial_num);
a = [];
ss = [];
for i = 1:8
switch x(i)
case '0'
F1 = 941;
F2 = 1336;
case '1'
F1 = 697;
F2 = 1209;
case '2'
F1 = 697;
F2 = 1336;
case '3'
F1 = 697;
F2 = 1477;
case 'A'
F1 = 697;
F2 = 1633;
case '4'
F1 = 770;
F2 = 1209;
case '5'
F1 = 770;
F2 = 1336;
case '6'
F1 = 770;
F2 = 1477;
case 'B'
F1 = 770;
F2 = 1633;
case '7'
F1 = 852;
F2 = 1209;
case '8'
F1 = 852;
F2 = 1336;
case '9'
F1 = 852;
F2 = 1477;
case 'C'
F1 = 852;
F2 = 1633;
case '*'
F1 = 941;
F2 = 1209;
case '#'
F1 = 941;
F2 = 1477;
otherwise
F1 = 941;
F2 = 1633;
end
first_sine = cos(2*pi*F1*T); % first sinusoidal signal
second_sine = cos(2*pi*F2*T); % second sinusoidal signal
%dtmf_output = first_sine + second_sine;
d = first_sine + second_sine;
%%% Adding noise to the generated DTMF output
% NoisePow has to be below 5 for getting the correct decode output
dtmf_output = d + NoisePow * rand(size(d));
% Generating Tones
ss(i,:) = dtmf_output;
filename = strcat('out',int2str(i),'.wav');
audiowrite(filename,dtmf_output, Fs);
w = fft(dtmf_output);
N = length(dtmf_output);
f = (0:N-1)/N*Fs;
figure();
plot(f, abs(w),'b')
xlabel('Frequency (Hz)')
ylabel('Amplitude')
title('FFT Amplitude Spectrum')
soundsc(dtmf_output);
pause(0.5)
end
y = [];
for i = 1:8
[y1 Fs] = audioread(strcat('out',int2str(i),'.wav'));
y = [y; y1];
end
audiowrite('finatout.wav',y, Fs);
% Signal to Noise Ratio
% figure(1);
% title('THE DTMF OUTPUT');
% plot(dtmf_output);
  3 个评论
dpb
dpb 2021-4-2
Don't let the magnitude exceed the allowable...what is the range of the target device, first?
"How" is dependent upon what is wanted/required in terms of what is being generated. The simplest way would be to generate the full time history first then scale it by the ratio of actual/allowable maxima (in absolute value).
If you have to generate and send in real time you need to compute the necessary scale factor to apply to the output signal to ensure it doesn't exceed the allowable value.
Of course, you can kill the error message by just clipping the generated signal before writing by use of min(), max() operations before the write...of course, the signal will still be clipped, it'll just be before there's annoying message. That is probably NOT the solution you should use.

请先登录,再进行评论。

回答(1 个)

Jan
Jan 2021-4-2
You can normalize the data such, that the values are in th allowed range [-1 +1]:
dtmf_output = dtmf_output ./ max(abs(dtmf_output(:)));

类别

Help CenterFile Exchange 中查找有关 MATLAB Mobile 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by