-1
$\begingroup$

I am trying to use the following crossfading code in MATLAB. I use audioread() to open the audio signals and I convert both of them to mono. When I use .wav files, it works perfectly fine. But when I use .aif files, I get the following warning message for the last line:

"Subscript indices must either be real positive integers or logicals."

Is there any way I can fix it without having to convert my audio signals?

n = 200;

W = linspace(1,0,n)';                                    

S1(end-n+1:end) = S1(end-n+1:end).*W;

S2(1:n) = S2(1:n).*(1-W);

S12 = zeros(size(S1,1) + size(S2,1) - n, 1);

S12(1:size(S1,1)) = S1;

S12(end-size(S2,1)+1:end) = S12(end-size(S2,1)+1:end) + S2; %this is where I get the warning
$\endgroup$
  • $\begingroup$ a programming/debugging question, not a signal processing question. $\endgroup$ – Marcus Müller Apr 20 '17 at 20:07
0
$\begingroup$

You are trying to access to the index number:

end-size(S2,1)+1

That can be negative or zero, and that's why you may be getting that error message. You have to be sure that the length of S2 is such that the final result is positive.

|improve this answer|||||
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.