首页 > 编程语言 >数字信号处理作业 序列的卷积 实现 + MATLAB 源码

数字信号处理作业 序列的卷积 实现 + MATLAB 源码

时间:2024-06-20 10:58:07浏览次数:13  
标签:String see get 卷积 handles hObject 源码 MATLAB eventdata

实现有限长序列的基本运算(包括:加法、乘法、累加、移位、翻褶、抽取、插值、卷 积和),并以 GUI 的形式将这些运算整合起来,使用者可通过向 GUI 输入任意有限长序列得 到对应的运算结果。

  1. 加法:对两个序列中对应位置的元素进行相加,得到一个新的序列,要求两个序列的长度相同。

  2. 乘法:对两个序列中对应位置的元素进行相乘,得到一个新的序列,要求两个序列的长度相同。

  3. 累加:对序列中的元素进行累加操作,即将每个元素与其前面所有元素的和依次相加,得到一个新的序列。

  4. 移位:将序列中的元素按照指定的步长向左或向右移动,空出的位置用零或者其他指定的值填充。

  5. 翻褶:将序列中的元素顺序完全颠倒,即首尾对调。

  6. 抽取:从序列中按照指定的步长抽取元素,得到一个新的序列。

  7. 插值:在序列中插入新的元素,通常是在指定位置插入一个特定的值或者另一个序列。

  8. 卷积:对两个序列进行卷积操作,得到一个新的序列,常用于信号处理和图像处理中。

题目分析:

该题是对序列的各种数据操作,可根据“需要两个序列”还是“需要一个序列”可分为两类操作,第一类操作为“加法、乘法、卷积和”,需要接收两个序列,第二类操作为“累加、移位、翻褶、抽取、插值”。基本定义如下:

设计思路:

第一类:通过两个可编辑文本框获取两个序列,运用axes()与stem()将A和B两个序列以针状图的形式画在轴上,接下来在按钮中写回调函数,按下后判断文本框中序列元素个数是否相等,不相等则弹出警告,相等则继续进行操作。

加法和乘法直接用A+B和A.*B即可得到,卷积和运用conv()即可操作完毕;

第二类:累加,运用for循环或者cumsum函数即可完成功能。移位,运用randn生成一个移位的随机数,通过if判断随机数的正负来决定左移还是右移,然后通过矩阵合并一个零矩阵来实现矩阵的移位。翻褶,通过以y轴为对称轴左右翻转得到,可运用fliplr函数来进行该操作。抽取,接收抽取的n值后,运用for循环找符合要求的矩阵索引来合成一个新矩阵,即完成抽取的功能。插值,接收插入的n值后,新建一个空矩阵,运用一个for循环不断地将零向量、所求矩阵索引与该矩阵合并,最终得到符合要求的新矩阵。

代码

