DSPRelated.com
Forums

reading of complex values

Started by Medris July 3, 2007
Hi,

I would like to ask this simple question, how can I get the complex value
in DSP. when I read the sumation of complex value i got only real value.
Any help.
 
Example:

x[i].re=2;
x[i].im=3;
I got x2[i]=5 not 2+3i

so how can I get the complex value.

Thanks

On 3 Jul, 12:57, "Medris" <maboz...@yahoo.com> wrote:
> Hi, > > I would like to ask this simple question, how can I get the complex value > in DSP. when I read the sumation of complex value i got only real value. > Any help. > > Example: > > x[i].re=2; > x[i].im=3; > I got x2[i]=5 not 2+3i > > so how can I get the complex value.
There are a couple of questions that need answering first: - What programming language is this? - How are the variables declared? - What does the code which performs the actual summation look like? Rune
Medris wrote:
> Hi, > > I would like to ask this simple question, how can I get the complex value > in DSP. when I read the sumation of complex value i got only real value. > Any help. > > Example: > > x[i].re=2; > x[i].im=3; > I got x2[i]=5 not 2+3i > > so how can I get the complex value. >
If this is C or C++ then x[i] is the same as x[i].re (since they have the same address), although in most cases you should at least get a compiler warning if you try to treat x[i] as a value. To display a complex value you should so something like this: printf("%g + j%g\n", x[i].re, x[i].im); Paul
"Medris" <mabozaed@yahoo.com> writes:

