Expressing delay of sequence on Matlab

Discussion in 'Homework Help' started by tquiva, Aug 31, 2011.

  1. tquiva

    Thread Starter Member

    Oct 19, 2010
    176
    1
    I'm currently having trouble with this problem. I'm not exactly sure how to start it or what it means by expressing the delay in terms of n. I have the problem attached, but could someone please assist me with a good approach to this?
     
  2. t_n_k

    AAC Fanatic!

    Mar 6, 2009
    5,448
    782
    It might be informative to investigate the Discrete Fourier Transform (DFT) properties and the DFT inverse transform properties - such as the effect of time shifting on the frequency sequence.
     
  3. tquiva

    Thread Starter Member

    Oct 19, 2010
    176
    1
    what would the pseudocode be in order to do so?

    This is my first time working with a problem like this, so it's still new to me.

    so far, on Matlab, I have something like:

    Code ( (Unknown Language)):
    1. star=-15:0.01:15;
    2. ife(star)=a*exp(i*2*pi*f*star(x));
    Should I start by finding the value of a for a unit energy?
     
  4. t_n_k

    AAC Fanatic!

    Mar 6, 2009
    5,448
    782
    Since this is an unfamiliar exercise for you then it begs the question - what are you being taught in class?

    If you gave some context to the problem with respect to the subject area you are studying it might be of help in assisting you with the problem.

    My previous comments regarding DFT may or may not be relevant, so trying to come up with Matlab code before you clearly understand the problem and the likely method of solution, is like "putting the cart before the horse".
     
  5. tquiva

    Thread Starter Member

    Oct 19, 2010
    176
    1
    I applied what I learned from class, and here's my updated script:

    Code ( (Unknown Language)):
    1. % Imaginary frequency sequence
    2.  
    3. % a=complex phasor, f=real frequency
    4.  
    5. f=1/2; n=1000; star=-5:5; dt=0.1; t=-5:dt:5;
    6. ife=a*exp(i*2*pi*f*star);
    7.  
    8. % (a)
    9.  
    10. % Another imaginary frequency exponential
    11. ife2=b*exp(i*2*pi*f*star);
    12.  
    13. % (b)
    I defined a second imaginary frequency exponential. Now for part b, I would multiply both ife and ife2 and obtain the summation of both? Or am I mistaken?

    Part (a) I am still lost. I tried integrating ife to obtain the energy, setting it at 1, then solving for a. I get a "false" answer afterward. Did I take a wrong apprach?


    **** EDIT: I redid (a) with a different approach:

    [​IMG]

    So first, the system would look like the very first line of the picture.
    Then I need to find a. But in order to do so, I need the energy of ife and I do so with the integral on the last line.

    Am I correct with this?

    Here's my redone code:

    Code ( (Unknown Language)):
    1. syms f star n;
    2. % Given ife
    3. ife=exp(i*2*pi*f*star);
    4.  
    5. % (a)
    6.  
    7. % Another ife
    8. ife2=exp(i*4*pi*f*star);
    9.  
    10. % Energy of ife
    11. E_ife=int(ife.^2,star,0,n);
    12.  
    13. a=(sum(ife*ife2))/sqrt(E_ife); pretty(a)
    14.  
     
    Last edited: Sep 1, 2011
  6. t_n_k

    AAC Fanatic!

    Mar 6, 2009
    5,448
    782
    Code ( (Unknown Language)):
    1.  
    2. %This sequence has 3600 samples
    3. N=3600;
    4. %star array
    5. star=[1:N];
    6. %frequency is 4 - choose a value
    7. f=4;
    8. %The shift is 100 - choose a number
    9. N_shift=100;                                  
    10. %Some complex amplitude
    11. A=(1+i)/sqrt(2);                              
    12. %The un-shifted original
    13. T=A*exp(i*2*pi*f*star/N);                
    14. %The shifted sequence
    15. S=A*exp(i*2*pi*f*(star+N_shift)/N);  
    16. % plot to check
    17. plot(T);                                      
    18. plot(S);
    19.  
    The code sample shows how a specified shift might possibly be implemented. Not sure how high the shift value can be in this case.

    You can possibly see how the original frequency is modified by the factor (1+N_shift/star)
     
  7. tquiva

    Thread Starter Member

    Oct 19, 2010
    176
    1
    Here's my modified code:

    Code ( (Unknown Language)):
    1. % (a) In terms of another ife
    2. n=3600; star=1:0.01:n; f=1/4; n_shift=100;
    3. a=(1+i)/sqrt(2);    % Phasor
    4.  
    5. % Unshifted original ife
    6. ife=a*exp(i*2*pi*f*star/n);
    7.  
    8. % Shifted sequence
    9. ife2=a*exp(i*2*pi*f*(star+n_shift)/n);
    10.  
    11. plot3(star,real(ife),imag(ife),star,real(ife2),imag(ife2),'o')
    I know my graph is supposed to look like a twisted piece of wire, but I only get an arc:

    [​IMG]

    My assignment is due tomorrow, so I'll return to this one afterwards.

    For part (b), I am asked to find the weight sum of two imaginary frequency exponentials as a single imaginary frequency. I did this by the following code:

    Code ( (Unknown Language)):
    1. sum(ife*ife2);
    And no I am received an error:

    ??? Error using ==> mtimes
    Inner matrix dimensions must agree.

    The same happens with part (c). I'm not exactly sure what's wrong here. I don't think I'd have to modify anything, but just work off of my code from part (a). Or did I miss something?
     
    • 3a.jpg
      3a.jpg
      File size:
      14.4 KB
      Views:
      175
  8. t_n_k

    AAC Fanatic!

    Mar 6, 2009
    5,448
    782
    Your "star" and "f" values are different to mine.

    I have star as a one dimensional integer array from 1 to 3600 [increments of 1].

    I have frequency f as 4 (not 1/4 as you have).

    I've attached the graph I received from my [Scilab] code with N_shift=100. The 100 element shift translates to an apparent phase shift of 40°.

    For clarity I've only plotted the real parts of the complex sequences T [original sequence] & S[shifted sequence].
     
  9. tquiva

    Thread Starter Member

    Oct 19, 2010
    176
    1
    Thank you!

    Now for parts (b) and (c), would I have to modify my code from part (a)? I can't seem to get the summation nor product of both ife's.
     
  10. t_n_k

    AAC Fanatic!

    Mar 6, 2009
    5,448
    782
    You need to put some thought into the problem for a while. I can't give you "the works" otherwise you obtain credit which isn't a fair comparison with your classmates.

    On part (b) - As a starting point for thinking - What happens if you add two identical sequences together? What changes & what doesn't? What if you weight one sequence more highly than the other? Then extend that thinking to two different sequences such as the original and shifted sequences proposed in part (a).
     
  11. roboticist

    New Member

    Feb 11, 2011
    1
    1
    sum(ife.*ife2); should work

    you need to use .* to multiply the elements of two matrices
     
    tquiva likes this.
  12. t_n_k

    AAC Fanatic!

    Mar 6, 2009
    5,448
    782
    Not sure if any further comments on this problem are relevant but it may be worth noting a few things. I'll limit the comment to part (a) - see post #1.

    The question proposes a sequence

    ife<br />
