首页 技术 正文
技术 2022年11月14日
0 收藏 849 点赞 4,064 浏览 4070 个字

《DSP using MATLAB》Problem 5.24-5.25-5.26

《DSP using MATLAB》Problem 5.24-5.25-5.26

代码:

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 x1if length(x1) > N
error('N must be >= the length of x1 !')
end
%% Check for length of x2if length(x2) > N
error('N must be >= the length of x2 !')
endx1 = [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)

  运行结果:

《DSP using MATLAB》Problem 5.24-5.25-5.26

《DSP using MATLAB》Problem 5.24-5.25-5.26

代码:

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 !')
endx = [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 x1if 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 !')
endx1 = [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)

  运行结果:

《DSP using MATLAB》Problem 5.24-5.25-5.26

《DSP using MATLAB》Problem 5.24-5.25-5.26

代码:

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 !')
endx1 = [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

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,487
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,903
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,736
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,487
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,127
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,289