2015-05-14 39 views
1

,因爲我沒有在我的MATLAB正弦函數,頻譜顯示我什麼

我實現這個函數如下圖所示

%% 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。

我不明白的一件事是,當我想進行傅里葉變換的函數只是餘弦函數時,完全相同的過程工作得很好。

+3

它可能具有的是,在'T = 0',你將零零的事實做。嘗試爲't = 0'明確指定'mt = 1'。 – jadhachem

回答

0

您有錯誤定義的sinc函數,因爲當它輸出NaNt=0

你可以檢查你在代碼中做的any(isnan(mt))

要正確定義函數做

mt(find(t==0))=1; 

這將使你的代碼輸出

enter image description here

你可能需要重新考慮,以更好地看到方波的參數。

+0

謝謝!添加該功能後,它工作得很好 – CSjune

0

辛格函數在Matlab的源代碼:

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;