필터 지우기
필터 지우기

I can't seem to find the error in my program.

조회 수: 4 (최근 30일)
Santos Tapia
Santos Tapia 2018년 2월 17일
댓글: Star Strider 2018년 2월 19일
My program looks like this, its supposed to take the input signal and output signal after convolution and graph them versus a variable.
function graphconv(~)
L=200;
K=50;
n=0:L-1;
z = double(rem(n,K) < K/2);
h=@(n) 1/15 .* n>=0&&n<=14;
y = conv(h,z);
plot(n,z,'r',n,y,'b')
but i keep getting these errors and i can't seem to understand what they mean. I already tried googling it but to no avail.
ERROR CODES:
>> graphconv
Input arguments to function include colon operator. To input the colon character,
use ':' instead.
Error in conv (line 43)
c = conv2(a(:),b(:),shape);
Error in graphconv (line 11)
y = conv(h,z);

채택된 답변

Star Strider
Star Strider 2018년 2월 17일
You are passing a function handle as an argument to conv. That is throwing the error.
Pass the function with an argument (so it returns a value) instead:
h=@(n) 1/15 .* ((n>=0) & (n<=14));
y = conv(h(n),z, 'same');
Use only one ‘&’ in ‘h’ to test vectors. (Using ‘&&’ requires logical arguments, and you have a vector of numeric arguments.) I added the 'same' argument because that then works in your plot call without problems. If you want a different plot, you will have to call it with either one argument (probably ‘z’), or two equal-length arguments.
  댓글 수: 6
Santos Tapia
Santos Tapia 2018년 2월 19일
No need to apologize, thank you very much you've been a great deal of help and have helped alleviate any confusion I previously had!
Star Strider
Star Strider 2018년 2월 19일
As always, my pleasure!

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

추가 답변 (2개)

Walter Roberson
Walter Roberson 2018년 2월 17일
What it is really getting at is that you cannot conv() a function handle on a matrix. The firs two arguments to conv must be numeric vectors or arrays.
It appears to me that you probably want
conv(z, ones(1,15)/15)
and that possibly you might want to add the 'same' or 'valid' option in the third parameter.
  댓글 수: 4
Santos Tapia
Santos Tapia 2018년 2월 17일
I tried the suggested code but the output isn't quite correct perhaps it might be some of the parameters I set but i'm not sure
Walter Roberson
Walter Roberson 2018년 2월 18일
y = conv(z, [ones(1,15)/15, zeros(1, L-15)], 'same');

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


Image Analyst
Image Analyst 2018년 2월 17일
h needs to be an actual numerical array, not a function defnintion. Try
h = 1/15 .* n>=0&&n<=14;
instead.
  댓글 수: 3
Santos Tapia
Santos Tapia 2018년 2월 17일
I'm attempting to recreate this function on matlab but I can't find out how to do it properly.
Walter Roberson
Walter Roberson 2018년 2월 17일
h = @(n) 1/15 .* (n>=0 & n<=14);
However, you still cannot convolve with that.

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

카테고리

Help CenterFile Exchange에서 Frequency Transformations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by