理想方波-傅里叶变换、频谱

clear
clc

f=1e9;   %1GHz;
t=0:0.02e-9:5e-9;   %5ns

w1=2*pi*f;

f2=0:1e9:50e9;  %从0HZ到50ghz,每次增加1GHZ
w2=2*pi*f2;

ft=square(w1*t);
subplot(3,2,1);
plot(t*1e9,ft);
ylim([-1.5,1.5]);
xlabel('时间/ns');
ylabel('幅值/V');
title('理想1GHz方波(时域)');



for j=1:length(w2)-1


    s1=sin(w2(j)*t);      %sinwt

    subplot(3,2,3);
    plot(t*1e9,s1);
    xlim([0,5]);
    ylim([-1.5,1.5]);
    xlabel('时间/ns');
    ylabel('幅值/V');
    title(sprintf('sinwt f=%d GHz',(f2(j)/1e9)));

    pause(0.01);


    c2=cos(w2(j)*t);    %coswt
    subplot(3,2,5);
    plot(t*1e9,c2);
    xlim([0,5]);
    ylim([-1.5,1.5]);
    xlabel('时间/ns');
    ylabel('幅值/V');
    title(sprintf('coswt f=%d GHz',(f2(j)/1e9)));
    pause(0.01);


    im1=ft.*s1;  %虚部f(t)*sinwt

    re1=ft.*c2; %实部f(t)*coswt

    g1=@(t) square(w1*t).*sin(w2(j)*t); %虚部积分
    q1=integral(g1,0,1);
    subplot(3,2,4);
    hold on;
    scatter(((f2(j)/1e9)),q1,10,'red','filled');
    yline(0, '--', 'Color', 'black', 'LineWidth', 1); % 红色虚线,线宽1.5
    xlabel('频率/GHz');
    ylabel('积分');
    title('虚部积分');

    g2=@(t) square(w1*t).*cos(w2(j)*t); %实部积分
    q2=integral(g2,0,1);
    subplot(3,2,6);
    hold on;
    scatter(((f2(j)/1e9)),q1,10,'red','filled');
    yline(0, '--', 'Color', 'black', 'LineWidth', 1); % 红色虚线,线宽1.5
    xlabel('频率/GHz');
    ylabel('积分');
    title('实部积分');

    subplot(3,2,2);  %模
    s=sqrt(q1^2+q2^2);
    hold on;
    scatter(((f2(j)/1e9)+1),s,10,'red','filled');
    yline(0, '--', 'Color', 'black', 'LineWidth', 1); % 红色虚线,线宽1.5
    xlabel('频率/GHz');
    ylabel('模');
    title('模');
end


可以看出在目标频率1GHz处,存在峰值。
理想方波只有奇次谐波,偶次谐波的谐波分量为0,0GHz的频率分量为0,也就是直流分量为0.

赞赏