how can i use symsum to make function with a variable apart from syms k?
조회 수: 5 (최근 30일)
이전 댓글 표시
hello
i'm trying to perform convolution and plot the result without using conv function in matlab.
i first created two function with variable n to perform convolution.
then, by using the definition of convolution in discrete domain,
i used symsum function to find the sum of each product in the series.
the problem is that the symsum keeps giving me errors.
what should i do to solve the problem? please help
below are the codes i made
close all
clear all
clc
n=-40:40;
unitstep=@(n)round(heaviside(n));
discretedelta=@(n)(n==0);
x=@(n)unitstep(n)-unitstep(n-21);
y=@(n)discretedelta(n-1)+2*discretedelta(n-2)+3*discretedelta(n-3)+2*discretedelta(n-4)+discretedelta(n-5);
syms k;
convxy=@(n)symsum(x(k)*y(n-k),k,-inf,inf);
subplot(2,2,1),
stem(n,x(n))
axis([-4 21 0 3])
hold on
subplot(2,2,2),
stem(n,y(n));
axis([-4 21 0 3])
hold on
subplot(2,2,[3 4]),
stem(n,convxy(n))
axis([-inf inf 0 inf])
hold on
댓글 수: 0
답변 (2개)
Paul
2021년 3월 31일
This code works for the specified sequences. It would need to be modified if either x[n] or y[n] take on non-zero values for n < 0
syms n k real
x(n) = heaviside(n) - heaviside(n-21);
y(n) = kroneckerDelta(n-1) + 2*kroneckerDelta(n-2) + 3*kroneckerDelta(n-3) + 2*kroneckerDelta(n-4) + kroneckerDelta(n-5);
convxy(n) = symsum(x(k)*y(n-k),k,0,n); % summation limits based on fact that x and y are zero for n < 0
% conv solution for comparison
xnum = ones([1 21]);
ynum = [0 1 2 3 2 1];
cnum = conv(xnum,ynum);
stem(0:25,cnum)
hold on;
stem(0:28,double(convxy(sym(0:28))),'x')
참고 항목
카테고리
Help Center 및 File Exchange에서 Calculus에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!