this script doesn't seem to work properly any more
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I've been given this script to generate MLS sequences and until recently it was working okay. Now I get this error code - 'Warning: Data clipped during write to file:'
Here's the code: -
% MLS generator
%
% Warning! - this can take a very long time for large n
close all
clear all
for n=2:16; %order of mls sequence
N=2^n-1; %length of sequence
% Define taps:
b = zeros(n,1);
switch n
case 2
b([ 1 2]) = 1;
case 3
b([ 2 3]) = 1;
case 4
b([ 3 4]) = 1;
case 5
b([ 3 5]) = 1;
case 6
b([ 5 6]) = 1;
case 7
b([ 6 7]) = 1;
case 8
b([ 2 3 5 8]) = 1;
case 9
b([ 5 9]) = 1;
case 10
b([ 7 10]) = 1;
case 11
b([ 9 11]) = 1;
case 12
b([ 6 8 11 12]) = 1;
case 13
b([ 9 10 12 13]) = 1;
case 14
b([ 4 8 13 14]) = 1;
case 15
b([14 15]) = 1;
case 16
b([ 4 13 15 16]) = 1;
case 17
b([14 17]) = 1;
case 18
b([11 18]) = 1;
case 19
b([14 17 18 19]) = 1;
case 20
b([17 20]) = 1;
case 21
b([19 21]) = 1;
case 22
b([21 22]) = 1;
case 23
b([18 23]) = 1;
case 24
b([17 22 23 24]) = 1;
case 25
b([ 3 25]) = 1;
case 26
b([ 1 7 8 26]) = 1;
case 27
b([ 1 7 8 27]) = 1;
case 28
b([ 3 28]) = 1;
case 29
b([ 2 29]) = 1;
case 30
b([ 1 15 16 30]) = 1;
case 31
b([ 3 31]) = 1;
case 32
b([ 1 27 28 32]) = 1;
otherwise
error('taps only defined for m<=31');
end
a = zeros(n,1); % Latches
a(1) = 1; % Set latches with some starting values
for m=n+1:N % Sum of eqn 28, one state at a time module 0
% a(m) = mod( sum( flipud(a(m-n:m-1)).*b(2:n+1) ),2 );
a(m) = mod(sum(flipud(a(m-n:m-1)).*b),2);
end
c = 2*a-1; % The best way to check if the mls sequence in a is correct is to plot the autocorrelation
C = fft(c);
figure;
plot(round(real(ifft(C.*conj(C)))))
wavwrite(c,sprintf('mls_%d.wav',N))
end
Any help would be great.
2 comentarios
Daniel Shub
el 4 de Abr. de 2012
Note that the best way to check for an mls sequence is not to plot the autocorrelation and inspect by eye. Also, it is unclear why if you know the taps you would want to plot every time.
Matt Fig
el 2 de Nov. de 2012
Tom's question:
I've been given this script to generate MLS sequences and until recently it was working okay. Now I get this error code - 'Warning: Data clipped during write to file:'
Here's the code: -
% MLS generator
%
% Warning! - this can take a very long time for large n
close all
clear all
for n=2:16; %order of mls sequence
N=2^n-1; %length of sequence
% Define taps:
b = zeros(n,1);
switch n
case 2
b([ 1 2]) = 1;
case 3
b([ 2 3]) = 1;
case 4
b([ 3 4]) = 1;
case 5
b([ 3 5]) = 1;
case 6
b([ 5 6]) = 1;
case 7
b([ 6 7]) = 1;
case 8
b([ 2 3 5 8]) = 1;
case 9
b([ 5 9]) = 1;
case 10
b([ 7 10]) = 1;
case 11
b([ 9 11]) = 1;
case 12
b([ 6 8 11 12]) = 1;
case 13
b([ 9 10 12 13]) = 1;
case 14
b([ 4 8 13 14]) = 1;
case 15
b([14 15]) = 1;
case 16
b([ 4 13 15 16]) = 1;
case 17
b([14 17]) = 1;
case 18
b([11 18]) = 1;
case 19
b([14 17 18 19]) = 1;
case 20
b([17 20]) = 1;
case 21
b([19 21]) = 1;
case 22
b([21 22]) = 1;
case 23
b([18 23]) = 1;
case 24
b([17 22 23 24]) = 1;
case 25
b([ 3 25]) = 1;
case 26
b([ 1 7 8 26]) = 1;
case 27
b([ 1 7 8 27]) = 1;
case 28
b([ 3 28]) = 1;
case 29
b([ 2 29]) = 1;
case 30
b([ 1 15 16 30]) = 1;
case 31
b([ 3 31]) = 1;
case 32
b([ 1 27 28 32]) = 1;
otherwise
error('taps only defined for m<=31');
end
a = zeros(n,1); % Latches
a(1) = 1; % Set latches with some starting values
for m=n+1:N % Sum of eqn 28, one state at a time module 0
% a(m) = mod( sum( flipud(a(m-n:m-1)).*b(2:n+1) ),2 );
a(m) = mod(sum(flipud(a(m-n:m-1)).*b),2);
end
c = 2*a-1; % The best way to check if the mls sequence in a is correct is to plot the autocorrelation
C = fft(c);
figure;
plot(round(real(ifft(C.*conj(C)))))
wavwrite(c,sprintf('mls_%d.wav',N))
end
Any help would be great.
Respuesta aceptada
Walter Roberson
el 4 de Abr. de 2012
With double precision data and no number-of-bits parameter to wavwrite(), the warning means that the data in "c" is outside the range –1.0 <= c < +1.0 .
Your mod(a,2) with integral data can generate values that are 0 or 1. Multiply by 2 and subtract 1 and you get values -1 and 1 exactly. The -1 exactly is fine, but the +1 exactly is out of range for wavwrite() unless you use N of 32 bits.
4 comentarios
Daniel Shub
el 4 de Abr. de 2012
It is possible you turned the warning off in your startup.m (or someplace else) and now the warning is on.
Más respuestas (1)
Geoff
el 4 de Abr. de 2012
A totally random aside... This script is also slow?
If you're repeating that switch statement thousands of times, why not put your indices into a cell:
idx = { [], [1 2], [2 3], [3 5], [5 6], ... };
Then in the loop:
b(idx{n}) = 1;
Also, your Latches preallocation surely should be size (N,1), not (n,1). That ought to make a huge difference, given how large N can be.
Ver también
Categorías
Más información sobre Audio I/O and Waveform Generation en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!