sinc function doesnt work...

조회 수: 44 (최근 30일)
Seungjun Lee
Seungjun Lee 2022년 10월 13일
편집: DGM 2024년 4월 10일
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...

채택된 답변

Steven Lord
Steven Lord 2022년 10월 13일
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
Aaron Kaw
Aaron Kaw 2024년 4월 9일
WHY CAN'T MATLAB JUST SAY THAT.
Steven Lord
Steven Lord 2024년 4월 10일
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
/MATLAB/toolbox/signal/signal/sinc.m /MATLAB/toolbox/signal/signal/@tall/sinc.m % tall method /MATLAB/toolbox/symbolic/symbolic/@sym/sinc.m % sym method
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?

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

추가 답변 (1개)

Paul
Paul 2022년 10월 13일
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
/MATLAB/toolbox/signal/signal/sinc.m /MATLAB/toolbox/signal/signal/@tall/sinc.m % tall method /MATLAB/toolbox/symbolic/symbolic/@sym/sinc.m % sym method
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
  댓글 수: 1
Seungjun Lee
Seungjun Lee 2022년 10월 13일
It works now!!
Thankyou!!

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by