> Hi, > > I would like to ask this simple question, how can I get the complex value > in DSP. when I read the sumation of complex value i got only real value. > Any help. > > Example: > > x[i].re=2; > x[i].im=3; > I got x2[i]=5 not 2+3i > > so how can I get the complex value.
Are companies trusting their products to folks like this? Or is this a student? (Maybe Vladimir is rubbing off on me...) -- % Randy Yates % "Rollin' and riding and slippin' and %% Fuquay-Varina, NC % sliding, it's magic." %%% 919-577-9882 % %%%% <yates@ieee.org> % 'Living' Thing', *A New World Record*, ELO http://home.earthlink.net/~yatescr
Randy Yates wrote:
> "Medris" <mabozaed@yahoo.com> writes: > >> Hi, >> >> I would like to ask this simple question, how can I get the complex value >> in DSP. when I read the sumation of complex value i got only real value. >> Any help. >> >> Example: >> >> x[i].re=2; >> x[i].im=3; >> I got x2[i]=5 not 2+3i >> >> so how can I get the complex value. > > Are companies trusting their products to folks like this? Or is this > a student? > > (Maybe Vladimir is rubbing off on me...)
And well he should, it seems. In the old days -- when I was (ahem) coming up, Sonny -- we were supposed to understand the material. We used tools to help manipulate it, but the tools were primitive enough to require understanding. When I did distortion analysis on paper, I picked off points on the plotted waveform at 15-degree intervals of the fundamental and computed the Fourier series that matched the points. Now, the tools have grown so powerful that many operations require only a knowledge of the appropriate incantation. These sorcerers' apprentices just turn the crank, without knowledge of the machinery that the crank connects to, or even realizing that machinery is part of the process. It has been some years since a CE graduate asked me how computer hardware distinguished between bits that represent numbers, and those that represent ASCII. He put me down as an ignoramus because I told him that was software's province. "Can't be!" Programs like Matlab that let one deal with concepts without bogging down in details allow one to seem useful without understanding the concepts at all. EE seems to be going the way that CE went. Jerry -- Engineering is the art of making what you want from things you can get. &macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;
Jerry Avins wrote:
> Randy Yates wrote: >> "Medris" <mabozaed@yahoo.com> writes: >> >>> Hi, >>> >>> I would like to ask this simple question, how can I get the complex >>> value >>> in DSP. when I read the sumation of complex value i got only real value. >>> Any help. >>> >>> Example: >>> >>> x[i].re=2; >>> x[i].im=3; >>> I got x2[i]=5 not 2+3i >>> >>> so how can I get the complex value. >> >> Are companies trusting their products to folks like this? Or is this >> a student? >> >> (Maybe Vladimir is rubbing off on me...) > > And well he should, it seems. In the old days -- when I was (ahem) > coming up, Sonny -- we were supposed to understand the material. We used > tools to help manipulate it, but the tools were primitive enough to > require understanding. When I did distortion analysis on paper, I picked > off points on the plotted waveform at 15-degree intervals of the > fundamental and computed the Fourier series that matched the points. > > Now, the tools have grown so powerful that many operations require only > a knowledge of the appropriate incantation. These sorcerers' apprentices > just turn the crank, without knowledge of the machinery that the crank > connects to, or even realizing that machinery is part of the process. > > It has been some years since a CE graduate asked me how computer > hardware distinguished between bits that represent numbers, and those > that represent ASCII. He put me down as an ignoramus because I told him > that was software's province. "Can't be!" > > Programs like Matlab that let one deal with concepts without bogging > down in details allow one to seem useful without understanding the > concepts at all. EE seems to be going the way that CE went. >
I know older guys who just know how to input the numbers and turn the crank -- they just have a longer set of procedures to follow by rote. There are younger people in both CE and EE who know the underlying principals. They're generally highly prized by their colleagues, and if they bill themselves right they're even highly prized by upper management, sometimes. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com Do you need to implement control loops in software? "Applied Control Theory for Embedded Systems" gives you just what it says. See details at http://www.wescottdesign.com/actfes/actfes.html
Medris wrote:
> Hi, > > I would like to ask this simple question, how can I get the complex value > in DSP. when I read the sumation of complex value i got only real value. > Any help. > > Example: > > x[i].re=2; > x[i].im=3; > I got x2[i]=5 not 2+3i > > so how can I get the complex value. >
As others have pointed out, you're trying to get superficial information, but you're not supplying the deeper information that one needs to answer your question. What language? If it's C++, you're loading x (which is presumably of type complex), but you're querying x2 (which is of entirely unknown type). If it's something else, then how does x2 relate to x? Even better questions to answer would be: * How is x[i] stored? * What is it's internal structure? * Is x of an intrinsic type, or is a library type? (note: in C++ the complex type is a library class defined in the 'math' header file; in Scilab (and Matlab, I think) all numbers are stored as matrices of complex -- real scalars are just a special case). * What does the compiler (or interpreter, or compiler+library) do with 'x ='; what do they do when you attempt to print x? If you answer these questions, then you should have no trouble answering your questions, and all related ones, on your own. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com Do you need to implement control loops in software? "Applied Control Theory for Embedded Systems" gives you just what it says. See details at http://www.wescottdesign.com/actfes/actfes.html
On Jul 3, 9:37 am, Jerry Avins <j...@ieee.org> wrote:

[snip]
> Now, the tools have grown so powerful that many operations require only > a knowledge of the appropriate incantation. These sorcerers' apprentices > just turn the crank, without knowledge of the machinery that the crank > connects to, or even realizing that machinery is part of the process. > > It has been some years since a CE graduate asked me how computer > hardware distinguished between bits that represent numbers, and those > that represent ASCII. He put me down as an ignoramus because I told him > that was software's province. "Can't be!" > > Programs like Matlab that let one deal with concepts without bogging > down in details allow one to seem useful without understanding the > concepts at all. EE seems to be going the way that CE went. > > Jerry
Although I agree with much of what Jerry is saying, it should be noted that the drive to learn to apply more "advanced" science and technology and teaching this to undergraduates means that we have to choose and limit what the focus is. Most of the time, it's done by encapsulating things into nice, well-behaved "black boxes" that the users do not have to know what is inside. Principally, I have no issues with this, except that in most cases knowledge of operating these black boxes does not translate to knowing what is inside. And when the student is pushed out into the real world, he/she faces a situation where they have to know how to build one. How is this reasonable for anybody? I think that a good start would be to admit this kind of limitations, and to be candid about the necessity to pick and choose what students learn. For that, I think it may be good to further divide up EE education into several majors. It's hard to expect undergrads to go through so much material in 4 years. At least by dividing up the major, we can more accurately represent what the students are expected to know by the end of their education. Julius
Tim Wescott wrote:

   ...

