How do I multiply Sin and stepseq functions?

21 Ansichten (letzte 30 Tage)
Hey kim
Hey kim am 2 Mai 2021
Beantwortet: Star Strider am 2 Mai 2021
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?

Antworten (1)

Star Strider
Star Strider am 2 Mai 2021
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.

Kategorien

Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by