How do I multiply Sin and stepseq functions?

20 次查看(过去 30 天)
x(t) = sin(2Πt)[u(t+1)-u(t-1)]
How do I multiply Sin and stepseq functions?
t=-1:1;
a = sin(2*pi*t);
b = stepseq(-1, -1, 1)-stepseq(1, -1, 1);
h = a.*b;
subplot(2,1,2);
title('5-19_d');xlabel('t');ylabel('x[t]');
It was originally intended to do this, but the size of the arrangement was not compatible. How can I multiply it?

回答(1 个)

Star Strider
Star Strider 2021-5-2
I have no idea what you are doing, and I had to look up ‘stepseq’, since I have never heard of it before.
Experiment with this to get the result you want —
t=-10:10;
a = sin(2*pi*t/11);
[x1,n1] = stepseq(-1, -10, 10);
[x2,n2] = stepseq(1, -1, 19);
b = x1-x2;
h = a.*b;
subplot(2,1,2);
plot(t, h)
title('5-19_d');xlabel('t');ylabel('x[t]');
function [x,n] = stepseq(n0,n1,n2) % Copied From: <https://www.mathworks.com/matlabcentral/answers/12834-unsolved-function?s_tid=srchtitle#>
% Generates x(n) = u(n-n0); n1 <= n,n0 <= n2
% ------------------------------------------
% [x,n] = stepseq(n0,n1,n2)
%
if ((n0 < n1) | (n0 > n2) | (n1 > n2))
error('arguments must satisfy n1 <= n0 <= n2')
end
n = [n1:n2];
%x = [zeros(1,(n0-n1)), ones(1,(n2-n0+1))];
x = [(n-n0) >= 0];
end
I made several changes to get the code to produce something meaningful.

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by