Confusion regarding indice vector?

조회 수: 4 (최근 30일)
ABTJ
ABTJ 2020년 2월 23일
답변: Deepak 2024년 12월 4일
I want to write a MATLAB function to systematically develop the sequence y[?] generated by the convolution of the
two-finite length sequence x[?] and ?[?]. Program should be able to handle causal and non- casual sequences.
Program should call for the input sequences and their indices vector?
Below is my code:
function [ny,y ] = convolution(nx,x,nh,h )
%UNTITLED7 Summary of this function goes here
% Detailed explanation goes here
a=nx(1)+nh(1) %nx is time span of x and nh is time span of h
b=nx(length(x))+nh(length(h))
ny=[a:b]% ny is length of y
y=conv(x,h)
end
What is meant by indices vector in bold? Is it referring to what i have used and wrote nx and nh?

답변 (1개)

Deepak
Deepak 2024년 12월 4일
Hi @ABTJ,
In the context of discrete-time sequences, the "indices vector" typically refers to the vector that specifies the time indices (or positions) corresponding to each element of the sequence. For example, for sequence “x[n]” that starts at index (n = 0), the indices vector “nx” would be [0, 1, 2, ..., N-1], where “N” is the length of the sequence.
In the code,
  • nx: The indices vector for the sequence “x[n]”.
  • nh: The indices vector for the sequence “h[n]”.
Here is an improved version MATLAB function that handles both causal and non-causal sequences while taking the indices vectors into account:
function [ny, y] = convolution(nx, x, nh, h)
% Calculate the start and end indices for the convolution result
start_index = nx(1) + nh(1);
end_index = nx(end) + nh(end);
% Create the indices vector for the output sequence
ny = start_index:end_index;
% Perform the convolution
y = conv(x, h);
end
Please find attached the documentation of functions used for reference:
I hope this will help in resolving the issue.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by