簡體   English   中英

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);

但該圖顯示我什么都沒有,只不過是空白,所以我查找了變量表,並用NaN填充了該表。

我不明白的一件事是,當我要進行傅立葉變換的函數只是余弦函數時,完全相同的過程效果很好。

您有一個錯誤定義的sinc函數,因為當t=0它將輸出NaN

您可以檢查代碼中是否執行了any(isnan(mt))

要正確定義功能

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;   

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM