sinc function doesnt work...
96 views (last 30 days)
Show older comments
My main code
clear all
close all
clc
T=0.1;
A=1;
tau=T/2;
kmax=20;
t0=tau/2;
%%
f0=1/T;
t=(0:0.0001:1)*5*T;
xsin=sin(2*pi*f0*t);
x=zeros(size(t));
ii1=find(xsin>=0);
x(ii1)=1;
figure(1)
plot(t,x), ylim([-0.5 1.5])
kk=-kmax:1:kmax;
Xk=func_Fourier_series_periodic_pulse(T,tau,t0,A,kk);
figure(2)
stem(kk,abs(Xk))
And my function code for "func_Fourier_series_periodic_pulse"
function Xk=func_Fourier_series_periodic_pulse(T,tau,t0,A,k)
f0=1/T;
Xk=(A*tau/T)*(sinc(k*f0*tau)).*exp(-j*2*pi*k*f0*t0);
There was an error saying
Incorrect number or types of inputs or outputs for function 'sinc'
I don't know what I did wrong... can someone help me...
0 Comments
Accepted Answer
Steven Lord
on 13 Oct 2022
The sinc function is part of Signal Processing Toolbox. Check the output of the ver function to see if you have this toolbox installed.
3 Comments
Steven Lord
on 10 Apr 2024
My answer from a year and a half ago was incomplete.
In this case, the sinc function for numbers is part of Signal Processing Toolbox. If that was the only sinc function in MathWorks products it may be able to say that, and I know that sometimes it does offer some suggestions that you need another product.
But in this case, there's also a version of sinc for symbolic variables.
which -all sinc
In the case where you have Symbolic Math Toolbox installed and do not have Signal Processing Toolbox installed, MATLAB identifies that there is a sinc function available to MATLAB, but MATLAB can't call it with the data that you passed into it. You're not calling it with a sym object so MATLAB can't call the sym method. In that case it flags "you might want to change the data with which you're calling the function."
Which one of those two potential reasons your call to sinc can't succeed should MATLAB prefer to alert you to?
More Answers (1)
Paul
on 13 Oct 2022
The code runs fine here.
clear all
close all
clc
T=0.1;
A=1;
tau=T/2;
kmax=20;
t0=tau/2;
%%
f0=1/T;
t=(0:0.0001:1)*5*T;
xsin=sin(2*pi*f0*t);
x=zeros(size(t));
ii1=find(xsin>=0);
x(ii1)=1;
figure(1)
plot(t,x), ylim([-0.5 1.5])
kk=-kmax:1:kmax;
Xk=func_Fourier_series_periodic_pulse(T,tau,t0,A,kk);
figure(2)
stem(kk,abs(Xk))
Perhaps you have a version of the sinc function shadowing the Matlab function and defined with a different signature? What is the output of
which sinc -all
function Xk=func_Fourier_series_periodic_pulse(T,tau,t0,A,k)
f0=1/T;
Xk=(A*tau/T)*(sinc(k*f0*tau)).*exp(-j*2*pi*k*f0*t0);
end
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!