|
From: | Rick T |
Subject: | Re: Shifting signal down |
Date: | Thu, 27 Oct 2011 11:17:13 -1000 |
First of all, to answer your questions:-To shift the square signal downward just subtract 0.5 from the signal, like so:squareShiftDown = square-0.5;-For the triangle you'll need to scale as well as shift. Try:triangleShiftDown = 2*triangle-1.5;Secondly, Octave has functions you can use to create these signals which may or may not be easier than what you are currently doing. Read the help files for square, rectpuls, sawtooth, and tripuls if you are interested.-RonOn Thu, Oct 27, 2011 at 1:42 PM, Rick T <address@hidden> wrote:
_______________________________________________Greetings allI have a signal that is created from 0 to 1 for the square,rectangle and the sawtooth signals on the y axis how can I shift the signal down (vertical offset) so the signal will go from -0.5 to 0.5 on the y axis, and change the triangle signal from 0.5 to 1.0 to -0.5 to 0.5?clear all
% SCRIPT BEGINS
t=linspace(0,1,22050)
freq=5%how many times it repeats in 1 sec
A = 1; % amplitude
T = 1/freq; % period of the signal
% square
square = mod(t * A / T, A) > A / 2;
plot(t, square)
title('Square');
% rectangle
l = 0.2; % percentage the signal spends on low value
rectangle = mod(t * A / T, A) > A * l;
figure;
plot(t, rectangle);
title('Rectangle');
% sawtooth
sawtooth = mod(t * A / T, A);
figure;
plot(t, sawtooth);
title('Sawtooth');
% triangle
triangle = (mod(t * A / T, A) > 0.5).*mod(t * A / T, A) + (mod(t * A / T, A) <= 0.5).*(1 - mod(t * A / T, A));
figure;
plot(t, triangle);
title('triangle');
thanks
--
-
Help-octave mailing list
address@hidden
https://mailman.cae.wisc.edu/listinfo/help-octave
[Prev in Thread] | Current Thread | [Next in Thread] |