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.

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)

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

I followed all the steps given by you ....but still i am gettiing the same error.ie not enough input arguments........which input arguments are less......that is not clear to me........
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];

Sign in to comment.

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

Asked:

on 24 Nov 2013

Edited:

DGM
on 1 Oct 2023

Community Treasure Hunt

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

Start Hunting!