[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: newbie question - unsigned conversion
From: |
Miquel Cabanas |
Subject: |
Re: newbie question - unsigned conversion |
Date: |
Thu, 16 Jan 2003 16:17:14 +0100 |
User-agent: |
Mutt/1.3.28i |
hi,
On Thu, Jan 16, 2003 at 02:32:52PM +0100, James Ridewood wrote:
>
> x = (0:1:720)';
> data = [x, sin((x-15)*(pi/180)), sin((x-105)*(pi/180)),
> sin((x-135)*(pi/180)), sin((x-225)*(pi/180)), sin((x-255)*(pi/180)),
> sin((x-345)*(pi/180))];
abs_data = abs (data) ;
> gplot [0:720] [-1.1:1.1] data with lines, data using 1:2 with lines,
> data
> using 1:3 with lines, data using 1:4 with lines, data using 1:5 with
> lines,
> data using 1:6 with lines, data using 1:7 with lines
then replace "data" with "abs_data" in the gplot command above,
or use
plot (abs_data(:,1), abs_data(:,2:7))
or
plot (x, abs_data(:,2:7))
A cleaner code could be,
# x axis in degrees up to 720 deg
x = 0:1:720 ;
# phase values in degrees
phase = [-15 -105 -135 -225 -255 -345]
# create signals matrix. The code below
# 1) creates a matrix that contains m copies of the x vector,
# where m is the length of the phase vector, i.e. the number
# of phase values "ones (length (phase), 1) * x", then
# 2) creates a matrix that contains n copies of the phase vector,
# where n is the length of the x vector, and transposes it, then
# 3) subtracts the phase matrix from the x matrix, converst from
# degrees to radians, and calculates the sine to obtain the signals
#
# NOTE that there are ways to merge and speed up steps #1 and #2,
# search the internet for "Matlab vectorisation tricks", they also
# apply to Octave.
x_mx = ones (length (phase), 1) * x;
phase_mx = (ones (length (x), 1) * phase)';
signals = sin ((x_mx .- phase_mx).*(pi/180));
# set y-axis range
gset yrange [-1.1:1.1]
plot (x, signals)
fprintf (stdout, "waiting 5 seconds");
pause(5);
# absolute signals
abs_signals = abs (signals);
plot (x, abs_signals)
Miquel
Miquel E Cabanas ------------------------------------------------------
SeRMN, Universitat Autonoma de Barcelona (address@hidden)
------------------------------------------o-oo--ooo---ooo--oo-o--------
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------