# Step functions - subtraction

Discussion in 'Homework Help' started by mickonk, Apr 6, 2015.

1. ### mickonk Thread Starter New Member

Apr 6, 2015
13
0
Here are two step functions:

Here is u(n+N)-u(n-N-1):

Can someone explain me way that these functions are subtracted?

2. ### Papabravo Expert

Feb 24, 2006
10,340
1,850
The first thing I would try would be the graphical method.

3. ### WBahn Moderator

Mar 31, 2012
18,087
4,917
Doing an example graphically like Papabravo recommends in a very good place to start. That will let you see how the two are interacting.

Once you've done that, you should be able to do it analytically by identifying the relevant regions for each function and then figuring out what the difference is within each region.

Once you've done that, you might consider whether everything still works nicely if N<0.

4. ### mickonk Thread Starter New Member

Apr 6, 2015
13
0
I sketched them but it doesn't help me a lot:

5. ### WBahn Moderator

Mar 31, 2012
18,087
4,917
Well, what do you get if you subtract the second one from the first one?

Don't forget that you are working with a discrete function that is not defined, for instance, between N and (N+1), but rather AT N and AT (N+1)

6. ### Papabravo Expert

Feb 24, 2006
10,340
1,850
∀N > 0
I agree with the first picture for n < -N.
For the second picture it looks correct, and the result of the subtraction looks like it should be 1, for -N ≤ n ≤ N+1
You should be able to rewrite:
u(n-N-1) as u(n - (N+1)) which is consistent with your picture.​
For N = 0 you get the expected result.

7. ### Papabravo Expert

Feb 24, 2006
10,340
1,850
I don't think these are discrete functions. The value of n can be any real number -- right? Step functions have always been defined on [-∞,∞].
If they are discrete functions then it is improper to call them step functions and the restriction on 'n' should have been explicit. as in n ∈ ℤ, the set of all integers.

Last edited: Apr 6, 2015
8. ### WBahn Moderator

Mar 31, 2012
18,087
4,917
It's hard to tell.

Usually the use of 'n' as the independent variable implies a discrete function.

But, technically, discrete functions (traditionally, but it may well vary where the TS is from) use [] instead of () for the domain variable, hence

y(x) would be continuous but y[x] would be discrete.

Here I think they mean for n to be discrete because of their result, namely that the difference is 1 for -N <= n <= +N.

9. ### Papabravo Expert

Feb 24, 2006
10,340
1,850
I agree on the use of () and brackets [] to distinguish continuous functions from discrete functions.
Even if the functions are discrete the result is still not what they say it should be because they use the ≤ operator in the definition.

10. ### WBahn Moderator

Mar 31, 2012
18,087
4,917
In which part of the definition are you referring to?

11. ### Papabravo Expert

Feb 24, 2006
10,340
1,850
In the definition of the second function it was a ≥, and not a ≤ operator.

u(n - N - 1) = 1, for n ≥ N + 1; and = 0 , for n < N + 1

The subtraction of the two functions will not go to zero until you reach n = N + 1
The subtraction of the two functions will be 1, when n = N

So now it appears that if the functions are discrete then they get the intended result. I don't like problems that leave out crucial information like that and are subject to misinterpretation. Maybe the TS/OP left out some information when he restated the problem. Certainly the use of the term "step function" without additional qualification was misleading.

12. ### WBahn Moderator

Mar 31, 2012
18,087
4,917
I don't see a problem here. Whether it is continuous or discrete, you have

u(x) = 1 for x ≥ 0 and 0 otherwise, so that would mean that

u(n - N - 1) = 1 for (n - N - 1) ≥ 0 which is the same as n ≥ (N+1)

Agreed. Which is why I say that their results are consistent with it being a discrete function and not a continuous function.

As I look at it, if the functions are discrete then they have stated things correctly (at least for N>0).

My guess (hope) is that the TS just got a bit sloppy and use () instead of []. That's a common mistake and I know it's one I used to make regularly when I was first learning this stuff.

13. ### Papabravo Expert

Feb 24, 2006
10,340
1,850
I think we agree that the stated result is correct for discrete functions, and wrong for continuous functions. Did we get snookered into hashing this out for his benefit, with minimal effort on his part? I think maybe we did -- oh well.

14. ### mickonk Thread Starter New Member

Apr 6, 2015
13
0
Thanks for replies. This is actualy part of one example from my book involving discrete Fourier transform. Here is complete task and solution:
Find Fourier transform of signal:

