【发布时间】:2011-10-27 20:54:52
【问题描述】:
我有一个从 0 到 1 的信号,用于 y 轴上的正方形、矩形和锯齿信号我如何将信号向下移动(垂直偏移),以便信号从 -0.5 变为 0.5 y轴,把三角信号从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');
感谢我正在使用 octave/matlab
【问题讨论】: