DSPRelated.com
Forums

complex filter in matlab

Started by sudarshan_onkar January 10, 2013
Hi All,
          I was trying to use filter function in matlab with complex
co-efficient. The result however is not matching with hand calculation.
Interestingly the real part of output matches correctly but imaginary part
is negative . So i am not sure where its going wrong and whether i am
interpreting results rightly. Please throw some light

code

a = [1.0000 + 0j 0 - 1.9556j -0.9565 +0j];
b = [1.0000 + 0j 0+2j -1+0j];
in = [1 zeros(1,10)];
out = filter(b,a,in);

out =
1.0000
        0 - 3.9556i
  -7.7788
        0 +11.4283i
  14.9081
        0 -18.2221i
 -21.3743
        0 +24.3686i
  27.2090
        0 -29.8994i


In the above code i was expecting 0 + 3.9556j when you do a hand calc but i
am getting 0 - 3.9556 and same is the case with all output imag part. Why
the o/p is conjugated ? (assuming hand calc is correct) 
Hi,

For a start, check the formatting, and remove spaces. For example, I think
matlab will read +0j in your first line as a separate list element, which
is probably not what you intended. 

>Hi, > >For a start, check the formatting, and remove spaces. For example, I
think
>matlab will read +0j in your first line as a separate list element, which >is probably not what you intended. > >
Hi , I agree there is indentation problem but its probably because of copy paste. I have checked printing out a and b and they are as intended. Regards Sudarshan
out is a row vector but displayed as column vector. 
Did you by any chance type: out'
This will display the conjugated transpose of out, try:  out.'

--
rgds
 
>out is a row vector but displayed as column vector. >Did you by any chance type: out' >This will display the conjugated transpose of out, try: out.' > >-- >rgds > >
Yes. That was the issue. Thanks a lot. Regards Sudarshan
On Thu, 10 Jan 2013 11:28:57 -0600, sudarshan_onkar wrote:

>>out is a row vector but displayed as column vector. Did you by any >>chance type: out' >>This will display the conjugated transpose of out, try: out.' >> >>-- >>rgds >> >> >> > Yes. That was the issue. Thanks a lot.
That trips me up all the time, too. -- My liberal friends think I'm a conservative kook. My conservative friends think I'm a liberal kook. Why am I not happy that they have found common ground? Tim Wescott, Communications, Control, Circuits & Software http://www.wescottdesign.com
On Thu, 10 Jan 2013 18:21:03 +0100, "willi"
<williwie_123_rm_321_@hotmail.com> wrote:

>out is a row vector but displayed as column vector. >Did you by any chance type: out' >This will display the conjugated transpose of out, try: out.'
Good job willi! (That conjugation that takes place during transposition has tripped me up more than once.) [-Rick-]
On Thursday, January 10, 2013 4:38:08 PM UTC-7, Rick Lyons wrote:
> On Thu, 10 Jan 2013 18:21:03 +0100, "willi" wrote: >out is a row vector but displayed as column vector. >Did you by any chance type: out' >This will display the conjugated transpose of out, try: out.' Good job willi! (That conjugation that takes place during transposition has tripped me up more than once.) [-Rick-]
Add me to that list. I think MATLAB needs better notation to make the two more distinct. At least that's my excuse :)
On Friday, January 11, 2013 6:53:58 AM UTC-8, Bryan wrote:
...
> > Add me to that list. I think MATLAB needs better notation to make the two more distinct. At least that's my excuse :)
From: http://www.mathworks.com/help/matlab/ref/arithmeticoperators.html "MATLAB software has two different types of arithmetic operations. Matrix arithmetic operations are defined by the rules of linear algebra. Array arithmetic operations are carried out element by element, and can be used with multidimensional arrays. The period character (.) distinguishes the array operations from the matrix operations. However, since the matrix and array operations are the same for addition and subtraction, the character pairs .+ and .- are not used." RTFM? Dale B. Dalrymple
On Saturday, January 12, 2013 12:50:26 AM UTC-7, dbd wrote:
> On Friday, January 11, 2013 6:53:58 AM UTC-8, Bryan wrote: ... > > Add me to that list. I think MATLAB needs better notation to make the two more distinct. At least that's my excuse :) From: http://www.mathworks.com/help/matlab/ref/arithmeticoperators.html "MATLAB software has two different types of arithmetic operations. Matrix arithmetic operations are defined by the rules of linear algebra. Array arithmetic operations are carried out element by element, and can be used with multidimensional arrays. The period character (.) distinguishes the array operations from the matrix operations. However, since the matrix and array operations are the same for addition and subtraction, the character pairs .+ and .- are not used." RTFM? Dale B. Dalrymple
I've RTFM, thanks. That's not my issue; my issue is the choice of notation (' and .'). In linear algebra, the standard notation is defined by x^T for transpose and x^H for Hermitian (conjugate) transpose. But since you brought it up, how does the paragraph you posted explain the behavior of ' vs .'? What is an elementwise transpose? What is an array transpose? Transpose is by its nature a matrix operation.