zoukankan      html  css  js  c++  java
  • 《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 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('
    ***********************************************************
    ');
    fprintf('        <DSP using MATLAB> Problem 5.24 
    
    ');
    
    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('
    ***********************************************************
    ');
    fprintf('        <DSP using MATLAB> Problem 5.25 
    
    ');
    
    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('
    ***********************************************************
    ');
    fprintf('        <DSP using MATLAB> Problem 5.26 
    
    ');
    
    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)
    

      运行结果:

    牢记: 1、如果你决定做某事,那就动手去做;不要受任何人、任何事的干扰。2、这个世界并不完美,但依然值得我们去为之奋斗。
  • 相关阅读:
    MongoDB Schema Design
    WinDBG中的poi是做什么用的?
    如何在Visual Studio中运行和调试汇编代码?
    [翻译图书] 未完工 Moving Applications to the Cloud on the Microsoft Windows Azure Platform 4
    在Word中生成随机的样本文本
    Quiz Win32内存表示与数值大小
    rep stos dword ptr es:[edi] 是做什么的?
    Windows Azure中虚拟机无法启动, 报错RoleStateUnknown的解决方案
    COM基础介绍
    64位的dump里如何寻找第一个到第四个参数?
  • 原文地址:https://www.cnblogs.com/ky027wh-sx/p/9457086.html
Copyright © 2011-2022 走看看