为什么我看不到印刷语句,即使代码正在编译并且没有显示任何错误

发布于 2025-02-03 08:20:41 字数 2033 浏览 2 评论 0原文

考虑以下代码:

%DTF与FFT

%% Example 1 N = 64
close all
clear
clc

eval_dft_vs_fft(64);


%% Example 2 N = 512
close all
clear

eval_dft_vs_fft(512);


%% Example 3 N = 4096
close all
clear

eval_dft_vs_fft(4096);


function [t_DFT,t_FFT, RMSE_FFT, RMSE_DFT] = eval_dft_vs_fft(N)
    % generate a arrray of random, complex numbers
    x = complex(rand(1, N), rand(1,N));
    
    tic % begin time measurement for the DFT calculation
    
     
    x_DFT = IDFT(DFT(x));   % Determine the DFT and IDFT result
    
    t_DFT = toc;            % end time measurement
    
    tic                     % begin time measurement for the FFT calculation
    
    x_FFT = ifft(fft(x));   % Determine the FFT and IFFT result
    
    t_FFT = toc;            % end time measurement
    
    % calculate the RMS Error of the DTF
    mean = sum(abs(x - x_DFT).^2)/N;
    RMSE_DFT = sqrt(mean);

    % calculate the RMS Error of the FFT
    mean = sum(abs(x - x_FFT).^2)/N;
    RMSE_FFT = sqrt(mean);
    
    disp("Number of elements N = " + N)
    disp(" ")
    disp("Calculation Time DTF = " + t_DFT)
    disp("Calculation Time FFT = " + t_FFT)
    disp(" ")
    disp("RMS Error DTF = " + RMSE_DFT)
    disp("RMS Error FFT = " + RMSE_FFT)
    fprintf('\n---------------\n\n')
end


function x = IDFT(X)
    
    N = length(X);
    x = zeros(1, N);
    
    for n=0:N-1
        x_1 = 0;
        for k = 0:N-1
            x_1 = x_1 + X(k+1) .* exp((1j*2*pi*k*n)/N);
        end
        x(n+1) = x_1;
    end
    x = x ./ N;

end


function X = DFT(x)

    N = numel(x);
    X = zeros(1, N);

    for k=0:N-1
        X_1 = 0;
        for n = 0:N-1
            X_1 = X_1 + x(n+1) .* exp(-(1j*2*pi*k*n)/N);
        end
        X(k+1) = X_1;
    end

end 

的目的是比较DFT和FFT的计算时间以及其RMS误差。我在命令窗口中没有遇到错误,但是在任何地方出现的dispations arent?

相反,我在命令窗口中得到的是这个;

列1至22:

142 181 173 162 165 178 96 175 166 166 165 172 165 173 173 165 174 180 179 96 179 96 142 96 125

61 32

我对八度的新手很新,因此对任何帮助都表示赞赏。

Consider this code:

% DTF vs FFT

%% Example 1 N = 64
close all
clear
clc

eval_dft_vs_fft(64);


%% Example 2 N = 512
close all
clear

eval_dft_vs_fft(512);


%% Example 3 N = 4096
close all
clear

eval_dft_vs_fft(4096);


function [t_DFT,t_FFT, RMSE_FFT, RMSE_DFT] = eval_dft_vs_fft(N)
    % generate a arrray of random, complex numbers
    x = complex(rand(1, N), rand(1,N));
    
    tic % begin time measurement for the DFT calculation
    
     
    x_DFT = IDFT(DFT(x));   % Determine the DFT and IDFT result
    
    t_DFT = toc;            % end time measurement
    
    tic                     % begin time measurement for the FFT calculation
    
    x_FFT = ifft(fft(x));   % Determine the FFT and IFFT result
    
    t_FFT = toc;            % end time measurement
    
    % calculate the RMS Error of the DTF
    mean = sum(abs(x - x_DFT).^2)/N;
    RMSE_DFT = sqrt(mean);

    % calculate the RMS Error of the FFT
    mean = sum(abs(x - x_FFT).^2)/N;
    RMSE_FFT = sqrt(mean);
    
    disp("Number of elements N = " + N)
    disp(" ")
    disp("Calculation Time DTF = " + t_DFT)
    disp("Calculation Time FFT = " + t_FFT)
    disp(" ")
    disp("RMS Error DTF = " + RMSE_DFT)
    disp("RMS Error FFT = " + RMSE_FFT)
    fprintf('\n---------------\n\n')
end


function x = IDFT(X)
    
    N = length(X);
    x = zeros(1, N);
    
    for n=0:N-1
        x_1 = 0;
        for k = 0:N-1
            x_1 = x_1 + X(k+1) .* exp((1j*2*pi*k*n)/N);
        end
        x(n+1) = x_1;
    end
    x = x ./ N;

end


function X = DFT(x)

    N = numel(x);
    X = zeros(1, N);

    for k=0:N-1
        X_1 = 0;
        for n = 0:N-1
            X_1 = X_1 + x(n+1) .* exp(-(1j*2*pi*k*n)/N);
        end
        X(k+1) = X_1;
    end

end 

Its purpose is to compare the calculation time of the DFT and the FFT as well as their RMS error. I am getting no errors in the command window but the disp statements arent showing up anywhere?

Rather what I get in the command window is this;

Columns 1 through 22:

142 181 173 162 165 178 96 175 166 96 165 172 165 173 165 174 180 179 96 142 96 125

61 32

I am very new to Octave so any help is appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清音悠歌 2025-02-10 08:20:41

函数 disp 不允许混合文本和值。这就是为什么输出是数字列表(可能是代码OS字符或其他内容)的原因。你可以分开
disp(“元素数n =”),disp(n)导致两行或使用其他功能作为printf printf(“元素数n =%d”,n)< /代码>将文本和值保持在同一行中。

The function disp does not allow mix text and values. That's the reason why the output are a list of numbers (probably codes os chars or something else). You could separate
disp("Number of elements N = "), disp(N) resulting in two lines or use others functions as printf printf("Number of elements N = %d", N) to keep text and value in the same line.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文