⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fouriertransform.m

📁 傅立叶变换和扩频BPSK的MATLAB仿真程序源码
💻 M
字号:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% PMC                                                          January 2008
% [f,Y] = FourierTransform (y,t)
%
% This function receives as input a sequence of samples of a waveform 
% in the time domain and calculates the corresponding frequency spectrum
%
% Input:  
%           - y[] = vector of samples
%           - t[] = vector of time values
% Output:
%           - Y[] = Fourier transform of y
%           - f[] = vector of frequency values
%
% NOTE: the Fourier transform vector is divided by the number of samples to
% get results applicable to continuous-time functions
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function [f,Y] = FourierTransform(y,t)

    % Calculate the Discrete Fourier Transform
    Y = fftshift(fft(y))/length(y); %; divide by N to normalize 
    % Y = fft(y)/length(y); %; divide by N to normalize 

    delta_f = 1/(length(Y)*(t(2)-t(1)));

    % If the vector length is odd, the DC component will be localized at
    % the center of the vector
    if mod(length(Y),2)
        tmp = ceil(length(Y)/2); % Find the center of the array
        f(tmp) = 0; % DC frequency 
        for nn=1:floor(length(Y)/2)
            f(tmp + nn) = f(tmp + nn - 1) + delta_f;
            f(tmp - nn) = -f(tmp + nn);
        end

    % If the vector length is even, the DC component will be localized at
    % the first element of the right-hand side
     else
        tmp = (length(Y)/2) + 1; % Find the center of the array
        f(tmp) = 0; % DC frequency
        for nn=1:tmp-2
            f(tmp + nn) = f(tmp + nn - 1) + delta_f;
            f(tmp - nn) = -f(tmp + nn);
        end        
        f(1) = f(2) - delta_f;
    end

end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -