【语音处理】基于matlab GUI语音信号处理与滤波【含Matlab源码 1663期】

举报
海神之光 发表于 2022/05/29 01:24:31 2022/05/29
【摘要】 一、语音处理简介 语音信号的处理与滤波系统主要功能:录制一段自己的语音信号,并对录制的信号进行采样;画出采样后语音信号的时域波形和频谱图;给定滤波器的性能指标,采用窗函数法和双线性变换法设计滤波器,并画...

一、语音处理简介

语音信号的处理与滤波系统主要功能:录制一段自己的语音信号,并对录制的信号进行采样;画出采样后语音信号的时域波形和频谱图;给定滤波器的性能指标,采用窗函数法和双线性变换法设计滤波器,并画出滤波器的频率响应;然后用自己设计的滤波器对采集的信号进行滤波,画出滤波后信号的时域波形和频谱,并对滤波前后的信号进行对比,分析信号的变化;回放语音信号;换一个与你性别相异的人录制同样一段语音内容,分析两段内容相同的语音信号频谱之间有什么特点;再录制一段同样长时间的背景噪声叠加到你的语音信号中,分析叠加前后信号频谱的变化,设计一个合适的滤波器,能够把该噪声滤除。

二、部分源代码

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 16-Aug-2021 15:45:41

% 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 pushbutton1_Callback(hObject, eventdata, handles)
    set(handles.pushbutton1,'BackgroundColor',[0.545,0.753,0.988]);
    set(handles.pushbutton2,'BackgroundColor',[0.651,0.651,0.651]);
    set(handles.pushbutton3,'BackgroundColor',[0.651,0.651,0.651]);
    set(handles.pushbutton4,'BackgroundColor',[0.651,0.651,0.651]);
    set(handles.pushbutton5,'BackgroundColor',[0.651,0.651,0.651]);
    set(handles.pushbutton6,'BackgroundColor',[0.651,0.651,0.651]);
    set(handles.pushbutton7,'BackgroundColor',[0.651,0.651,0.651]);
    set(handles.pushbutton8,'BackgroundColor',[0.651,0.651,0.651]);
    fs = 8000;           % 采样频率
    duration = 4;        % 时间长度(秒) 
    % 创建一个录音文件:fs =8000Hz, 16-bit, 单通道
    voice = audiorecorder(fs, 16, 1);   
    recordblocking(voice, duration);   % 录音2秒钟
    stop(voice);
    y = getaudiodata(voice);
    ymax = max(abs(y));  % 归一化
    y = y/ymax;
    audiowrite('系统录音.wav',y,fs); % 存储录音文件

% 语音播放
function pushbutton2_Callback(hObject, eventdata, handles)
    set(handles.pushbutton2,'BackgroundColor',[0.545,0.753,0.988]);
    set(handles.pushbutton1,'BackgroundColor',[0.651,0.651,0.651]);
    set(handles.pushbutton3,'BackgroundColor',[0.651,0.651,0.651]);
    set(handles.pushbutton4,'BackgroundColor',[0.651,0.651,0.651]);
    set(handles.pushbutton5,'BackgroundColor',[0.651,0.651,0.651]);
    set(handles.pushbutton6,'BackgroundColor',[0.651,0.651,0.651]);
    set(handles.pushbutton7,'BackgroundColor',[0.651,0.651,0.651]);
    set(handles.pushbutton8,'BackgroundColor',[0.651,0.651,0.651]);
    fs = 8000;           % 采样频率
    duration = 4;        % 时间长度(秒) 
    n = duration*fs;     % 采样点数
    t = (1:n)/fs;
    y = audioread('系统录音.wav');  %读取音频10010000部分
    plot(handles.axes1,t,y);                          % 画出声音的时域波形图
    xlabel(handles.axes1,'时间/s');                   % x轴标题
    ylabel(handles.axes1,'相对信号强度');                     % y轴标题
    L = length(y);
    X=fft(y,L);
    A = fftshift(X);
    A=abs(A);
    ws = 2* pi* fs;
    w1 = (-ws/2 + (0:L-1) * ws/L)/(2 * pi);
    plot(handles.axes2,w1, abs(A)); 
    xlabel(handles.axes2,'频率/Hz');
    ylabel(handles.axes2,'幅度');
    clear sound
    sound(y);