[*]=aexp[i2\pi f *]

    and then asks what would be the effect of a n element shift of a second similar sequence ife[*-n]

    Suppose we call the original sequence S1 and the shifted sequence S2.

    If n=5 say, then the 10th element of S2 (S2[10]) would be the same as S1[5] and so on.

    The question then asks how in general terms the expression for S1 & S2 would be related. Specifically how would the frequency term 'f' &/or complex phasor 'a' term be adjusted in transforming S1 into S2?

    My take on this is that there could be many solutions.

    Another perspective of the n element shift is to also think of it as a phase shift.

    Keeping in mind the discrete nature of the sequence we can temporarily apply a continuous time analogy to the problem as follows

    Consider a continuous time function Y=aexp(iωt) where a=p+iq is a complex phasor of magnitude m. The ω is the angular frequency.

    We can also write a=mexp(iθ) where θ=arctan(q/p)

    So we can also recast Y as Y=mexp(iθ)exp(iωt)=mexp(i[ωt+θ])

    Suppose we apply a phase shift ψ to the function Y to create another shifted function Z where

    Z=Yexp(iψ)=mexp(i[ωt+θ])exp(iψ)=mexp(i[ωt+θ+ψ])

    But we can re-cast Z another way by remembering that exp(iψ)=cos(ψ)+isin(ψ)

    which is a complex phasor.

    So we could equally well write that

    Z={cos(ψ)+isin(ψ)}mexp(i[ωt+θ])

    or even

    Z={cos(ψ)+isin(ψ)}aexp(iωt)=bexp(iωt)

    where b is another complex phasor. In the continuous case the possibilities are limitless for re-casting the shifted function.

    Returning to the discrete situation of S2 the possibilities are not limitless but there will be more than one in any event. A shift of n=1 gives rise to two possible valid expressions for S1 in terms of a new phasor and /or 'frequency' term. The re-cast frequency term isn't really a new 'frequency' [as the original question might seem to imply] since only the original frequency 'f' is a multiple of the * value of any sequence term. A shift of n=10 gives rise to 11 possible expressions. And so on ...

    However, my guess is that the consistent answer for part (a) would probably be

    ife[*-n]=bexp[i 2 \pi f *]

    where

    b=aexp(-i 2 \pi f n)

    So only the complex phasor term would be different.
     
    Last edited: Sep 4, 2011
    tquiva likes this.
Loading...