We can write x(n) as:

where x1(n) is u(n+N)-u(n-N-1). We can write:

(we used that cos(n)=(1/2)*(exp(j*n)+exp(-j*n)
Using properties of Fourier transform of discrete signal:

Fourier transform of our signal will be:

We must find Fourier transform of x1(n):

Last edited: Apr 7, 2015
15. ### WBahn Moderator

Mar 31, 2012
18,087
4,917
I think we agree, too. To some degree we did get snookered (though not by the TS), though I was careful not to show the algebraic approach to the solution.

16. ### mickonk Thread Starter New Member

Apr 6, 2015
13
0
Here is how I tried to solve this algebraically.
We have function u(n+N)-u(n-(N+1)). Let's say N is some positive number, for example N=1.
1. When n is less then -N, for example n=-2, we have u(n+N)-u(n-(N+1))=0-0=0.
2. When -N<n<N+1 , for example n=-0.5, we have u(n+N)-u(n-(N+1))=1-0=1.
3. When n>N+1, for example n=3, we have u(n+N)-u(n-(N+1))=1-1=0.
So our function equals 1 for n between -N and N+1 but solution from my book doesn't agree with it?

Last edited: Apr 7, 2015
17. ### WBahn Moderator

Mar 31, 2012
18,087
4,917
First of all, could you confirm whether this is a continuous or a discrete time signal. Since you are using the DFT I'm assuming it is a discrete signal.

Is your text really using u(n) instead of u[n] for discrete signals?

An algebraic solution involves breaking each function into compatible segments and then performing the operations on each segment and then, if possible, combining adjacent segments.

Say we have

x[n] = n for -(N+2) <= n <= (N+3) and 0 otherwise
y[n] = 0 for n < -(N-1) and 1 otherwise.

we want to know

z[n] = x[n]·y[n]

So start at -∞ and define the functions in bins that are the same size by starting a new bin each time you reach a boundary for ANY of the functions.

-∞ <= n < -(N+2): x[n] = 0; y[n] = 0 => z[n] = 0
-(N+2) <= n < -(N-1): x[n] = n; y[n] = 0 => z[n] = 0
-(N-1) <= n <= (N+3): x[n] = n; y[n] = 1 => z[n] = n
(N+3) < n <= +∞: x[n] = 0; y[n] = 1 => z[n] = 0

The end result is that

z[n] = n for -(N-1) <= n <= (N+3) and 0 otherwise

Because this is a discrete system, we can replace <= with < by doing a simple shift. The same with >=.

So

z[n] = n for -(N-1)-1 < n < (N+3)+1 and 0 otherwise
z[n] = n for -N < n < (N+4) and 0 otherwise

is the same thing (assuming I haven't messed things up).

18. ### mickonk Thread Starter New Member

Apr 6, 2015
13
0
It's definitely discrete signal. I don't know why they use () brackets instead of [].

19. ### MrAl Distinguished Member

Jun 17, 2014
2,562
518
Hi,

I dont think 'n' has to be discrete, but who cares. As long as they say what it is, we dont have to worry
'k' is more likely to be discrete, but im not going to argue either way.

In any case, when a unit step function starts at say t=t1 that means it goes to 1 at t1 and stays at 1 indefinitely.
If a negative unit step function starts at say t=t2, that means it goes to -1 at t2 and stays at -1 indefinitely.
They are both zero otherwise.

What we get when we have a unit step go high at t=t1 and a negative unit step go to -1 at t=t2 at a LATER time is a pulse of 1 of duration equal to t2-t1 because the second unit step which is really a negative unit step completely cancels the first unit step at t=t2, and before t=t1 there was no step, so we have zero everywhere except for the time between t1 and t2.
If we then later generate another unit step at t3 and then another negative unit step at t4, we get a second pulse.
If we start with a unit step times two and then a negative unit step of just -1, we end up with a higher pulse between t1 and t2 and then +1 for the rest of the time. The amplitude is A1-A2 and the time durations are t2-t1 at +2 and and t2 to infinity at +1.
So you compute the amplitude and the duration.

20. ### WBahn Moderator

Mar 31, 2012
18,087
4,917
It matters here because you get a different answer if you use continuous compared to discrete.

The distinction comes into play because in the discrete world, n≤N and n<(N+1) are the same thing. This is NOT true in the continuous world. Consider the case of N+0.5 to see the difference.