% 语音滤波
function pushbutton3_Callback(hObject, eventdata, handles)
    set(handles.pushbutton3,'BackgroundColor',[0.545,0.753,0.988]);
    set(handles.pushbutton2,'BackgroundColor',[0.651,0.651,0.651]);
    set(handles.pushbutton1,'BackgroundColor',[0.651,0.651,0.651]);
    set(handles.pushbutton4,'BackgroundColor',[0.651,0.651,0.651]);
    set(handles.pushbutton5,'BackgroundColor',[0.651,0.651,0.651]);
    set(handles.pushbutton6,'BackgroundColor',[0.651,0.651,0.651]);
    set(handles.pushbutton7,'BackgroundColor',[0.651,0.651,0.651]);
    set(handles.pushbutton8,'BackgroundColor',[0.651,0.651,0.651]);
    fs = 8000;           % 采样频率
    duration = 4;        % 时间长度(秒) 
    n = duration*fs;     % 采样点数
    t = (1:n)/fs;
    y = audioread('系统录音.wav');
    L = length(y);
    ws = 2* pi* fs;
    w1 = (-ws/2 + (0:L-1) * ws/L)/(2 * pi);
    fs1 = str2double(get(handles.edit1,'String'));  %阻带下边界
    fsu = str2double(get(handles.edit3,'String'));  %阻带上边界
    fpl = str2double(get(handles.edit2,'String'));  %通带下边界
    fpu = str2double(get(handles.edit4,'String'));  %通带上边界 
    As = str2double(get(handles.edit5,'String'));  %阻带最小衰减
    Fs = str2double(get(handles.edit6,'String'));  %抽样频率
    if ( fs1 > 100 || fsu > 100 || fpl > 100 || fpu > 100 || Fs > 100 )
        %msgbox('单位:kHz,请重新输入','注意');
        ha=msgbox('默认单位:kHz,请重新输入 0 ~ 100','注意');
        % 设置显示字体大小和粗细
        hb = findobj(ha, 'Type', 'text');
        set(hb, 'FontSize', 16, 'FontUnit', 'normal','FontWeight','Bold');
        % 设置字体居中
        th = findall(0, 'Tag','MessageBox' );
        boxPosition = get(ha,'position');
        textPosition = get(th, 'position'); 
        set(th, 'position', [boxPosition(3).*1 textPosition(2) textPosition(3)]);
        set(th, 'HorizontalAlignment', 'center');
        set(ha,'position',[400 400 300 50]);% 使用这个语句可以修改msgbox的位置和大小
        return;
    end
    if ( As > 80 )
        %msgbox('As的范围为 0 ~ 80 ,请重新输入','注意');
        ha=msgbox('As的范围为 0 ~ 80 ,请重新输入','注意');
        % 设置显示字体大小和粗细
        hb = findobj(ha, 'Type', 'text');
        set(hb, 'FontSize', 16, 'FontUnit', 'normal','FontWeight','Bold');
        % 设置字体居中
        th = findall(0, 'Tag','MessageBox' );
        boxPosition = get(ha,'position');
        textPosition = get(th, 'position'); 
        set(th, 'position', [boxPosition(3).*1 textPosition(2) textPosition(3)]);
        set(th, 'HorizontalAlignment', 'center');
        set(ha,'position',[400 400 300 50]);% 使用这个语句可以修改msgbox的位置和大小
        return;
    end

  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177

三、运行结果

在这里插入图片描述

四、matlab版本及参考文献

1 matlab版本
2014a

2 参考文献
[1]韩纪庆,张磊,郑铁然.语音信号处理(第3版)[M].清华大学出版社,2019.
[2]柳若边.深度学习:语音识别技术实践[M].清华大学出版社,2019.
[3]宋云飞,姜占才,魏中华.基于MATLAB GUI的语音处理界面设计[J].科技信息. 2013,(02)

文章来源: qq912100926.blog.csdn.net,作者:海神之光,版权归原作者所有,如需转载,请联系作者。

原文链接:qq912100926.blog.csdn.net/article/details/122438950

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。