向下移动信号

发布于 2024-12-12 10:39:17 字数 812 浏览 3 评论 0原文

我有一个为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

酒与心事 2024-12-19 10:39:18
function x_new = rescale(x, new_min, new_max)

x_min = min(x);
x_max = max(x);

x_new = new_min + (new_max - new_min) * (x - x_min) / (x_max - x_min);

(顺便说一句,这是非常基本的数学,可以很容易地用谷歌搜索)

function x_new = rescale(x, new_min, new_max)

x_min = min(x);
x_max = max(x);

x_new = new_min + (new_max - new_min) * (x - x_min) / (x_max - x_min);

(BTW this is very basic math that could have been easily googled)

当爱已成负担 2024-12-19 10:39:18

这是代码,以防它对下一个人有帮助

clear all
% SCRIPT BEGINS
t=linspace(0,1,22050);
freq=5; %how many in 1 sec
%t = 0:0.01:1; %time vector
A = 1; % amplitude
T = 1/freq; % period of the signal

vertoffset=0.5;
% square
square = mod(t * A / T, A) > A / 2;
square = square - vertoffset;
plot(t, square)
title('Square');

% rectangle
l = 0.2; % percentage the signal spends on low value
rectangle = mod(t * A / T, A) > A * l;
rectangle = rectangle - vertoffset;
figure;
plot(t, rectangle);
title('Rectangle');

% sawtooth
sawtooth = mod(t * A / T, A);
sawtooth = sawtooth -vertoffset;
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));
triangle = 2*triangle - 1.5;
figure;
plot(t, triangle);
title('triangle');

Here's the code in case it helps the next person

clear all
% SCRIPT BEGINS
t=linspace(0,1,22050);
freq=5; %how many in 1 sec
%t = 0:0.01:1; %time vector
A = 1; % amplitude
T = 1/freq; % period of the signal

vertoffset=0.5;
% square
square = mod(t * A / T, A) > A / 2;
square = square - vertoffset;
plot(t, square)
title('Square');

% rectangle
l = 0.2; % percentage the signal spends on low value
rectangle = mod(t * A / T, A) > A * l;
rectangle = rectangle - vertoffset;
figure;
plot(t, rectangle);
title('Rectangle');

% sawtooth
sawtooth = mod(t * A / T, A);
sawtooth = sawtooth -vertoffset;
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));
triangle = 2*triangle - 1.5;
figure;
plot(t, triangle);
title('triangle');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文