matlab中sinc函数的频谱没有显示任何内容
frequency spectrum of sinc function in matlab shows me nothing
因为我的 MATLAB 中没有 sinc 函数,
我实现了如下所示的功能
%% time specificactions:
Fs=10000; dt=1/Fs; t=(-0.1:dt:0.1-dt)'; N=size(t,1);
%message signal
mt=(sin(pi*100*t))./(pi*100*t);
%% frequency specifications
dF=Fs/N;
f=-Fs/2:dF:Fs/2-dF;
M=fftshift(fft(mt));
plot(f,abs(M)/N);
但图中只显示空白,所以我查找了变量 table,它充满了 NaN。
我不明白的一件事是,当我想要进行傅里叶变换的函数只是余弦函数时,完全相同的过程工作得很好。
你有一个错误定义的 sinc
函数,当 t=0
它输出 NaN
.
您可以检查在您的代码中执行 any(isnan(mt))
。
正确定义函数 do
mt(find(t==0))=1;
这将使您的代码输出
您可能需要重新考虑参数以便更好地查看方波。
Matlab sinc函数源码:
function y=sinc(x)
%SINC Sin(pi*x)/(pi*x) function.
% SINC(X) returns a matrix whose elements are the sinc of the elements
% of X, i.e.
% y = sin(pi*x)/(pi*x) if x ~= 0
% = 1 if x == 0
% where x is an element of the input matrix and y is the resultant
% output element.
%
% % Example of a sinc function for a linearly spaced vector:
% t = linspace(-5,5);
% y = sinc(t);
% plot(t,y);
% xlabel('Time (sec)');ylabel('Amplitude'); title('Sinc Function')
%
% See also SQUARE, SIN, COS, CHIRP, DIRIC, GAUSPULS, PULSTRAN, RECTPULS,
% and TRIPULS.
% Author(s): T. Krauss, 1-14-93
% Copyright 1988-2004 The MathWorks, Inc.
% $Revision: 1.7.4.1 $ $Date: 2004/08/10 02:11:27 $
i=find(x==0);
x(i)= 1; % From LS: don't need this is /0 warning is off
y = sin(pi*x)./(pi*x);
y(i) = 1;
因为我的 MATLAB 中没有 sinc 函数,
我实现了如下所示的功能
%% time specificactions:
Fs=10000; dt=1/Fs; t=(-0.1:dt:0.1-dt)'; N=size(t,1);
%message signal
mt=(sin(pi*100*t))./(pi*100*t);
%% frequency specifications
dF=Fs/N;
f=-Fs/2:dF:Fs/2-dF;
M=fftshift(fft(mt));
plot(f,abs(M)/N);
但图中只显示空白,所以我查找了变量 table,它充满了 NaN。
我不明白的一件事是,当我想要进行傅里叶变换的函数只是余弦函数时,完全相同的过程工作得很好。
你有一个错误定义的 sinc
函数,当 t=0
它输出 NaN
.
您可以检查在您的代码中执行 any(isnan(mt))
。
正确定义函数 do
mt(find(t==0))=1;
这将使您的代码输出
您可能需要重新考虑参数以便更好地查看方波。
Matlab sinc函数源码:
function y=sinc(x)
%SINC Sin(pi*x)/(pi*x) function.
% SINC(X) returns a matrix whose elements are the sinc of the elements
% of X, i.e.
% y = sin(pi*x)/(pi*x) if x ~= 0
% = 1 if x == 0
% where x is an element of the input matrix and y is the resultant
% output element.
%
% % Example of a sinc function for a linearly spaced vector:
% t = linspace(-5,5);
% y = sinc(t);
% plot(t,y);
% xlabel('Time (sec)');ylabel('Amplitude'); title('Sinc Function')
%
% See also SQUARE, SIN, COS, CHIRP, DIRIC, GAUSPULS, PULSTRAN, RECTPULS,
% and TRIPULS.
% Author(s): T. Krauss, 1-14-93
% Copyright 1988-2004 The MathWorks, Inc.
% $Revision: 1.7.4.1 $ $Date: 2004/08/10 02:11:27 $
i=find(x==0);
x(i)= 1; % From LS: don't need this is /0 warning is off
y = sin(pi*x)./(pi*x);
y(i) = 1;