make function to shift discrete signal

hello I am currently studying DSP and using matlab . I build a function that shifting signals and the out put of this function is n and y for exmaple :
x=[ 2 3 0 -5 2 1 ]; n=-1:4;
and i want that y(n)=x(2-K)
and this is my code :
clc;
clear all;
x=[ 2 3 0 -5 2 1 ];
n=-1:4;
m=2;
k=-1
shifting_by_m (x,m,n,k)
stem(n,x)
and the function is :
function [n,x] =shifting_by_k (x,m,n,k)
if (k<0)
n=m+flip(-n) %%h(m-k)
x=flip(x)
else (k>0)
n=(-1)*(m-n)
x=x
end
end
the question is there a way to write in my main code '(2-k)' and that the function will get that m=2 and k<0 ?

댓글 수: 3

Adam
Adam 2018년 6월 26일
If your function only supports a scalar k then why don't you just pass in 2-k as that argument? Where k is whatever you want it to be in your original equation and within the function it is just the single shift - i.e. whatever you pass it, which would be the result of 2-k
tomer polsky
tomer polsky 2018년 6월 26일
I am sorry but i did not understand what do you mean
Adam
Adam 2018년 6월 27일
Why are you trying to pass '2-k' into a function? Just calculate 2-k and pass the result of that into the function as the desired shift.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Signal Generation, Analysis, and Preprocessing에 대해 자세히 알아보기

태그

질문:

2018년 6월 26일

댓글:

2018년 6월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by