MatLab Help on Defining New Signals

Discussion in 'Programmer's Corner' started by tquiva, Jan 17, 2011.

  1. tquiva

    Thread Starter Member

    Oct 19, 2010
    176
    1
    I'm entirely new to MatLab, and I have no idea how to go about doing this problem.

    Problem:
    Consider the complex exponential signal x(t) =X*exp*(s_x*t) with the phasor X and the complex frequency s_x. Define the new signals:

    a(t) = 2*x^3(t)
    b(t) = 4/x(t)
    c(t) = conj(x(t))
    d(t) = 2*a(t) + 6*b(t)
    f(t) = (d^2*x(t)) / dt^2
    g(t) = d(t) + 5*f(t)

    (a) Use numerical Matlab plots to investigate each of the above new signals; determine the signals that appear to be complex exponentials.



    I've watched some of the demos on MatLab and read the manual, and I am quite unsure of my chosen approach to this. I would first create a new script or .m file defining these functions? And then enter them into the command window??

    Could someone advanced with MatLab please give me just one example how to begin this problem?
     
  2. Georacer

    Moderator

    Nov 25, 2009
    5,142
    1,266
    I don't see any way to do this without passing a test value on the variables X and s_x. Would that be ok with you?
     
  3. tquiva

    Thread Starter Member

    Oct 19, 2010
    176
    1
    I don't mind trying your suggestion, but what do you mean by test value?
    Could you please give me an example?
     
  4. Georacer

    Moderator

    Nov 25, 2009
    5,142
    1,266
    If your Matlab package includes the symbolic math library, you could type:
    Code ( (Unknown Language)):
    1.  
    2. syms x t
    3. x=exp(t) \\assume that X and x_s are 1
    4. ezplot(x,[-5,5]) \\ispect the plot of x
    5.  
    6. syms a
    7. a=2*x^3
    8. ezplot(a)
    9. \\and so on
    10.  
    If the first command (syms) pops an error that means you don't have the library and we 'll have to go around it. Tell me if this is the case and we 'll try something else.
     
  5. tquiva

    Thread Starter Member

    Oct 19, 2010
    176
    1
    For the first part:


    Code ( (Unknown Language)):
    1. EDU>> syms x t
    2. x=exp(t) \\assume that X and x_s are 1
    3. ezplot(x,[-5,5]) \\ispect the plot of x
    4. ??? x=exp(t) \\assume that X and x_s are 1
    5.               |
    6. Error: Unexpected MATLAB operator.
    And the second part:

    Code ( (Unknown Language)):
    1. EDU>> syms a
    2. a=2*x^3
    3. ezplot(a)
    4. \\and so on
    5.  
    6. a =
    7.  
    8. 2*x^3
    9.  
    10. ??? \\and so on
    11.     |
    12. Error: Unexpected MATLAB operator.
    Is that what I am supposed to get?
     
  6. Georacer

    Moderator

    Nov 25, 2009
    5,142
    1,266
    Just remove the "\\" along with the content after it in the same line.
    I used it to tell you that this is a comment, but Matlab actually uses the ";" sign to do it.
     
  7. tquiva

    Thread Starter Member

    Oct 19, 2010
    176
    1
    alright, so once I have these test values for x and s_x,
    how woudl I go about declaring the functions (signals)...
    such as a(t) = 2*x^3(t) ?

    Do I just type in 'function' in the MatLab command window?
     
  8. Georacer

    Moderator

    Nov 25, 2009
    5,142
    1,266
    I 'll retype the code you have to write in order to build the functions:
    Code ( (Unknown Language)):
    1. syms x t a b c d f g
    2. x=exp(t)
    3. a=2*x^3
    4. b=4/x
    5.  
    and so on, until you declare all your symbolic functions.
    You can group all that in an .m file.

    Afterwards, if you want to inspect a function, you can do so by typing
    Code ( (Unknown Language)):
    1.  
    2. ezplot(f,[xmin, xmax])
    3.  
    where f is the desired function and xmin and xmax the graph limits.
     
  9. Georacer

    Moderator

    Nov 25, 2009
    5,142
    1,266
    You can use the command
    Code ( (Unknown Language)):
    1.  
    2. diff(f,n)
    3.  
    to differentiate the function f n times.

    Do the graphs seem ok to you? Does the complex exponentials part of the question seem ok?
    Tell us what you think.

    The other way to generate the functions would be to create a long time table, say, from -100 to 100, maybe with more than a unit of accuracy, and apply all the above functions element-wise with the arrayfun command. That takes more time and requires you to pick a correct time table and amount of precision.

    Remember: Matlab built-in help is an invaluable help.
     
    Last edited: Jan 18, 2011
  10. tquiva

    Thread Starter Member

    Oct 19, 2010
    176
    1
    Thank you very much. I think I've got that part down now. So for a), how would I go about determining the signals (functions) that appear to be complex exponentials with the MatLab numerical plots?
     
  11. Georacer

    Moderator

    Nov 25, 2009
    5,142
    1,266
    The signals would be complex exponentials if the power of e was a complex number. However we assumed that s_x was a real number. You can substitute s_x for a complex number, i.e. 1+1j and run the simulations again. This time most of the signals will be complex exponentials.

    A complex exponential resembles a sine wave when plotted. More info on how your professor wants to solve the exercise would be helpful.
     
  12. tquiva

    Thread Starter Member

    Oct 19, 2010
    176
    1
    In the code example that you gave me, why didn't you include the capital X in the equation x(t) ?
     
  13. tquiva

    Thread Starter Member

    Oct 19, 2010
    176
    1
    So I tried this:

    Code ( (Unknown Language)):
    1. EDU>> syms x t a b c d f g
    2. EDU>> s=1+1j;
    3. EDU>> x=exp(s*t);
    4. EDU>> a=2*x^3;
    5. EDU>> b=4/x;
    6. EDU>> c=conj(x);
    7. EDU>> d=2*a+6*b;
    8. EDU>> f=diff(x,2);
    9. EDU>> g=d+5*f;
    Then I tried to graph a, but I got an error:

    Code ( (Unknown Language)):
    1. EDU>> ezplot(a,[-10, 10])
    2. Warning: Cannot plot 2*exp(t*(3*i + 3)):  This function has no real values.
    3. > In ezplot>ezplot1 at 471
    4.   In ezplot at 144
    5.   In sym.ezplot at 56
    6. Error in ==> ezplot>ezplot1 at 420
    7. error(nargchk(4,6,nargin,'struct'));
    8.  
    9. ??? Output argument "hp" (and maybe others) not assigned during call to
    10. "/Applications/MATLAB_R2010aSV.app/toolbox/matlab/specgraph/ezplot.m>ezplot1".
    11.  
    12. Error in ==> ezplot at 144
    13.     [hp,cax] = ezplot1(cax,f{1},vars,labels,args{:});
    14.  
    15. Error in ==> sym.ezplot at 56
    16.       h = ezplot(char(f),varargin{:});
    What correction do I need to make?

    I noticed that if I remove the complex number s, then the plotting actually works.

    When I put this into the command window:
    Code ( (Unknown Language)):
    1. ezplot(a,[-10, 10])
    I receive this graph:
    [​IMG]

    Is this correct? And how would I be able to tell if the function is a complex exponential?
     
    Last edited: Jan 20, 2011
  14. tquiva

    Thread Starter Member

    Oct 19, 2010
    176
    1
    For the second part of the problem, it says:

    (b) For each signal that appears to be a complex exponential, use symbolic Matlab to relate the phasor and complex frequency of the new complex exponential to those of x(t).

    What exactly is 'symbolic Matlab' and how would I use it to relate X and s_x (phasor and complex frequency) ?
     
  15. Georacer

    Moderator

    Nov 25, 2009
    5,142
    1,266
    You cannot plot a complex number as a function of time in a 2-D plot. It just doesn't make sense. Instead use this to approach the result from its real and imaginary part
    Code ( (Unknown Language)):
    1.  
    2. syms t
    3. s=(1+i)
    4. x=exp(s*t)
    5. ezplot(real(x))
    6.  
    The imaginary part will give you a similar waveform with an offset of 90 degrees. The fact that instead of a simple exponential, you get a wavy line, betrays the fact that you have a complex exponential at your hands. A complex exponential is given by the expression
    f(t)=e^{(x+yi) \cdot t}=e^{x \cdot t} \cdot e^{i \cdot (y \cdot t)}
    If y is greater that zero, you will end with a sine wave with increasing magnitude. It will still cross the x-axis twice in every period.

    You can revise that by adding
    Code ( (Unknown Language)):
    1.  
    2. temp=axis
    3. axis([temp(1), temp(2), -1, 1])
    4.  
    to your code, thus zooming in the y-axis.

    For the second part:
    From what I understand, you have to compare the phasor and frequency magnitudes of the functions in respect to the ones of x.
    In other words if x=e^{(x+yi) \cdot t} and y=con \cdot e^{(a+bi) \cdot t}, the phasor ratio is \frac{con \cdot e^{a \cdot t}}{e^{x \cdot t}}=con \cdot e^{(a-x) \cdot t} (not constant).
    The frequency ratio is  \frac by and this is constant.

    Is that clear?
     
Loading...