2
votes

I am VERY new to Matlab and am trying to generate a .wav file, but I keep getting an Unsupported number of Channels error. Here is my code.

TTL = zeros(2, 2205);
TTL(1,1:2205) = 2;
audiowrite('hereitis.wav', TTL, 44100, 'BitsPerSample', 16);

I'm fairly certain that my problem is with TTL since I have used Matlab once or twice in the past to generate a .wav file. What I am trying to do is save a sound that another person is transmitting over analog using the Matlab Data Acquisition Toolbox. I don't think that I am too far off the mark since I have been able to play the sound using Sound(TTL, 44100);

Thanks in advance.

1

1 Answers

5
votes

You have two problems here.

First, as help audiowrite says:

Stereo data should be specified as a matrix with two columns.

But you have two rows, so you need to change it. If you run changed code, you'll get warning:

Warning: Data clipped when writing file. 
>In audiowrite>clipInputData at 390   
In audiowrite at 166

It means you need to use proper data type for your signal (in this case int16). So after this modifications we come to this code:

TTL = int16(zeros(2205, 2));
TTL(1:2205, 1) = 2;
audiowrite('hereitis.wav', TTL, 44100, 'BitsPerSample', 16);