因为我的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);
但是这个图只显示了空白,所以我抬起了变量表,它充满了NaN。
我不明白的一点是,当我想要傅立叶变换的函数只是余弦函数时,完全相同的程序工作得很好。
答案 0 :(得分:0)
您有一个错误定义的sinc
函数,因为它t=0
输出NaN
。
您可以检查代码中是否any(isnan(mt))
。
正确定义功能
mt(find(t==0))=1;
这将使您的代码输出
您可能需要重新考虑这些参数,以便更好地了解方波。
答案 1 :(得分:0)
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;