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

New to MATLAB?

Why am I getting this error "??? error using ==> times matrix dimensions must agree" in matlab?

Asked by Debajyoti

Debajyoti (view profile)

on 21 Apr 2013

design a FIR low pass filter using Kaiser window

a1phap=0.1
a1phas=44
ws=30
wp=20
wsf=100
B=ws-wp
wc=0.5*(ws+wp)
wcr=wc*2*pi/wsf
D=(a1phas-7.95)/14.36
N=ceil((wsf*D/B)+1)
a1pha=(N-1)/2
gamma=(.5842*(a1phas-21).^(0.4)+0.07886*(a1phas-21))
n=0:1:N-1
hd=sin(wcr*(n-a1pha))./(pi*(n-a1pha))
hd(a1pha+1)=0.5
wk=(kaiser(N,gamma))
hn=hd.*wk     % *(HERE I AM GETTING THIS ERROR)*
W=85:5:120
h=freqz(hn,1,W)
plot(W/pi,20*log10(abs(h)))

those two matrices have the same dimensions of 27..still why this error?

0 Comments

Debajyoti

Debajyoti (view profile)

Products

No products are associated with this question.

3 Answers

Answer by Cedric Wannaz

Cedric Wannaz (view profile)

on 21 Apr 2013
Accepted answer

You have to transpose either wk or hd, because one is a column vector and the other a row vector. E.g.

 hn = hd .* wk.'

0 Comments

Cedric Wannaz

Cedric Wannaz (view profile)

Answer by the cyclist

the cyclist (view profile)

on 21 Apr 2013
Edited by the cyclist

the cyclist (view profile)

on 21 Apr 2013

I don't have the Signal Processing Toolbox, so I can't execute the kaiser() function. However, the documentation indicates that it will output a column vector. Your vector hd is a row vector, so it does not actually have the same dimension. You need to transpose one of them.

0 Comments

the cyclist

the cyclist (view profile)

Answer by Chandra Shekhar

Chandra Shekhar (view profile)

on 21 Apr 2013
Edited by Chandra Shekhar

Chandra Shekhar (view profile)

on 21 Apr 2013

Don't use dot product,edit that line like this

hn=hd*wk;

but you will get single value after multiplying,but 'freqz' function requires vector as a input.

if you need vector then do like this, you will get waveform.

hn=hd. * wk ' ;

0 Comments

Chandra Shekhar

Chandra Shekhar (view profile)

Contact us