• 注册 / 登录
  • 切换到窄版
  • 查看: 2336|回复: 0

    傅里叶3D可视化绘图技巧

    [复制链接]

    676

    主题

    690

    帖子

    6808

    积分

    版主

    Rank: 7Rank: 7Rank: 7

    积分
    6808
    发表于 2024-4-1 13:44:35 | 显示全部楼层 |阅读模式

    路线栈欢迎您!

    您需要 登录 才可以下载或查看,没有帐号?立即注册

    x
    三维数据可视化为学习者提供直观影像,应用广泛。3D折线图旨在展示三维空间的曲线分布,采用MATLAB函数plot3。与二维折线绘制plot函数的差异在于,需要设定x,y,z方向坐标向量,其他绘图属性两者基本一致。与之类似的还有3D散点图scatter3,3D杆状图stem3等。

    下面,我们以傅里叶级数展开(Fourier series expansion)3D可视化作为代码示例。

    1. clc; clear; close all;
    2. %----------------------
    3. m = 15; % Series
    4. N = 512; % Period
    5. T0 = 4;
    6. T = 2;
    7. t1 = linspace(-T/2, T/2, N);
    8. t2 = linspace(T/2, T0-T/2, N);
    9. t = [(t1-T0)'; (t2-T0)'; t1'; t2'; (t1+T0)'];
    10. %----------------------
    11. % Construct periodic signals
    12. %----------------------
    13. % s = zeros(5*N,1);
    14. % s(1:N)=1; s(2*N+1:3*N)=1; s(4*N+1:5*N)=1;
    15. s = [ones(N,1);zeros(N,1);ones(N,1);zeros(N,1);ones(N,1)]';
    16. y = zeros(m+1, length(s));
    17. y(m+1,:) = s-0.5;
    18. plot3(t-(t+2), t, y(m+1,:),'LineWidth',2); % Period square wave
    19. hold on;
    20. axis([-2,m+1,-T0-1,T0+1,-1,2])
    21. set(gca,'XTick',-T0-1:2:m);
    22. set(gca,'YTick',-T0-1:1:T0+1);
    23. set(gca,'ZTick',-1:0.5:T0);
    24. title('Fourier series expansion','FontSize',15);
    25. grid on;
    26. view(-49,23)
    27. fsamp = 1028;
    28. f = linspace(1, m+1, fsamp);
    29. A = 0.5; % Coefficient
    30. freq = 1:1:m;
    31. plot3(f,T0+f-f+1,A*sinc(A*f)*5,'LineWidth',3)
    32. mag = A*sinc(A*freq)*5;
    33. h=stem3(freq,T0+freq-freq+1,mag,'filled','LineWidth',3);
    34. set(h,'Marker','o',...   
    35. 'MarkerFaceColor','g')
    36. x = A*ones(size(t));%  Harmonic signals
    37. X = A*ones(size(t));% Synthesis signals
    38. for k = 1:m
    39. x = 2*A*sinc(A*k)*cos(2*pi*t*k/T0);
    40. X = X+2*A*sinc(A*k)*cos(2*pi*t*k/T0);
    41. y(k, :) = x;
    42. plot3(k+t-t, t, y(k,:),'LineWidth',1.5); % Harmonic
    43. end
    44. plot3(k+1+t-t, t, X-0.5,'LineWidth',2);
    45. grid on;
    46. xlabel('Frequency view','Rotation', 15);
    47. ylabel('Time duration','Rotation', -10);
    48. zlabel('Amplitude/Magnitude');
    49. set(gcf,'Color','White');  % Background is white
    50. %----------------------
    复制代码

    程序运行如图-1所示。

    1711944076202.jpg
    图-1 傅里叶级数展开的三维可视化

    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    小黑屋|路丝栈 ( 粤ICP备2021053448号 )

    GMT+8, 2024-12-22 14:52 , Processed in 0.043693 second(s), 21 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2021, Tencent Cloud.

    快速回复 返回顶部 返回列表