i am defining a new function for generating unit sample sequences x(n)=delta(n-n0); n1<=n<=n2 i am proceeding in the follwing way .But some how i am getting error as not enough arguments at line n=[n1,n2];Therefore i am unable to define function.
Show older comments
i am defining a new function for generating unit sample sequences
x(n)=delta(n-n0); n1<=n<=n2
i am proceeding in the follwing way .But some how i am getting error as not enough arguments at line
n=[n1,n2];
Therefore i am unable to define function.
function [ x,n ] = impseq(n0,n1,n2)
% generates x(n)=delta(n-n0);n1<=n<=n2
% [ x,n ] = impseq(n0,n1,n2)
n=[n1,n2];
x=[(n-n0)==0];
end
Answers (2)
Azzi Abdelmalek
on 24 Nov 2013
Edited: Azzi Abdelmalek
on 24 Nov 2013
save your function as impseq.m then call it in Windows Command
n1=2;
n2=10;
n0=5;
[x,n ] = impseq(n0,n1,n2)
2 Comments
Pranali
on 24 Nov 2013
Mohammed Akthar kazi
on 6 Dec 2014
Don't execute the script file in which you have written your function.save your function as impseq.m and call this function from command window by typing n1=-5; n2=5; n0=0; n=n1:n2; [x,n]=impseq(n0,n1,n2) ;
in your code change n=[n1,n2] to n=[n1:n2];
n=(-5:5);
x=n.*impseq(-3,-5,5)-impseq(4,-5,5);
y=2*impseq(-2,-5,5)-impseq(4,-5,5);
subplot(121);
stem(n,x);
xlabel('input')
ylabel('output')
title('1st plot')
grid on
hold on
subplot(122);
stem(n,y);
xlabel('input')
ylabel('output')
title('2nd plot')
grid on
hold on
function [x]=impseq (n0,n1,n2)
n= [n1:n2];
x=[(n-n0)==0];
end
Categories
Find more on Legend in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!