代码:

function y = circonvt(x1,x2,N)
%% N-point Circular convolution between x1 and x2: (time domain)
%% ------------------------------------------------------------------
%% [y] = circonvt(x1,x2,N)
%% y = output sequence containning the circular convolution
%% x1 = input sequence of length N1 <= N
%% x2 = input sequence of length N2 <= N
%%
%% N = size of circular buffer
%% Method: y(n) = sum( x1(m)*x2((n-m) mod N) )
%% Check for length of x1 if length(x1) > N
error('N must be >= the length of x1 !')
end
%% Check for length of x2 if length(x2) > N
error('N must be >= the length of x2 !')
end x1 = [x1 zeros(1,N-length(x1))];
x2 = [x2 zeros(1,N-length(x2))]; m = [0:1:N-1]; x2 = x2(mod_1(-m, N)+1); H = zeros(N,N);
for n = 1:1:N
H(n,:) = cirshftt(x2,n-1,N);
end
y = x1*conj(H'); % x1---row vector
% H
% y = H*x1'; % x1---column vector

  主程序:

%% +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
%% Output Info about this m-file
fprintf('\n***********************************************************\n');
fprintf(' <DSP using MATLAB> Problem 5.24 \n\n'); banner();
%% +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ % -------------------------------------------------------------------
%
% -------------------------------------------------------------------
N = 4;
n1 = [0:3];
x1 = [1, 2, 2]; x2 = [1, 2, 3, 4]; y1 = circonvt(x1, x2, N)

  运行结果:

代码:

function [C] = circulnt(x, N)
%% Circulant Matrix from an N-point sequence
%% ------------------------------------------------------------------
%% [C] = circulnt(x, N)
%% C = Circulant Matrix of size NxN
%% x = sequence of length <= N
%%
%% N = size of circulant matrix
if length(x) > N
error('N must be >= the length of x !')
end x = [x zeros(1, N-length(x))]; for i = 1 : N
c(i) = x(i);
end m = [0:1:N-1]; x_fold = x(mod_1(-m, N)+1);
r = x_fold; C = toeplitz(c,r);

  

function y = circonvt_v3(x1,x2,N)
%% N-point Circular convolution between x1 and x2: (time domain)
%% ------------------------------------------------------------------
%% [y] = circonvt(x1,x2,N)
%% y = output sequence containning the circular convolution
%% x1 = input sequence of length N1 <= N
%% x2 = input sequence of length N2 <= N
%%
%% N = size of circular buffer
%% Method: y(n) = sum( x1(m)*x2((n-m) mod N) )
%% Check for length of x1 if length(x1) > N
error('N must be >= the length of x1 !')
end
%% Check for length of x2
if length(x2) > N
error('N must be >= the length of x2 !')
end x1 = [x1 zeros(1,N-length(x1))];
x2 = [x2 zeros(1,N-length(x2))]; C = circulnt(x2, N); % m = [0:1:N-1]; x2 = x2(mod_1(-m, N)+1); H = zeros(N,N);
% for n = 1:1:N
% H(n,:) = cirshftt(x2,n-1,N);
% end
% y = x1*conj(H'); % x1---row vector y = C*x1'; % x1---column vector

  

%% +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
%% Output Info about this m-file
fprintf('\n***********************************************************\n');
fprintf(' <DSP using MATLAB> Problem 5.25 \n\n'); banner();
%% +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ % -------------------------------------------------------------------
%
% -------------------------------------------------------------------
N = 4;
n1 = [0:3];
x1 = [1, 2, 2]; x2 = [1, 2, 3, 4]; %C = circulnt(x2, 4); y1 = circonvt_v3(x1, x2, N)

  运行结果:

代码:

function x3 = circonvf(x1, x2, N)
%% N-point Circular convolution between x1 and x2: (frequency domain)
%% ------------------------------------------------------------------
%% [x3] = circonvf(x1,x2,N)
%% x3 = output sequence containning the circular convolution
%% x1 = input sequence of length N1 <= N
%% x2 = input sequence of length N2 <= N
%%
%% N = size of circular buffer
%% Method: x3(n) = IDFT[X1(k)X2(k)] %% Check for length of x1
if length(x1) > N
error('N must be >= the length of x1 !')
end
%% Check for length of x2
if length(x2) > N
error('N must be >= the length of x2 !')
end x1 = [x1 zeros(1,N-length(x1))];
x2 = [x2 zeros(1,N-length(x2))]; X1k_DFT = dft(x1, N);
X2k_DFT = dft(x2, N); x3 = real(idft( X1k_DFT.* X2k_DFT, N));

  

%% +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
%% Output Info about this m-file
fprintf('\n***********************************************************\n');
fprintf(' <DSP using MATLAB> Problem 5.26 \n\n'); banner();
%% +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ % -------------------------------------------------------------------
%
% -------------------------------------------------------------------
N = 4;
n1 = [0:3];
x1 = [4,3,2,1];
%x1 = [1,2,2]; n2 = [0:3];
x2 = [1, 2, 3, 4]; %C = circulnt(x2, 4); y1 = circonvf(x1, x2, N)

  运行结果:

《DSP using MATLAB》Problem 5.24-5.25-5.26的更多相关文章

  1. 《DSP using MATLAB》Problem 7.24

    又到清明时节,…… 注意:带阻滤波器不能用第2类线性相位滤波器实现,我们采用第1类,长度为基数,选M=61 代码: %% +++++++++++++++++++++++++++++++++++++++ ...

  2. 《DSP using MATLAB》Problem 6.24

    代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...

  3. 《DSP using MATLAB》Problem 4.24

    Y(z)部分分式展开, 零状态响应部分分式展开, 零输入状态部分分式展开,

  4. 《DSP using MATLAB》Problem 6.15

    代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...

  5. 《DSP using MATLAB》Problem 6.8

    代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...

  6. 《DSP using MATLAB》Problem 4.15

    只会做前两个, 代码: %% ---------------------------------------------------------------------------- %% Outpu ...

  7. 《DSP using MATLAB》Problem 2.16

    先由脉冲响应序列h(n)得到差分方程系数,过程如下: 代码: %% ------------------------------------------------------------------ ...

  8. 《DSP using MATLAB》 Problem 2.3

    本题主要是显示周期序列的. 1.代码: %% ------------------------------------------------------------------------ %% O ...

  9. 《DSP using MATLAB》Problem 7.29

    代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...

随机推荐

  1. shell shell基本概述

    SHELL的概念 SHELL是一个命令行解释器,它为用户提供了一个向Linux内核发送请求以便运行程序的界面系统级程序, 用户可以用shell来启动,挂起,停止甚至是编写一些程序. ​ Shell还是 ...

  2. day24-python操作数据库四

    #!/usr/bin/env python # -*- coding:utf-8 -*- # @time: 2017/11/23 23:10 # Author: caicai # @File: dem ...

  3. RabbitMQ Dead Lettering(死信)

    死信,顾名思义,就是死掉的消息,死掉的消息是会被一般的队列丢弃的.如果这些消息很重要,而我们又需要,怎么办?凡事都有一个退路,现在就有一种方法可将这些死信消息存下来,那就是DLX(Dead Lette ...

  4. MeshLab 编译

    1.需要以下:  MeshLab 1.3.3  下载地址 http://sourceforge.net/projects/meshlab/files/meshlab Win7 X64  Visual ...

  5. js 将文本转换为数据 string number

    <span class="Span" > <p>123.81</p> <a> dejiw</a> </span&g ...

  6. Centos7部署kubelet(六)

    1.二进制包准备将软件包从linux-node1复制linux-node2.linux-node3中去 [root@linux-node1 ssl]# cd /usr/local/src/kubern ...

  7. Aimbat安装

    1:Pysmo下的sac和aimbat需要放在和前面的toolkits 相同的地方,Python就能找到: 在安装obspy时,需要装yum-plugin-copr; 方法在网址: https://c ...

  8. shell脚本实例-实现监控tcp的链接状态另一种方式批量创建用户

    Array实现TCP的链接状态 #!/usr/bin/bash declare -A status type=`ss -an | grep :80|awk '{print $2}'` for i in ...

  9. PHPexcel 导入import 数据到 mysql: mysql 查询数据是否存在, 如果存在返回id, 不存在, 插入返回id. 2) mysql_query , mysql_connect, mysql_select_db, mysql_error, mysql_num_rows,mysql_close

    一: 要求: 上面的图表 中的数据插入到 3张表中. 1)t_vide_warehourse 分类表: 此表中包含 一级分类 和二级分类.  二级分类是一级分类的子级. 2)t_video_info  ...

  10. python django字段类型

    <1> CharField #字符串字段, 用于较短的字符串. #CharField 要求必须有一个参数 maxlength, 用于从数据库层和Django校验层限制该字段所允许的最大字符 ...