Does audioread not return a vector?

12 views (last 30 days)
I'm having a small issue with understanding why this conv wont pass through.
Fs = 33600;%sampling frequency
T = 1;
samples = [1,T*Fs];%this is my sample range, for seconds recorded change the multiplier
[filename,filepath] = uigetfile('*.*', 'Please choose audio data');
B = audioread(strcat(filepath,filename),samples);
A = zeros(1,100);
op = conv(A, B);
When I run this and select the file that I want to read, I get this Error:
Error using conv (line 28)
A and B must be vectors.
Error in convcheck (line 8)
op = conv(A, B);
I was under the impression that Audioread did return a vector, but if i'm wrong then there has to be another way to convolute audio signals that I'm unaware of?
thank you for your time.
  1 Comment
Stephen23
Stephen23 on 19 Apr 2019
"I was under the impression that Audioread did return a vector..."
The audioread documentation clearly states that the first output is "returned as an m-by-n matrix, where m is the number of audio samples read and n is the number of audio channels in the file. " So the answer to your question is no if there are two or more channels in the file.
It is more reliable to read the documentation than to rely on an "impression" .

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 19 Apr 2019
It depends on your audio file. A stereophonic signal will return an (N x 2) matrix, with the first column being the left channel, and the second column being the right channel. using:
NrChan = size(B,2);
will tell you this.
  2 Comments
Logan Betts
Logan Betts on 19 Apr 2019
I see, so if I want to convolve the audio file should I then try and make the file mono. Thank you for your help.
Star Strider
Star Strider on 19 Apr 2019
As always, my pleasure.
However to ‘make the file mono’ will necessarily remove or change the data in the file (unless the same information is present in both channels).

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 19 Apr 2019
No, often audioread() does not return a vector. audioread() normally returns a 2D array with one column per channel.
Note: you should think about providing an option such as 'valid' or 'same' to conv()
Note by the way that convolving with 0 is always going to return all zeros. You could skip the conv() call and just do
op = zeros(length(B) + length(A) - 1, 1);
  1 Comment
Logan Betts
Logan Betts on 19 Apr 2019
Ok, thanks you. I know that a convolution with 0s will always be zero, I should have specified that it was only a test to ensure the culprit was the audio file.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!