sinc function doesnt work...

42 ビュー (過去 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