# Building periodic sequences from finite-support sequences

Given a discrete-time finite-support signal x[n]

$$x[n] = \left\{ {\begin{array}{*{20}{l}} {{{( - 1)}^n}n}&{{\rm{ }}n = 1,2,3}\\ 0&{{\rm{otherwise}}} \end{array}} \right.$$

And consider also its periodic repetition is

$$y[n] = \sum\nolimits_{k = - \infty }^\infty {x[n + 7k]}$$

How we can generate the y[n] in Matlab or Python?

Here is piece of code to generate and plot x[n]. But for Y[n] I have no idea!

% finite support signal
n = -5:1:8;
x = zeros(size(n));
x( find(n==1 | n==2 | n==3) ) = [(-1)^1*1 (-1)^2*2 (-1)^3*3];
stem(n, x, 'filled')

• Hint: think about what mod(n,7) might do for you. – Florian Jul 22 '19 at 13:51
• Thank you for comment. $x(mod(n,7)+1)$ produces the periodic extension of x[n]: $y[n]=x[n\space mod\space 7]$. @Florian – sci9 Jul 22 '19 at 14:53
• @Florian Now the question is, $y[n] = \sum\nolimits_{k = - \infty }^\infty {x[n + 7k]}$ is equivalent to $y[n]=x[n\space mod\space 7]$? – sci9 Jul 22 '19 at 14:58
• Do you see any reason why it shouldn't be the same? I suggest you write out $y[n]$ for a few examples, this should make it easier to see it. Like $y = x+x+x+...+x[-6]+x[-13]+...$ Then use the fact that $x[n]$ is zero almost everywhere... – Florian Jul 22 '19 at 15:04
• @Florian Cloud you please check answer I've posted? – sci9 Jul 22 '19 at 17:55

You're thinking too complicated. Sorry I wasn't clear enough in my comment.

You're given a sequence $$x[n]$$ that contains three spikes and zeros elsewhere. Your sequence $$y[n]$$ contains periodically shifted copies of the original one. It's just repeating the same three spikes indefinitely, without overlap since $$7>3$$. Hence, all you need to do to find out what $$y[n]$$ is for a given $$n$$ is to check where it would map to in your original sequence. In other words: $$y[n] = x[n \; {\rm mod} \; 7].$$

Here is how you can see why that is true: take $$y[n] = \sum_k x[n+7k]$$, expand, and then use the fact that $$x[n]$$ is zero outside $$[0,7)$$ (in fact, zero outside $$[1,2,3]$$):

\begin{align}y & = x + x + x + \ldots + x[-7] + x[-14] + \ldots = x \\ y & = x + x + x + \ldots + x[-6] + x[-13] + \ldots = x\\ & \ldots\\ y & = x + x + x + \ldots + x[-1] + x[-8] + \ldots = x \\ y & = x + x + x + \ldots + x + x[-7] + \ldots = x \\ y & = \ldots = x \\ & \ldots \\ y & = \ldots = x \\ y & = \ldots = x \\ \end{align}

And that's how I would do it in Matlab

x = @(n) (-1).^n .* n .* ((n>=1)&(n<=3));
y = @(n) x(mod(n,7));
n = -7:21;
figure(1);clf;stem(n,x(n))
hold on;
stem(n,y(n),'rx--')
xlabel('n');axis([-7,21,-4,4])
legend('x[n]','y[n]');


*edit: Regarding your question 1: yes, you can do it with a sum as well. If you do it correctly, the result is exactly the same. Here's a take in Matlab: Of course you cannot do an infinite sum, so this example sums from -K to K, plotting for K=10:

x = @(n) (-1).^n .* n .* ((n>=1)&(n<=3));
y = @(n) x(mod(n,7));
y_sum = @(n,K) sum(x(n + 7*(-K:K)'),1);
n = -7:21;
figure(1);clf;stem(n,x(n))
hold on;
stem(n,y(n),'rx--')
stem(n,y_sum(n,10),'k*-.')
xlabel('n');axis([-7,21,-4,4])
legend('x[n]','y[n]'); Regarding your second question, well, the code is there, you can experiment with what changes. If the pulses overlap, you're going to see the sums of the overlapping ones... in particular the -1 and the -3 pulse add up to -4 pulses. Looks like this (now the modulo method does not work like that, since it assumed no overlap): • Merci for answer. I have some questions ... – sci9 Jul 23 '19 at 11:07
• 1- We can build y[n] by superimposing (adding) infinite copies of x[n]. Ok? So, what the answer I've posted represent? Are superimposing and adding are two different operator in DSP? – sci9 Jul 23 '19 at 11:08
• 2- If we take k=2 instead of 7, then copies in the sum do overlap. Now what are the values of y[n]? – sci9 Jul 23 '19 at 11:08
• @sci9 I edited my reply to account for your questions. – Florian Jul 23 '19 at 11:22
• Thank you very much for the detailed answer. But there is still one question left unanswered. Does the answer I've posted have some meaning? @Florian – sci9 Jul 23 '19 at 12:46

Thanks to @Florian's comments, here is sample solution

clc, clear
n = 0:1:7*10^6-1;
x = zeros(size(n));
x( find(n==1 | n==2 | n==3) ) = [(-1)^1*1 (-1)^2*2 (-1)^3*3];
y = x(mod(n,7)+1);
y = sum(reshape(y,7,[]),2)'


For large $$k$$s we have for example: y = 0 -1000000 2000000 -3000000 0 0 0.