# Expressing delay of sequence on Matlab

#### tquiva

Joined Oct 19, 2010
176
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?

#### t_n_k

Joined Mar 6, 2009
5,455
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.

#### tquiva

Joined Oct 19, 2010
176
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:

Rich (BB code):
star=-15:0.01:15;
ife(star)=a*exp(i*2*pi*f*star(x));
Should I start by finding the value of a for a unit energy?

#### t_n_k

Joined Mar 6, 2009
5,455
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".

#### tquiva

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

Rich (BB code):
% Imaginary frequency sequence

% a=complex phasor, f=real frequency

f=1/2; n=1000; star=-5:5; dt=0.1; t=-5:dt:5;
ife=a*exp(i*2*pi*f*star);

% (a)

% Another imaginary frequency exponential
ife2=b*exp(i*2*pi*f*star);

% (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: 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:

Rich (BB code):
syms f star n;
% Given ife
ife=exp(i*2*pi*f*star);

% (a)

% Another ife
ife2=exp(i*4*pi*f*star);

% Energy of ife
E_ife=int(ife.^2,star,0,n);

a=(sum(ife*ife2))/sqrt(E_ife); pretty(a)

Last edited:

#### t_n_k

Joined Mar 6, 2009
5,455
Rich (BB code):
%This sequence has 3600 samples
N=3600;
%star array
star=[1:N];
%frequency is 4 - choose a value
f=4;
%The shift is 100 - choose a number
N_shift=100;
%Some complex amplitude
A=(1+i)/sqrt(2);
%The un-shifted original
T=A*exp(i*2*pi*f*star/N);
%The shifted sequence
S=A*exp(i*2*pi*f*(star+N_shift)/N);
% plot to check
plot(T);
plot(S);
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)

#### tquiva

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

Rich (BB code):
% (a) In terms of another ife
n=3600; star=1:0.01:n; f=1/4; n_shift=100;
a=(1+i)/sqrt(2);    % Phasor

% Unshifted original ife
ife=a*exp(i*2*pi*f*star/n);

% Shifted sequence
ife2=a*exp(i*2*pi*f*(star+n_shift)/n);

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: 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:

Rich (BB code):
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?

#### t_n_k

Joined Mar 6, 2009
5,455
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].

#### tquiva

Joined Oct 19, 2010
176
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.

#### t_n_k

Joined Mar 6, 2009
5,455
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).

#### roboticist

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

you need to use .* to multiply the elements of two matrices

• tquiva

#### t_n_k

Joined Mar 6, 2009
5,455
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 [*]=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) would be the same as S1 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:
• tquiva