help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question on defining a digital signal x[n]


From: Sergei Steshenko
Subject: Re: Question on defining a digital signal x[n]
Date: Wed, 8 May 2013 15:10:18 -0700 (PDT)


--- On Wed, 5/8/13, Juan Pablo Carbajal <address@hidden> wrote:

> From: Juan Pablo Carbajal <address@hidden>
> Subject: Re: Question on defining a digital signal x[n]
> To: "Oceanic" <address@hidden>
> Cc: "Octave Help" <address@hidden>
> Date: Wednesday, May 8, 2013, 12:54 PM
> On Wed, May 8, 2013 at 9:38 PM,
> Oceanic <address@hidden>
> wrote:
> > Hello,
> >
> > Some background - I am currently teaching myself DSP
> and have recently taken
> > a Signals & Systems course.
> > As part of the process I am also learning how to use
> Octave.
> >
> > As a learning exercise I am going back to see if I can
> use Octave instead of
> > pen-and-paper to go through past examples and
> exercises. I will probably be
> > asking a lot of questions and hopefully I can can get
> some help. I would
> > like to make a preemptive apology for the noob
> questions
> >
> > So first question:
> >
> > I have a digital signal described as follows:
> > x[n] = 0, when n <= -3 and when n >= 2
> > x[n] = 1, otherwise
> >
> > I described the signal successfully (at least a window
> of the signal, since
> > it extends to +ve and -ve infinity) using the following
> code (contents of .m
> > file below):
> >
> > y = ones(1,20);
> > x = [-10:9];
> > n = length(x);
> > for i = 1:n
> >   if x(i) <= -3 | x(i) >= 2
> >     y(i) = 0;
> >   end
> > end
> >
> > stem(x,y)
> > axis([-15 15 -1 1.5])
> >
> > My question is - Is there a more efficient way to
> describe this signal
> > (probably without having to use a for-loop)? What are
> the best-practices for
> > describing such signals?
> >
> > Thank you.
> >
> >
> >
> >
> > --
> > View this message in context: 
> > http://octave.1599824.n4.nabble.com/Question-on-defining-a-digital-signal-x-n-tp4652749.html
> > Sent from the Octave - General mailing list archive at
> Nabble.com.
> > _______________________________________________
> > Help-octave mailing list
> > address@hidden
> > https://mailman.cae.wisc.edu/listinfo/help-octave
> 
> You can do it without a for loop.  What you do is
> create vectors of
> boolean variables... example below
> (signal that is 1 if input is between -n and n)
> 
> function y = signal (t,n)
>   tf = t >= -n & t <= n;
>   y = zeros(size(t));
>   y(tf) = 1;
> endfunction
> 
> You can generalize this. Also check in the signal package
> in
> Octave-forge[1] exmaples like sigmoid_train [2]
> 
> [1] http://octave.sourceforge.net/signal/overview.html
> [2] http://octave.sourceforge.net/signal/function/sigmoid_train.html
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://mailman.cae.wisc.edu/listinfo/help-octave
> 

Well, in my self-built octave-3.6.4:

"
octave:1> foo(-1) = 1;
error: subscript indices must be either positive integers or logicals
".

I.e. according to my understanding x(-3) is impossible in Octave (assuming 'x' 
is a vector).

Regards,
  Sergei.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]