Computing a convolution sum with MATLAB
显示 更早的评论
Let
x[n]=u[n-1]-u[n-1] and h[n]=tri((n-6)/4). Find the convolution sum x[n]*h[n] using MATALB CONVOLUTION and x[n] is limited to range 1 and 5 , h[n] is limited to range 3 and 9.
script for above one's
nx = -2:8 ; nh = 0:12; % Set time vectors for x and h
x = usD(n-1) - usD(n-6); % Compute values of x
h = tri((nh-6)/4); % Compute values of h
y = conv(x,h); % Compute the convolution of x with h
%
% Generate a discrete-time vector for y
%
ny = (nx(1) + nh(1)) + (0:(length(nx) + length(nh) - 2)) ;
%
% Graph the results
%
subplot(3,1,1) ; stem(nx,x,'k', 'filled');
xlabel('n') ; ylabel('x'); axis([-2,20,0,4]);
subplot(3,1,2) ; stem(nh,h,'k','filled') ;
xlabel('n') ; ylabel('h'); axis([-2,20,0,4]);
subplot(3,1,3) ; stem(ny,y,'k','filled');
xlabel('n') ; ylabel('y'); axis([-2,20,0,4]);
and functions for unit step discrete "usD" and "tri"
Tri function.
% Function to compute the triangle function. Uses the definition
% of the triangle function in terms of the ramp function. Works
% for vectors and scalars equally well.
function y = tri(t)
y = ramp(t+1) - 2*ramp(t) + ramp(t-1) ;
usD function
% Unit sequence function defined as 0 for input integer argument
% values less than zero, and 1 for input integer argument values
% equal to or greater than zero. Returns "NaN" for non-integer
% arguments. Works for vectors and scalars equally well.
%
% function y = uD(n)
function y = usD(n)
y = double(n >= 0) ; % Set output to one for non-
% negative arguments
ss = find(round(n)~=n) ; % Find all non-integer "n's"
y(ss) = NaN ; % Set the corresponding outputs
% all to "NaN"
And please help I cannot get any graph with above one script and two functions i.e usD and tri function.Do i need to keep convolution "conv" function y = conv(x,h); also? please give me conv function else
please give me suggestion for the above mat lab program to execute and I want to get graph for it???
回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Signal Processing Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!