フィルターのクリア

Why i am gettiing warning

3 ビュー (過去 30 日間)
moonman
moonman 2011 年 10 月 8 日
移動済み: DGM 2023 年 2 月 26 日
I have generated dtmf tones and i am listening them i tried to write them in wave file by using this command
wavwrite(dtmf,8000,'alpha');
Although the file is saved but i m gettiing these warnings Can u explain me these
Warning: Data clipped during write to file:alpha
> In wavwrite>PCM_Quantize at 287
In wavwrite>write_wavedat at 309
In wavwrite at 138
In dtmfdial at 100

採用された回答

Jan
Jan 2011 年 10 月 8 日
The line 287 of WAVWRITE is reached only for less than 32 bit precision.
If you write a WAV-file with 32 bits resoltution, the allowed data range is -1 <= Y <= 1. But for 8, 16 or 24 bits, the limits are -1 <= Y < 1, such that Y==1 creates the clipping warning.
Even Y./max(abs(Y)) will not catch this. Does anybody knows an efficient method for scaling?
  2 件のコメント
Jan
Jan 2011 年 10 月 8 日
BTW: WAVWRITE is a nice example for a bad programming style. E.g. in PCM_Quantize:
1. Do not calculate "2.^(nbits-1)", if "switch nbits" is following directly. If all 3 valid nbits are hardcoded, hardcoding the range is better.
2. "[path name ext] = fileparts( fmt.filename )"? Do not shaddow the built-in "path", name and ext are needed in case of errors only, so do not obtain them as default.
3. "ylim = [-1 +1];"? Do not shaddow built-in function names.
4. Three lines to create the [1x2] vector qlim? What about "qlim = [b-m, b+1-1]"? But two scalars would be smarter.
5. "i = find(y < qlim(1)); if ~isempty(i) ..."? Do not shaddow the built-in "i". Logical indexing is faster: "idx = (y < qlim(1)), if any(idx) ...".
This could be continued: IF statements with side-effects; FINDSTR; FOPEN('wb') although there is no 'b' format since Matlab 5.3 anymore; an auto-indent would be fancy also.
Well.
Daniel Shub
Daniel Shub 2011 年 10 月 26 日
@Jan, in answer to your question:
Y = Y./max(abs(Y(:)))*(1-(2^-(nBits-1)));
A limitation of signed integers is that you cannot have symmetric fullscale data.

サインインしてコメントする。

その他の回答 (6 件)

Walter Roberson
Walter Roberson 2011 年 10 月 8 日
編集済み: Walter Roberson 2015 年 10 月 20 日
You have values that were either less than -1 or greater than (or equal to) 1.
  2 件のコメント
moonman
moonman 2011 年 10 月 8 日
is this ok or there is some flaw in my code
i am generating DTMF tones
Walter Roberson
Walter Roberson 2011 年 10 月 8 日
Clipping could introduce significant distortion to the signal, potentially even enough to lose information about what frequency a particular pulse was.
You should try to figure out why you are getting the clipping.
Sometimes clipping happens because people are working with values in the range 0 to 255 and assume that this will be somehow noticed by wavwrite() and turned in to 8 bit values. And wavwrite() can handle 8 bit values without difficulty, but it looks at the data type (double vs uint8) to decide what the values are intended to represent rather than looking at the range of values. Sometimes people miss something small in their code and have their uint8 data turn in to double data when the didn't intend to.
But my guess is that you are doing simple addition of the signals for the individual tones and coming out with values up to +/- 2 because of that. Scaling the whole stream of data in response is not really appropriate (otherwise all your monofrequency tones come out at half volume): instead the code that is doing the additive generation of those two signals should ensure that the sum is kept within range.

サインインしてコメントする。


Walter Roberson
Walter Roberson 2011 年 10 月 26 日
The below code should adjust the range to be no more negative than -1 (inclusive), and less positive than 1 (exclusive):
maxd = max(dtmf(:));
mind = min(dtmf(:));
if mind + maxd < 0 %more negative than positive
dtmf = dtmf ./ (-mind);
else
dtmf = dtmf ./ (maxd * (1+eps));
end
  3 件のコメント
Walter Roberson
Walter Roberson 2011 年 11 月 5 日
Include it just before the wavwrite()
Geethu
Geethu 2011 年 11 月 8 日
Thank you!!! It worked!

サインインしてコメントする。


Wayne King
Wayne King 2011 年 10 月 8 日
Hi, Moonman, as Walter correctly states, the values in your vector (waveform) exceed 1 and -1. You don't want the data values clipped in your wav file, so try.
dtmf = dtmf./max(abs(dtmf));
and try to write it again.
  4 件のコメント
Sean de Wolski
Sean de Wolski 2011 年 10 月 25 日
移動済み: DGM 2023 年 2 月 26 日
what error?
what does size(dtmf) return?
moonman
moonman 2011 年 10 月 25 日
移動済み: DGM 2023 年 2 月 26 日
now i am not getting error
wavwrite(dtmf,8000,32,'alpha');
with 32 bit

サインインしてコメントする。


moonman
moonman 2011 年 11 月 5 日
Write it like this
wavwrite(dtmf,8000,32,'alpha');

tammna abid
tammna abid 2012 年 5 月 10 日
i guess now its totally different error of window or somthing ...
don't know if i am rite or not
  1 件のコメント
Daniel Shub
Daniel Shub 2012 年 5 月 10 日
No, the problem is you are creating a 32 bit wav file, which is pretty rare. Your best bet is to create a 16 bit wav file. In order to do this your array needs to be scaled so that the magnitude of every sample is less than 1.

サインインしてコメントする。


Ingo Schalk-Schupp
Ingo Schalk-Schupp 2015 年 10 月 20 日
In wavwrite.m, replace:
m = 2.^(nbits-1);
with
m = 2.^(nbits-1)-1;
This scales the data to the maximum positive integer range, instead of the negative. As a result, float data that is scaled to a maximum absolute value of 1 does not get clipped. However, you will have a different scaling than the one implemented by MATLAB. I consider this a minor drawback assuming that you can choose your normalization freely.
As was mentioned before, the reason for the problem is that signed integer representations typically allow for an additional negative number, e.g., -32768..32767. In my opinion, quantizing float to integer should always choose the smaller absolute value as the normalization factor, because only then will the integer signal stay symmetric and unclipped.
  1 件のコメント
Ingo Schalk-Schupp
Ingo Schalk-Schupp 2015 年 10 月 20 日
You could as well hook in your own integer conversion function, but do not forget to warn about actual clipping.

サインインしてコメントする。

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by