Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Help with audio code

Subject: Help with audio code

From: Diogo

Date: 26 Mar, 2013 02:51:14

Message: 1 of 3

Hi, I am working on a project and I have 2 microphones connected to a matlab function and outputting to audio device:

(from audio device 1)----u1
                                  MATLAB function-----To audio device
(from audio device 2)----u2

This alone is working, but inside the function I am trying to make a simple operation like this:

x=u1;
y=u2;

x=x-mean(x);
y=y-mean(y);

and the system gives me the error :
Size mismatch (size 1024 x 2 ~= size 1 x 2)

This is strange because I tested this with simple sin waves(with different phases and amplitudes) and it worked...

Any help pls?

Subject: Help with audio code

From: Diogo

Date: 26 Mar, 2013 03:47:06

Message: 2 of 3

"Diogo" wrote in message <kir2f2$o7e$1@newscl01ah.mathworks.com>...
> Hi, I am working on a project and I have 2 microphones connected to a matlab function and outputting to audio device:
>
> (from audio device 1)----u1
> MATLAB function-----To audio device
> (from audio device 2)----u2
>
> This alone is working, but inside the function I am trying to make a simple operation like this:
>
> x=u1;
> y=u2;
>
> x=x-mean(x);
> y=y-mean(y);
>
> and the system gives me the error :
> Size mismatch (size 1024 x 2 ~= size 1 x 2)
>
> This is strange because I tested this with simple sin waves(with different phases and amplitudes) and it worked...
>
> Any help pls?

Ok, solved my problem by selecting only one channel to the microphone, 1024 * 1

doesnt make much sense since its still different but I guess its fixed..

Just another question, how can I equal u1 to 0?
its giving me the same error...the size mismatch

Subject: Help with audio code

From: Steven_Lord

Date: 26 Mar, 2013 14:10:40

Message: 3 of 3



"Diogo " <duradurad@hotmail.com> wrote in message
news:kir2f2$o7e$1@newscl01ah.mathworks.com...
> Hi, I am working on a project and I have 2 microphones connected to a
> matlab function and outputting to audio device:
>
> (from audio device 1)----u1
> MATLAB function-----To audio device
> (from audio device 2)----u2
>
> This alone is working, but inside the function I am trying to make a
> simple operation like this:
>
> x=u1;
> y=u2;
>
> x=x-mean(x);
> y=y-mean(y);
>
> and the system gives me the error : Size mismatch (size 1024 x 2 ~= size 1
> x 2)
>
> This is strange because I tested this with simple sin waves(with different
> phases and amplitudes) and it worked...
>
> Any help pls?

You can't subtract a vector from a matrix like that. You'd need to use
BSXFUN.

x = reshape(1:24, 12, 2)
x = bsxfun(@minus, x, mean(x))

It worked in your mono case because MEAN of a vector is a scalar and
subtracting a scalar from a vector works due to scalar expansion.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us