1
$\begingroup$

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')
$\endgroup$
  • $\begingroup$ Hint: think about what mod(n,7) might do for you. $\endgroup$ – Florian Jul 22 at 13:51
  • $\begingroup$ 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 $\endgroup$ – sci9 Jul 22 at 14:53
  • $\begingroup$ @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]$? $\endgroup$ – sci9 Jul 22 at 14:58
  • $\begingroup$ 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[1] = x[1]+x[8]+x[15]+...+x[-6]+x[-13]+...$ Then use the fact that $x[n]$ is zero almost everywhere... $\endgroup$ – Florian Jul 22 at 15:04
  • $\begingroup$ @Florian Cloud you please check answer I've posted? $\endgroup$ – sci9 Jul 22 at 17:55
0
$\begingroup$

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[0] & = x[0] + x[7] + x[14] + \ldots + x[-7] + x[-14] + \ldots = x[0] \\ y[1] & = x[1] + x[8] + x[15] + \ldots + x[-6] + x[-13] + \ldots = x[1]\\ & \ldots\\ y[6] & = x[6] + x[13] + x[20] + \ldots + x[-1] + x[-8] + \ldots = x[6] \\ y[7] & = x[7] + x[14] + x[15] + \ldots + x[0] + x[-7] + \ldots = x[0] \\ y[8] & = \ldots = x[1] \\ & \ldots \\ y[13] & = \ldots = x[6] \\ y[14] & = \ldots = x[0] \\ \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]');

Matlab example, revised

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

Matlab example with overlap

$\endgroup$
  • $\begingroup$ Merci for answer. I have some questions ... $\endgroup$ – sci9 Jul 23 at 11:07
  • $\begingroup$ 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? $\endgroup$ – sci9 Jul 23 at 11:08
  • $\begingroup$ 2- If we take k=2 instead of 7, then copies in the sum do overlap. Now what are the values of y[n]? $\endgroup$ – sci9 Jul 23 at 11:08
  • $\begingroup$ @sci9 I edited my reply to account for your questions. $\endgroup$ – Florian Jul 23 at 11:22
  • $\begingroup$ 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 $\endgroup$ – sci9 Jul 23 at 12:46
0
$\begingroup$

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.