function varargout = untitled(varargin)
% UNTITLED MATLAB code for untitled.fig
%      UNTITLED, by itself, creates a new UNTITLED or raises the existing
%      singleton*.
%
%      H = UNTITLED returns the handle to a new UNTITLED or the handle to
%      the existing singleton*.
%
%      UNTITLED('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in UNTITLED.M with the given input arguments.
%
%      UNTITLED('Property','Value',...) creates a new UNTITLED or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before untitled_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to untitled_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
 
% Edit the above text to modify the response to help untitled
 
% Last Modified by GUIDE v2.5 09-Mar-2024 14:45:54
 
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @untitled_OpeningFcn, ...
                   'gui_OutputFcn',  @untitled_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end
 
if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
 
 
% --- Executes just before untitled is made visible.
function untitled_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to untitled (see VARARGIN)
 
% Choose default command line output for untitled
handles.output = hObject;
 
% Update handles structure
guidata(hObject, handles);
 
% UIWAIT makes untitled wait for user response (see UIRESUME)
% uiwait(handles.figure1);
 
 
% --- Outputs from this function are returned to the command line.
function varargout = untitled_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
 
% Get default command line output from handles structure
varargout{1} = handles.output;
function edit1_Callback(hObject, eventdata, handles)
% hObject    handle to edit1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
 
% Hints: get(hObject,'String') returns contents of edit1 as text
%        str2double(get(hObject,'String')) returns contents of edit1 as a double
 
 
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
 
% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
 
 
 
function edit2_Callback(hObject, eventdata, handles)
% hObject    handle to edit2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
 
% Hints: get(hObject,'String') returns contents of edit2 as text
%        str2double(get(hObject,'String')) returns contents of edit2 as a double
 
 
% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
 
% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
 
 
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
eval(“A=”+get(handles.edit1,'String'));
eval(“B=”+get(handles.edit2,'String'));
x=0:length(A)-1;
axes(handles.axes1);
stem(x,A);
axes(handles.axes2);
stem(x,B);
V=get(handles.popupmenu1,'Value');
if numel(A)==numel(B)
    switch V
        case 1
        C1=A+B;
        axes(handles.axes3);
        set(handles.text20,'String',num2str(C1));
        stem(x,C1)
        case 2
        axes(handles.axes3);
        C2=A.*B;
        stem(C2)
        set(handles.text20,'String',num2str(C2));
        case 3
        axes(handles.axes3);
        C3=conv(A,B);
        stem(C3);
             set(handles.text20,'String',num2str(C3))
    end
else
    msgbox('¶þÕßÔªËظöÊý²»Í¬','error','modal');
end
 
 
 
function edit3_Callback(hObject, eventdata, handles)
% hObject    handle to edit3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
 
% Hints: get(hObject,'String') returns contents of edit3 as text
%        str2double(get(hObject,'String')) returns contents of edit3 as a double
 
 
% --- Executes during object creation, after setting all properties.
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
 
% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
 
 
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
A2=str2num(get(handles.edit3,'String'));
x=0:1:length(A2)-1;
axes(handles.axes4);
stem(x,A2);
V=get(handles.popupmenu2,'Value');
switch V
    case 1
        C1=cumsum(A2);
        axes(handles.axes6);
        stem(x,C1);
        set(handles.text17,'String',num2str(C1))
    case 2
        axes(handles.axes6);
        r=round(randn()*10)
        if r>0
        x=zeros(1,r);
        C2=[x,A2];
        else
            r=-r;
            x=zeros(1,r);
            C2=[A2,x];
        end
        z=0:1:length(C2)-1;
         stem(z,C2);
        set(handles.text17,'String',num2str(A2))
    case 3
        axes(handles.axes6);
        x=0:1:length(A2)-1;
        x=-x;
        stem(x,A2);
        set(handles.text17,'String',num2str(fliplr(A2)))
    case 4
        ninput=inputdlg('ÇëÊäÈë³éÈ¡µÄ¼ä¸ôÊý');
        n=str2double(ninput);
        cqu=[];
        for i=1:n:length(A2)
            cqu=[cqu,A2(i)];
        end
         axes(handles.axes6);
        x=0:1:length(cqu)-1;
        stem(x,cqu);
        set(handles.text17,'String',num2str(cqu))
    case 5
        axes(handles.axes6)
        ninput=inputdlg('ÿÁ½µã¼ä²åÈë¶àÉÙ¸öÖµ')
        n=str2double(ninput);
         C5=A2(1);
 for i=2:1:length(A2)
     z=zeros(1,n);
     C5=[C5,z,A2(i)]
 end
 x=0:1:length(C5)-1;
        stem(x,C5);
 set(handles.text17,'String',num2str(C5));
end
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
 
 
% --- Executes on selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
 
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu1 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu1
 
 
% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
 
% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
 
 
% --- Executes on selection change in popupmenu2.
function popupmenu2_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
 
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu2 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu2
 
 
% --- Executes during object creation, after setting all properties.
function popupmenu2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
 
% Hint: popupmenu controls usually have a white background on Windows.

标签:String,see,get,卷积,handles,hObject,源码,MATLAB,eventdata
From: https://blog.csdn.net/mohen_777/article/details/139766089

相关文章

  • 数字信号处理之展示 z 变换与 s 变换之间的所有关系 +matlab 源码
    题目分析:要求z变换与s变换的关系,首先考虑z变换与s变换之间运用领域的不同,s域是连续时间表示域,使用连续的时间变量s表示信号的自变量,取值范围为复平面上的所有点。而z域是离散时间表示域,使用离散的时间变量z表示信号的自变量取值范围虽然也为复平面上的所有点,但对于离散信号而......
  • 基于小程序056大学生心理健康测试系统微信小程序项目(源码+文档+运行视频+讲解视频)
    前言......
  • 43、基于神经网络拟合函数的体脂估计(matlab)
    1、神经网络拟合函数的原理及流程神经网络拟合函数是一种基于人工神经元之间相互连接的模型,用来拟合复杂的非线性函数关系。其原理是通过多层次的神经元网络,每一层神经元通过激活函数将输入信号加权求和后输出,经过多次迭代优化权值,使得网络输出与实际值误差最小化。流程如下:......
  • 一种基于非线性滤波过程的旋转机械故障诊断方法(MATLAB)
    在众多的旋转机械故障诊断方法中,包络分析,又称为共振解调技术,是目前应用最为成功的方法之一。首先,对激励引起的共振频带进行带通滤波,然后对滤波信号进行包络谱分析,通过识别包络谱中的故障相关的特征频率,从而判断是否发生故障与故障的类型。然而,包络分析方法的主要难点在于共振频......
  • Java项目-基于SpringCloud+springboot+vue的分布式架构网上商城系统(源码+数据库+文档
    源码获取:https://download.csdn.net/download/u011832806/89440647基于SpringCloud+SpringBoot+Vue的分布式架构网上商城系统   开发语言:Java   数据库:MySQL   技术:SpringCloud+SpringBoot+MyBatis+Vue.js+eureka   工具:IDEA/Ecilpse、Navicat、Maven经......
  • Java项目-基于ssm+vue的大学生兼职跟踪系统(源码+数据库+文档)​
    如需完整项目,请私信博主基于ssm+Vue的大学生兼职跟踪系统开发语言:Java数据库:MySQL技术:Spring+SpringMVC+MyBatis+Vue.js工具:IDEA/Ecilpse、Navicat、Maven本文以Java为开发技术,实现了一个大学生兼职跟踪系统。大学生兼职跟踪系统的主要实现功能包括:管理员:首页、个人中心、商......
  • Java项目-基于springboot+vue的学习平台(源码+数据库+文档)​
    源码获取:https://download.csdn.net/download/u011832806/89456223基于SpringBoot+Vue的学习平台开发语言:Java数据库:MySQL技术:SpringBoot+MyBatis+Vue.js工具:IDEA/Ecilpse、Navicat、Maven在Internet高速发展的今天,我们生活的各个领域都涉及到计算机的应用,其中包括学习平台......
  • 基于Java+Vue前后端分离在线考试系统(源码+LW+PPT+部署教程)
    博主介绍:✌全网粉丝10W+平台特邀作者、博客专家、CSDN新星计划导师、java领域优质创作者,博客之星、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于毕业项目实战✌一、作品包含源码+数据库+设计文档LW+PPT+全套环境和工具资源+部署教程二、项目技术前端技术:Ht......
  • 基于SpringBoot的在线刷题小程序的设计与实现+附源码+数据库
     摘要:随着互联网技术的快速发展,在线教育平台逐渐成为学生学习和复习的重要工具。为了提高用户在学习过程中的效率和体验,本文提出并实现了一个基于SpringBoot的刷题小程序。该小程序旨在通过高效的题库管理、智能化的刷题功能以及友好的用户界面,帮助用户更好地进行知识点的......
  • 鸿蒙内核源码分析(内存汇编篇) | 谁是虚拟内存实现的基础
    ARM-CP15协处理器ARM处理器使用协处理器15(CP15)的寄存器来控制cache、TCM和存储器管理。CP15的寄存器只能被MRC和MCR(MovetoCoprocessorfromARMRegister)指令访问,包含16个32位的寄存器,其编号为0~15。本篇重点讲解其中的C7,C2,C13三个寄存器。先拆解一段汇编代码上来......