代码:

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. u-boot的内存分布

    cpu会自动从NAND flash 中读取前4KB的数据放置在片内SRAM里(s3c2440是soc),同时把这段片内SRAM映射到nGCS0片选的空间(即0x00000000).cpu是从0x000 ...

  2. 回溯算法 LEETCODE别人的小结 一八皇后问题

    回溯算法实际上是一个类似枚举的搜索尝试过程,主要是在搜索尝试中寻找问题的解,当发现已不满足求解条件时,就回溯返回,尝试别的路径. 回溯法是一种选优搜索法,按选优条件向前搜索,以达到目的.但是当探索到某 ...

  3. day10-高阶函数

    高阶函数 高阶函数:就是把函数当成参数传递的一种函数,例如: def add(x,y,f): return f(x)+f(y) print(add(-8,11,abs)) 结果: 19 解释: 调用a ...

  4. asp.net webapi 返回json结果的方法

    第一种: public static void Register(HttpConfiguration config) { //1.将默认的xml格式化程序清除 GlobalConfiguration. ...

  5. C++11新特性,bind,基于对象

    body, table{font-family: 微软雅黑; font-size: 10pt} table{border-collapse: collapse; border: solid gray; ...

  6. node 慕课笔记

    global global.testVar2 = 200; 在别的文件中可以任意调用到 因为global是全局变量相当于js的window一样的

  7. sas 变量类型转换

    data b2: set b1; newbl=put(oldbl,10.); run; 根据转换后的类型灵活填写

  8. ASPNET MVC5 根 core

    Asp.Net Core MVC的开源地址:https://github.com/aspnet/Mvc Asp.net MVC的开源地址:http://aspnetwebstack.codeplex. ...

  9. 7.3 C++模板中的函数式参数

    参考:http://www.weixueyuan.net/view/6400.html 总结: 模板类至少有一个类参数,但是可以有多个参数,这些参数中可以存在非类类型的参数. 类参数是指 class ...

  10. GDI中StretchBlt或Blt缩放图片失真问题

    在用Scrollview控件的缩放图片时,严重失真: 解决方法:dc.SetStretchBltMode(COLORONCOLOR). 参考文章:https://blog.csdn.net/m3728 ...