how can i use symsum to make function with a variable apart from syms k?
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (2)
Paul
am 31 Mär. 2021
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')
Siehe auch
Kategorien
Mehr zu Calculus finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!