> I know older guys who just know how to input the numbers and turn the > crank -- they just have a longer set of procedures to follow by rote.
We call them "hacks". They exist in all professions, including writer and composer and educator.
> There are younger people in both CE and EE who know the underlying > principals. They're generally highly prized by their colleagues, and if > they bill themselves right they're even highly prized by upper > management, sometimes.
Of course. I've even helped train a few. But there are people out there who, to find log2(16) use their calculators to find log10(16)/log10(2), and an alarming number who don't know that -- or why -- it works. That's not an exaggeration. A job candidate actually did it in an interview. I studied by turning to the problems at the back of the section and tackling them in order. When I got to one I wasn't clear about -- that happened often -- I read the applicable text and went back to the problem. When I had finished all of them, I reread the section from the beginning, often finding easier ways to do a problem than the way I had cobbled together. If I had been able to use Mathcad with a motor-design package, my first run-through would likely not have required my reading the text at all. It would have been easy to lead myself into disaster by believing that I actually knew the material. I suspect that more and more modern students fall into that trap. I can drive a nail without bending it with only a rock. Some modern "carpenters" can't drive a nail straight unless they have compressed air. Jerry -- Engineering is the art of making what you want from things you can get. &macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;
Thanks a lot for all of you for reply, in fact I am using in my work 67dsk
and CCS 2.1 version and I used C-language for programming my project. I
would like to display my result using contour function and because this
function is not available in CCS I used interfacing function between
MatLab and ccs and it was fine, but the problem I couldn't read the
complex value I got the both values as real values. Here both codes in
matlab and cccs: 

this a part from c code in CCS:

for( i = 0 ; i < N/2 ; i++ ) 
  {
   W[i].re = cos(D*i);// where N is = 512 (number of FFT points)    
   W[i].im = sin(D*i);		    
  }	
    for( i = 0 ; i <N ; i++ ) 
  {	   
   x[i].re=(float)((short)input_signal[i]);
    x[i].im = 0 ;				    
     y[i]=samples[i]; 
  }
  
 digitrev_index(iTwid, N/2, 2); 
 bitrev(W, iTwid, N/2);
 		     
  	
 cfftr2_dit(x, W, N ) ;			    
  	
 digitrev_index(iData, N, 2);	    
 bitrev(x, iData, N);
 
  for (i=0;i<512;i++){
  //x[i].re=2.2*i;
  //x[i].im=4.3*i;
  x4[i]=x[i].re;
  x5[i]=x[i].im;
  } 
     
     for(i=0;i<512;i++)
        simt[i]=i;
  
         for(i=0;i<N;i++)
	{
		l=i+1;
		if(i>0) k=1;
		for(j=0;j<4;j++)
		{if(l>(N-1)) l=0;
x2[i][j]=x[l].re*k*exp(-2.0*PI*PI*simt[i]*simt[i]/(1.0*(j+1)*64*64*(j+1)));
x3[i][j]=x[l].im*k*exp(-2.0*PI*PI*simt[i]*simt[i]/(1.0*(j+1)*64*64*(j+1)));
	 //x4[j]=exp(-2.0*PI*PI*simt[j]*simt[j]/(16.0*(5.0)*(5.0)));
	   l++;     
	 }
	 
 matlab code(just a part from my code):  

cc=ccsdsp;
  
  x2 = read(cc,address(cc,'x2'),'single',512);
  x3 = read(cc,address(cc,'x3'),'single',512);
 
 y= read(cc,address(cc,'y'),'single',512);