I am trying to convolve two functions.
f(s) = (1-4s^2)^0.5
v(s) = sinc(s/pi)-0.5(sinc(s/2*pi))^2
I followed with entering in this:
w = conv(f,v,'full');
I keep getting an error. Would anyone know how to help? I'm not sure where I am going wrong?

6 Kommentare

M
M am 31 Okt. 2017
What is the error you get ? How do you define s ?
There are a few potential problems here.
1. Sinc uses the Signal Processing Toolbox.
2. This is not valid MATLAB code:
v(s) = sinc(s/pi)-0.5(sinc(s/2*pi))^2
Multiplication requires an "*". Leaving it out will generate an error. So depending on whats is, you might have done this:
v = sinc(s/pi)-0.5*(sinc(s/2*pi))^2
If s is a vector, then you needed to use a dot operator, though scalar multiplication and division are ok with * and / alone.
v = sinc(s/pi)-0.5*(sinc(s/2*pi)).^2
Likewise, f has problems. Note that this relation only lives for real values on the interval [-0.5,0.5]. As well, you need to use dot operators again for vector s. And again, multiplication REQUIRES an *.
f = sqrt(1-4*s.^2);
3. Were you wanting to do a symbolic convolution?
Asima Warner
Asima Warner am 31 Okt. 2017
Hi John, I did download the Signal Processing Toolbox. I am still pretty new to MatLab and am still learning the ropes. Thank you for pointing the typing errors out. I would have never noticed. What is the difference between a symbolic convolution and a normal convolution?
Asima Warner
Asima Warner am 31 Okt. 2017
M, this is the error I am receiving.
Error using conv2 Invalid data type. First and second arguments must be numeric or logical.
Error in conv (line 43) c = conv2(a(:),b(:),shape);
Error in CT_ComputerProject_Week8 (line 60) w = conv(v(:),s(:),'full');
Did you create
s = tf('s')
or using
syms s
? Either way, conv() is not valid for those.
I used syms s on a previous section of this problem. I was plotting a ram-lak filter and used this code:
syms s v
f(s, v) = sinc(s./pi)-0.5*sinc(s./(2*pi))^2;
ezplot(f, [-1,1])
Would that be affecting the conv? If so, would you have any suggestions on what to do?

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Walter Roberson
Walter Roberson am 31 Okt. 2017

0 Stimmen

conv() is for discrete convolution. The use of symbolic variables implies continuous convolution. For that, you can use the fourier equivalence, that convolution in time is equivalent to addition in frequency.
syms s t
f(s) = sqrt(1-4*s^2)
v(s) = sinc(s/pi)-0.5*(sinc(s/2*pi))^2
fv = simplify(ifourier(fourier(f,s,t)+fourier(v,s,t),t,s))

2 Kommentare

I entered what you have provided and added
imshow(fv)
to display fv, but am receiving this error
Error using imageDisplayValidateParams Expected input number 1, I, to be one of these types:
numeric, logical
Instead its type was sym.
Error in images.internal.imageDisplayValidateParams (line 11) validateattributes(common_args.CData, {'numeric','logical'},...
Error in images.internal.imageDisplayParseInputs (line 78) common_args = images.internal.imageDisplayValidateParams(common_args);
Error in imshow (line 241) images.internal.imageDisplayParseInputs({'Parent','Border','Reduce'},preparsed_varargin{:});
Error in CT_ComputerProject_Week8 (line 62) imshow(fv)
Am I interpreting your code incorrectly? fv is the convolution between f(s) and v(s) and should be able to be displayed via imshow.
Taylor Artunian
Taylor Artunian am 13 Dez. 2019
Convolution in time domain is equivalent to multiplication in frequency.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by