# Real To Complex Stream Conversion

Started by October 1, 2004
```Hi all,
I have a need to sample audio from my sound card and process it.
However, the hardware I am processing it on works faster in complex
domain than real domain.  I know this may sound funny, but it is true.

In essence, I need to convert a real stream sampled at N to a complex
stream sampled at N/2.  Not sure what the best way to do this is or if
it can even be done.

Here are the ways I have been told by others to accomplish this.  Are
these correct?

1. To keep the N samp rate.. i can have two sensors, both sampling at N
but one sensore 90 degrees out of phase when sampling.  I believe this
is the best way to get complex data, but dont have the capabilities to
do this in my system.

2. Sample at N and get a stream of reals.  Perform the Hilbert Transform
to get N/2 complex samples.  Not sure of what a Hilbert transform
does...I though it takes your signal and makes it 90 degrees out of
phase.. this brings me to the third solution.

3. Sample reals at N.  Perform Hilbert transform to shift wave by 90
degree.... Mix hilbert transform with reals to get a samp freq of N.
Looks like this output = reals + j*Hilbert_XForm

4.  Sample reals at N.  Then, make every 4 samples the real part
(position 1)... and the samples at positions 2 the complex part.. thus
those are 90 degees of the sampling frequency N/4.  Discard parts 3 and
4 of the N samples.  This has me downsampling to N/4 which isnt a
problem bth.
N   -> 1    90    180  270   1
N/4 -> 1     2     3    4

Any help appreciated it!

Isaac
```
```Hi Isaac.

Isaac> Hi all, I have a need to sample audio from my sound card and
Isaac> process it. However, the hardware I am processing it on works
Isaac> faster in complex domain than real domain.  I know this may
Isaac> sound funny, but it is true. Read on...

Isaac> In essence, I need to convert a real stream sampled at N to a
Isaac> complex stream sampled at N/2.  Not sure what the best way to
Isaac> do this is or if it can even be done.

Isaac> Here are the ways I have been told by others to accomplish
Isaac> this.  Are these correct?

Isaac> 1. To keep the N samp rate.. i can have two sensors, both
Isaac> sampling at N but one sensore 90 degrees out of phase when
Isaac> sampling.  I believe this is the best way to get complex data,
Isaac> but dont have the capabilities to do this in my system.

Isaac> 2. Sample at N and get a stream of reals.  Perform the Hilbert
Isaac> Transform to get N/2 complex samples.  Not sure of what a
Isaac> Hilbert transform does...I though it takes your signal and
Isaac> makes it 90 degrees out of phase.. this brings me to the third
Isaac> solution.

Isaac> 3. Sample reals at N.  Perform Hilbert transform to shift wave
Isaac> by 90 degree.... Mix hilbert transform with reals to get a samp
Isaac> freq of N. Looks like this output = reals + j*Hilbert_XForm

Isaac> 4.  Sample reals at N.  Then, make every 4 samples the real
Isaac> part (position 1)... and the samples at positions 2 the complex
Isaac> part.. thus those are 90 degees of the sampling frequency N/4.
Isaac> Discard parts 3 and 4 of the N samples.  This has me
Isaac> downsampling to N/4 which isnt a problem bth.  N -> 1 90 180
Isaac> 270 1 N/4 -> 1 2 3 4 keep Q discard discard

What you are looking for is the down-sampled analytical signal. The
analytical signal relates to the Hilbert transform as you describe
in 3. :-) That people tell you to perform the Hilbert Transform to get
the so-called analytic signal is wrong, and maybe MATLAB is partly to
blame for this since hilbert() calculates the analytic signal and not
the Hilbert transform. Having calculated the analytic signal as
x_a(n)=x_r(n)+j*H(x_r(n)) with H() being the Hilbert Transform and
x_r(n) your original real input, you just need to downsample x_a(n) by
a factor of 2, i.e. discard every other sample. For more details, have
a look at

S. L. Marple Jr., "Computing the discrete-time "Analytic" signal via
FFT," IEEE Trans. Signal Processing, vol. 47, pp. 2600 - 2603,
September 1999.

--
```
```"Isaac Gerg" <isaacgerg@psu.edu> wrote in message
news:cjjjla\$vhm\$1@f04n12.cac.psu.edu...
> Hi all,
>    I have a need to sample audio from my sound card and process it.
> However, the hardware I am processing it on works faster in complex domain
> than real domain.  I know this may sound funny, but it is true. Read on...
>
> In essence, I need to convert a real stream sampled at N to a complex
> stream sampled at N/2.  Not sure what the best way to do this is or if it
> can even be done.
>
> Here are the ways I have been told by others to accomplish this.  Are
> these correct?
>
> 1. To keep the N samp rate.. i can have two sensors, both sampling at N
> but one sensore 90 degrees out of phase when sampling.  I believe this is
> the best way to get complex data, but dont have the capabilities to do
> this in my system.
>
> 2. Sample at N and get a stream of reals.  Perform the Hilbert Transform
> to get N/2 complex samples.  Not sure of what a Hilbert transform does...I
> though it takes your signal and makes it 90 degrees out of phase.. this
> brings me to the third solution.
>
> 3. Sample reals at N.  Perform Hilbert transform to shift wave by 90
> degree.... Mix hilbert transform with reals to get a samp freq of N. Looks
> like this output = reals + j*Hilbert_XForm
>
> 4.  Sample reals at N.  Then, make every 4 samples the real part (position
> 1)... and the samples at positions 2 the complex part.. thus those are 90
> degees of the sampling frequency N/4.  Discard parts 3 and 4 of the N
> samples.  This has me downsampling to N/4 which isnt a problem bth.
> N   -> 1    90    180  270   1
> N/4 -> 1     2     3    4

I think you want to do quadrature sampling.  As I recall, there's a neat
trick regarding how to do this.  It's described in Rick Lyon's book on DSP.

What I remember is that the sampling in essence generates "I" samples on
every other sample and "Q" samples on every other sample.  Then maybe you
consider these to be samples of the analytic signal (complex).

Better read about it than listen further to me!

Fred

```
```So, you are saying that my number 3 is the correct means to proceed?

Would you please comment on Fred Marshalls comment?

Thanks for the help!

Mads G. Christensen wrote:

> Hi Isaac.
>
> Isaac> Hi all, I have a need to sample audio from my sound card and
> Isaac> process it. However, the hardware I am processing it on works
> Isaac> faster in complex domain than real domain.  I know this may
> Isaac> sound funny, but it is true. Read on...
>
> Isaac> In essence, I need to convert a real stream sampled at N to a
> Isaac> complex stream sampled at N/2.  Not sure what the best way to
> Isaac> do this is or if it can even be done.
>
> Isaac> Here are the ways I have been told by others to accomplish
> Isaac> this.  Are these correct?
>
> Isaac> 1. To keep the N samp rate.. i can have two sensors, both
> Isaac> sampling at N but one sensore 90 degrees out of phase when
> Isaac> sampling.  I believe this is the best way to get complex data,
> Isaac> but dont have the capabilities to do this in my system.
>
> Isaac> 2. Sample at N and get a stream of reals.  Perform the Hilbert
> Isaac> Transform to get N/2 complex samples.  Not sure of what a
> Isaac> Hilbert transform does...I though it takes your signal and
> Isaac> makes it 90 degrees out of phase.. this brings me to the third
> Isaac> solution.
>
> Isaac> 3. Sample reals at N.  Perform Hilbert transform to shift wave
> Isaac> by 90 degree.... Mix hilbert transform with reals to get a samp
> Isaac> freq of N. Looks like this output = reals + j*Hilbert_XForm
>
> Isaac> 4.  Sample reals at N.  Then, make every 4 samples the real
> Isaac> part (position 1)... and the samples at positions 2 the complex
> Isaac> part.. thus those are 90 degees of the sampling frequency N/4.
> Isaac> Discard parts 3 and 4 of the N samples.  This has me
> Isaac> downsampling to N/4 which isnt a problem bth.  N -> 1 90 180
> Isaac> 270 1 N/4 -> 1 2 3 4 keep Q discard discard
>
> What you are looking for is the down-sampled analytical signal. The
> analytical signal relates to the Hilbert transform as you describe
> in 3. :-) That people tell you to perform the Hilbert Transform to get
> the so-called analytic signal is wrong, and maybe MATLAB is partly to
> blame for this since hilbert() calculates the analytic signal and not
> the Hilbert transform. Having calculated the analytic signal as
> x_a(n)=x_r(n)+j*H(x_r(n)) with H() being the Hilbert Transform and
> x_r(n) your original real input, you just need to downsample x_a(n) by
> a factor of 2, i.e. discard every other sample. For more details, have
> a look at
>
> S. L. Marple Jr., "Computing the discrete-time "Analytic" signal via
> FFT," IEEE Trans. Signal Processing, vol. 47, pp. 2600 - 2603,
> September 1999.
>
```
```Hi Isaac.

Isaac> So, you are saying that my number 3 is the correct means to
Isaac> proceed?  Would you please comment on Fred Marshalls comment?

Yes, your number 3 is the way to do it. And you need to do
downsampling by a factor of 2, i.e. drop every other sample. Usually,
you would have to filter before the downsampling, but in this case,
the spectrum is already half the bandwidth, so you don't need to in
this case.

Fred is probably saying the same thing I am, but using a different
terminology. The I and Q terminology is often used in
telecommunication, I think...

--
```
```I don't think you need to change your sampling scheme at all.
I think you just want to use the common trick of getting a N real FFT using
a N/2 complex FFT.

"Fred Marshall" <fmarshallx@remove_the_x.acm.org> wrote in message
news:2KydnZfpSfJAAsDcRVn-sw@centurytel.net...
>
> "Isaac Gerg" <isaacgerg@psu.edu> wrote in message
> news:cjjjla\$vhm\$1@f04n12.cac.psu.edu...
>> Hi all,
>>    I have a need to sample audio from my sound card and process it.
>> However, the hardware I am processing it on works faster in complex
>> domain than real domain.  I know this may sound funny, but it is true.
>>
>> In essence, I need to convert a real stream sampled at N to a complex
>> stream sampled at N/2.  Not sure what the best way to do this is or if it
>> can even be done.
>>
>> Here are the ways I have been told by others to accomplish this.  Are
>> these correct?
>>
>> 1. To keep the N samp rate.. i can have two sensors, both sampling at N
>> but one sensore 90 degrees out of phase when sampling.  I believe this is
>> the best way to get complex data, but dont have the capabilities to do
>> this in my system.
>>
>> 2. Sample at N and get a stream of reals.  Perform the Hilbert Transform
>> to get N/2 complex samples.  Not sure of what a Hilbert transform
>> does...I though it takes your signal and makes it 90 degrees out of
>> phase.. this brings me to the third solution.
>>
>> 3. Sample reals at N.  Perform Hilbert transform to shift wave by 90
>> degree.... Mix hilbert transform with reals to get a samp freq of N.
>> Looks like this output = reals + j*Hilbert_XForm
>>
>> 4.  Sample reals at N.  Then, make every 4 samples the real part
>> (position 1)... and the samples at positions 2 the complex part.. thus
>> those are 90 degees of the sampling frequency N/4.  Discard parts 3 and 4
>> of the N samples.  This has me downsampling to N/4 which isnt a problem
>> bth.
>> N   -> 1    90    180  270   1
>> N/4 -> 1     2     3    4
>
> I think you want to do quadrature sampling.  As I recall, there's a neat
> trick regarding how to do this.  It's described in Rick Lyon's book on
> DSP.
>
> What I remember is that the sampling in essence generates "I" samples on
> every other sample and "Q" samples on every other sample.  Then maybe you
> consider these to be samples of the analytic signal (complex).
>
> Better read about it than listen further to me!
>
> Fred
>

```
```Hi.

Jerry> I don't think you need to change your sampling scheme at all.
Jerry> I think you just want to use the common trick of getting a N
Jerry> real FFT using a N/2 complex FFT.

That depends on what he's trying to do. If he's just calculating the
periodogram, then you are right. But I think he's trying to speed up
some other processing by applying the down-sampled analytic signal.

--
```
```You are correct in your assumption.

Mads G. Christensen wrote:
> Hi.
>
> Jerry> I don't think you need to change your sampling scheme at all.
> Jerry> I think you just want to use the common trick of getting a N
> Jerry> real FFT using a N/2 complex FFT.
>
> That depends on what he's trying to do. If he's just calculating the
> periodogram, then you are right. But I think he's trying to speed up
> some other processing by applying the down-sampled analytic signal.
>
```
```Your assumption is correct.

Mads G. Christensen wrote:

> Hi.
>
> Jerry> I don't think you need to change your sampling scheme at all.
> Jerry> I think you just want to use the common trick of getting a N
> Jerry> real FFT using a N/2 complex FFT.
>
> That depends on what he's trying to do. If he's just calculating the
> periodogram, then you are right. But I think he's trying to speed up
> some other processing by applying the down-sampled analytic signal.
>
```