DSPRelated.com
Forums

generating I & Q

Started by Unknown March 11, 2005
How do I generate the I(n) & Q(n) values from an X(n) value.  The X(n)
are the input data between -1 and 1.  The variables are related using
X(n) = I(n) + j*Q(n).  I need these values to calculate the
instantaneous frequency using freq = Fs * delta(atan(q/i)) / 2*pi.

Thanks,

In = Xn*cos(theta)
Qn=Xn*sin(theta)

"Neo" <zingafriend@yahoo.com> wrote in message 
news:1110524418.550458.275210@g14g2000cwa.googlegroups.com...
> In = Xn*cos(theta) > Qn=Xn*sin(theta) >
and theta = n*2*pi/fs + some arbitrary constant if you like. Best of luck - Mike
<george_barr@yahoo.com> wrote in message
news:1110516798.705729.115930@o13g2000cwo.googlegroups.com...
> How do I generate the I(n) & Q(n) values from an X(n) value. The X(n) > are the input data between -1 and 1. The variables are related using > X(n) = I(n) + j*Q(n). I need these values to calculate the > instantaneous frequency using freq = Fs * delta(atan(q/i)) / 2*pi. > > Thanks, >
If you samples are indeed real, try using the HILBERT function to convert is to an anlytic signal, so you can use the ANGLE function on the complex samples. -Aj
Neo wrote:
> In = Xn*cos(theta) > Qn=Xn*sin(theta)
Ah so! How should George find theta? Atan(Q/I)? Jerry -- Engineering is the art of making what you want from things you can get. &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;
in article 3cmdnVQNj5o0RKzfRVn-tg@rcn.net, Jerry Avins at jya@ieee.org wrote
on 03/11/2005 12:47:

> Neo wrote: >> In = Xn*cos(theta) >> Qn=Xn*sin(theta) > > Ah so! How should George find theta? Atan(Q/I)?
which is good for I > 0. strictly speaking it's arg{I + j*Q} or atan2(Q, I) if your computer has that one. -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."
I am still having trouble creating my Matlab m-file.  I am trying to
find the instantaneous FM frequency of a signal for the purpose of FM
demodulation.  I tried atan() and atan2() without successful results.
Here is my m-file.  If the program below works, it should print out the
Fi or 200Hz.  Can someone help me with this?

function result = fm_iq04
    format long;
    Fs = 1000;       % Number of samples
    Fc = 250;        % center freq
    Fi = 200;        % Frequency of interest
    Ts = 1 / Fs;
    t = Ts*(0:Fs-1)';
    x = cos(2*pi*Fi*t);


    cur_a = 0;
    last_a = 0;
    for i = 1:length(x) - 1
        theta = (i * 2 * pi) / Fs;
        cur_i = x(i) * cos(theta);
        cur_q = x(i) * sin(theta);
        cur_a = atan2(cur_q, cur_i);

        % cur_a = atan(cur_q / cur_i);

        freq = (Fs * (cur_a - last_a)) / 2 * pi;

        % display the instantaneous frequency
        disp(freq);
        
        last_a = cur_a;
    end

Thanks,

I figured it out.  I can use the hilbert() matlab function to convert a
real signal into a complex signal.  Here is the m-file to compute the
instantaneous frequency and it seems to work.

function result = fm_iq09
    format long;
    Fs = 5000;       % Number of samples
    Fc = 1250;        % center freq
    Fi = 1570;        % Frequency of interest
    Ts = 1 / Fs;
    t = Ts*(0:Fs-1)';
    x = cos(2*pi*Fi*t);
    x = hilbert(x);

    cur_a = 0;
    last_a = 0;
    for i = 1:length(x) - 1
        cur_i = real(x(i));
        cur_q = imag(x(i));

        cur_a = atan(cur_q / cur_i);
        freq = (Fs * (cur_a - last_a)) / 2 * pi / 10;


        error = (Fi / freq) - 1;
        if freq > 0
           disp(freq);
           disp(error);
        end
        
        last_a = cur_a;
    end

in article 1110613336.330448.148760@f14g2000cwb.googlegroups.com,
george_barr@yahoo.com at george_barr@yahoo.com wrote on 03/12/2005 02:42:

> I figured it out. I can use the hilbert() matlab function to convert a > real signal into a complex signal. Here is the m-file to compute the > instantaneous frequency and it seems to work.
i think you still have phase unwrapping issues to work out. if you don't want to explicitly unwrap your phase angle, perhaps you want to compute your phase difference with a trig identity that i can't remember. it's for arctan(q[n]/i[n]) - arctan(q[n-1]/i[n-1]) = something if you find that identity and use it for phase difference (which is proportional to frequency), you won't have to worry about unwrapping. -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."
This is a multi-part message in MIME format.
--------------000706080404020207000004
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit

robert bristow-johnson wrote:

>in article 1110613336.330448.148760@f14g2000cwb.googlegroups.com, >george_barr@yahoo.com at george_barr@yahoo.com wrote on 03/12/2005 02:42: > > > >>I figured it out. I can use the hilbert() matlab function to convert a >>real signal into a complex signal. Here is the m-file to compute the >>instantaneous frequency and it seems to work. >> >> > >i think you still have phase unwrapping issues to work out. if you don't >want to explicitly unwrap your phase angle, perhaps you want to compute your >phase difference with a trig identity that i can't remember. it's for > > arctan(q[n]/i[n]) - arctan(q[n-1]/i[n-1]) = something > >if you find that identity and use it for phase difference (which is >proportional to frequency), you won't have to worry about unwrapping. > > >
in Matlab following formula works also (signal must be complex): freq = Fs/2/pi * diff( unwrap (imag (log (signal)))); Ren&#4294967295; --------------000706080404020207000004 Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: 7bit <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"> <title></title> </head> <body text="#000000" bgcolor="#ffffff"> robert bristow-johnson wrote:<br> <blockquote type="cite" cite="midBE58DB51.5343%25rbj@audioimagination.com"> <pre wrap="">in article <a class="moz-txt-link-abbreviated" href="mailto:1110613336.330448.148760@f14g2000cwb.googlegroups.com">1110613336.330448.148760@f14g2000cwb.googlegroups.com</a>, <a class="moz-txt-link-abbreviated" href="mailto:george_barr@yahoo.com">george_barr@yahoo.com</a> at <a class="moz-txt-link-abbreviated" href="mailto:george_barr@yahoo.com">george_barr@yahoo.com</a> wrote on 03/12/2005 02:42: </pre> <blockquote type="cite"> <pre wrap="">I figured it out. I can use the hilbert() matlab function to convert a real signal into a complex signal. Here is the m-file to compute the instantaneous frequency and it seems to work. </pre> </blockquote> <pre wrap=""><!----> i think you still have phase unwrapping issues to work out. if you don't want to explicitly unwrap your phase angle, perhaps you want to compute your phase difference with a trig identity that i can't remember. it's for arctan(q[n]/i[n]) - arctan(q[n-1]/i[n-1]) = something if you find that identity and use it for phase difference (which is proportional to frequency), you won't have to worry about unwrapping. </pre> </blockquote> <tt>in Matlab following formula works also (signal must be complex):<br> <br> freq = Fs/2/pi * diff( unwrap (imag (log (signal))));<br> <br> Ren&eacute;<br> </tt> </body> </html> --------------000706080404020207000004--