配套的讲解视频详见数字信号处理7-1_卷积的Matlab实现_哔哩哔哩_bilibili,数字信号处理7-2_利用Matlab求解系统响应_哔哩哔哩_bilibili,数字信号处理7-3_相关运算的Matlab实现_哔哩哔哩_bilibili
(1)Matlab求解卷积的实例代码如下:
%% //数字信号第3个Matlab编程实例:卷积,系统响应及两个信号的相关运算
%% //作者:gc_yang 小杨小Young
%% //日期:2022年1月15日
%% //初始设置
% 清空工作空间,关闭无关页面
clc,clear,close all;
% 绘图变量
font_size = 12; axis_size = 10; line_width = 2; legend_size = 12; marker_size = 6;
figure_width = 14; figure_height = 8; BiaValue = 0;
%% //卷积-离散时间形式
% 信号x1
n1 = 0 : 1 : 10;
x1 = sin(2*pi*(1/10)*n1);
% 信号x2
n2 = 0 : 1 : 4;
x2 = [1.0, 0.8, 1.2, -1.0, 0.5];
% 卷积的结果
N = length(n1) + length(n2) - 1;
n = 0 : 1 : N-1;
y = conv(x1, x2);
%% 绘图
figure
set(gcf,'Unit','centimeters','Position',[3 3 3+figure_width 3+figure_height]);
set(gca,'LooseInset',get(gca,'TightInset')+[BiaValue,0,0,0],'FontName','Times New Roman','FontSize',font_size);
stem(n1, x1, 'b-', 'LineWidth', line_width)
set(gca,'FontSize',font_size,'FontName','Times New Roman')
xlim([0 10])
ylim([-1.6 1.6])
set(gca,'XTick',0 : 2 : 10)
set(gca,'YTick',-1.6 : 0.8 : 1.6)
xlabel('节拍', 'FontSize', font_size, 'FontName', 'Times New Roman')
ylabel('信号幅值', 'FontSize', font_size, 'FontName', 'Times New Roman')
title('离散时间信号x1[n]', 'FontSize', font_size*1.5, 'FontName', 'Times New Roman')
figure
set(gcf,'Unit','centimeters','Position',[3 3 3+figure_width 3+figure_height]);
set(gca,'LooseInset',get(gca,'TightInset')+[BiaValue,0,0,0],'FontName','Times New Roman','FontSize',font_size);
stem(n2, x2, 'b-', 'LineWidth', line_width)
set(gca,'FontSize',font_size,'FontName','Times New Roman')
xlim([0 4])
ylim([-1.6 1.6])
set(gca,'XTick',0 : 1 : 4)
set(gca,'YTick',-1.6 : 0.8 : 1.6)
xlabel('节拍', 'FontSize', font_size, 'FontName', 'Times New Roman')
ylabel('信号幅值', 'FontSize', font_size, 'FontName', 'Times New Roman')
title('离散时间信号x2[n]', 'FontSize', font_size*1.5, 'FontName', 'Times New Roman')
figure
set(gcf,'Unit','centimeters','Position',[3 3 3+figure_width 3+figure_height]);
set(gca,'LooseInset',get(gca,'TightInset')+[BiaValue,0,0,0],'FontName','Times New Roman','FontSize',font_size);
stem(n, y, 'b-', 'LineWidth', line_width)
set(gca,'FontSize',font_size,'FontName','Times New Roman')
xlim([0 14])
ylim([-3 3])
set(gca,'XTick',0 : 2 : 14)
set(gca,'YTick',-3 : 1.5 : 3)
xlabel('节拍', 'FontSize', font_size, 'FontName', 'Times New Roman')
ylabel('信号幅值', 'FontSize', font_size, 'FontName', 'Times New Roman