zoukankan      html  css  js  c++  java
  • [Matlab] 线性卷积&圆周卷积代码实现

    1、线性卷积 周期卷积 圆周卷积的 关系:

    2、Matlab实验及现象

    圆周卷积:

     1 %% 圆周卷积实例程序
     2 %% Alimy 2014年11月21日 20:19:12
     3 clc;
     4 clear;
     5 %%准备数据
     6 N = 5;
     7 M = 5;
     8 L = N + M -1;
     9 x1n = [1,2,3,4,5];
    10 x2n = [1,5,9,7,3];
    11 kn_x1 = 0:1:N-1;
    12 kn_x2 = 0:1:M-1;
    13 kn_y = 0:1:L-1;
    14 %%画原始有限长序列
    15 subplot(4,2,1);
    16 stem(kn_x1,x1n);
    17 xlabel('n','FontSize',15);
    18 ylabel('x1n','FontSize',15);
    19 subplot(4,2,2);
    20 stem(kn_x2,x2n);
    21 xlabel('n','FontSize',15);
    22 ylabel('x2n','FontSize',15);
    23 
    24 x1n_t = [x1n, zeros(1,L-N)];  %%补零
    25 x2n_t = [x2n, zeros(1,L-M)];
    26 kn_x1t = 0:1:(N+M-1)-1;
    27 kn_x2t = 0:1:(N+M-1)-1;
    28 %%画补0后序列
    29 subplot(4,2,3);
    30 stem(kn_x1t,x1n_t);
    31 xlabel('n','FontSize',15);
    32 ylabel('x1n补0后','FontSize',15);
    33 subplot(4,2,4);
    34 stem(kn_x2t,x2n_t);
    35 xlabel('n','FontSize',15);
    36 ylabel('x2n补0后','FontSize',10);
    37 
    38 x1n_t = [x1n_t,x1n_t,x1n_t,x1n_t];    %沿拓
    39 x1n_t = fliplr(x1n_t);                %翻转 
    40 [x1t_x,x1t_y] = size(x1n_t);
    41 x1t_numbers = x1t_x * x1t_y;
    42 kn_x1t = -17:1:18;
    43 %%画沿拓翻转后的周期序列
    44 subplot(4,2,5);
    45 stem(kn_x1t,x1n_t);
    46 xlabel('t','FontSize',15);
    47 ylabel('x1n_t补0后再沿拓翻转后','FontSize',10);
    48 
    49 x2n_t = [zeros(1,L),zeros(1,L),x2n_t,zeros(1,L)];
    50 kn_x2t = -18:1:17;
    51 subplot(4,2,6);
    52 stem(kn_x2t,x2n_t);
    53 xlabel('t','FontSize',15);
    54 ylabel('x2n_t补0后 沿拓翻转后','FontSize',15);
    55 
    56 
    57 %%  乘 加 移位
    58 yn = zeros(1,2*L);
    59 for I = 1:1:18
    60     x1n_t = circshift(x1n_t,[0,1]);
    61     yn(I) = x2n_t*x1n_t';
    62 end
    63 
    64 kn_yn = 0:1:2*(N+M-1)-1;
    65 subplot(4,2,7);
    66 stem(kn_yn,yn);
    67 xlabel('n','FontSize',15);
    68 ylabel('圆周卷积结果','FontSize',15);
    69 
    70 %%取主值序列
    71 ynmain = zeros(1,L);
    72 for I = 1:1:9
    73     ynmain(I) = yn(I);
    74 end
    75 kn_ynm = 0:1:8;
    76 subplot(4,2,8);
    77 stem(kn_ynm,ynmain)
    78 xlabel('n','FontSize',15);
    79 ylabel('主值序列','FontSize',15);
    80 
    81 %% 
    cycleConv.m

    线性卷积:

     1 %% 线性卷积 
     2 clc;
     3 clear;
     4 %%
     5 N = 5;
     6 M = 5;
     7 L = N + M - 1;
     8 x1n = [1,2,3,4,5];
     9 kx1 = 0:1:N-1;
    10 x2n = [1,5,9,7,3];
    11 kx2 = 0:1:M-1;
    12 
    13 %% 线性卷积
    14 yn = conv(x1n,x2n);
    15 kyn = kx1(1)+kx2(1):1:kx1(end)+kx2(end);  % 0:1:(N+M-1)-1
    16 
    17 %% 循环卷积   To do 2014年11月20日 15:25:36 循环卷积怎么做
    18 
    19 %% 画图
    20 subplot(2,2,1);
    21 stem(kx1,x1n);
    22 xlabel('n');
    23 ylabel('x1n');
    24 title('信号1');
    25 
    26 subplot(2,2,2);
    27 stem(kx2,x2n);
    28 xlabel('n');
    29 ylabel('x1n');
    30 title('信号2');
    31 
    32 subplot(2,2,3);
    33 stem(kyn,yn);
    34 xlabel('n');
    35 ylabel('yn');
    36 title('线性卷积结果');
    37 yn   %%  1     7    22    44    69    88    82    47    15
    linConv.m

    结果如下:

    当 L = N + M -1时,圆周卷积和线性卷积的结果一致:

    yn =

    1 7 22 44 69 88 82 47 15

    圆周卷积:

    线性卷积:

    ~不再更新,都不让我写公式,博客园太拉胯了
  • 相关阅读:
    2020.10.08 模拟赛 题解
    可爱路径 题解
    飞行路线 题解2
    架设电话线 题解
    浅谈 LCA
    浅谈 Tarjan 算法之强连通分量(危
    初赛题目整理1
    【求助,待续!】holes
    【题解】HDU4467
    【题解】zhx154嬲
  • 原文地址:https://www.cnblogs.com/alimy/p/4113668.html
Copyright © 2011-2022 走看看