向下移动信号
我有一个为 y 轴上的正方形、矩形和锯齿信号从 0 到 1 创建的信号,如何将信号向下移动(垂直偏移),以便信号在 y 轴上从 -0.5 变为 0.5,并将三角信号从 0.5 到 1.0 更改为 -0.5 到 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');
谢谢我正在使用八度/matlab
I 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 I'm using octave/matlab
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
(顺便说一句,这是非常基本的数学,可以很容易地用谷歌搜索)
(BTW this is very basic math that could have been easily googled)
这是代码,以防它对下一个人有帮助
Here's the code in case it helps the next person