A list,

Using the MATLAB GUI design platform, using the window function method to design FIR digital filter, the given sound signal containing noise digital filtering processing, noise reduction sound signal, time domain frequency domain analysis, analysis of the effect of different window function.

Wav audio file function: Audioread (); (wavread) MATLAB playback music function: sound(); Wav audio file function: Audiowrite (); Add white noise to audiowrite: noise=(Max (x(:,1))/5)*randn(x,2); y=x+noise; Spectrum analysis: FFT (); Fftshift (); Fir filter: FIR1 (n,Wn,ftype,window); Window function selection: trapezoidal window Boxcar triang window Hamming window Hanning window Blackman window Kaiser window

3 Functions

The functions are as follows:

3.1 Opening files: Select a path to open waV audio files and automatically generate the original audio waveform and spectrum.

3.2 Adding noise: There are two kinds of noise you can choose to add, one is white noise, whose frequency spreads throughout the spectrum; One is the noise of a specific frequency, which can be added to the noise of a single frequency through the input frequency. After adding noise, automatically draw the waveform and spectrum after adding noise.

3.3 Filtering processing: First input the start frequency and cut-off frequency of the filter pass/stop band (for low/high-pass filtering, only input the start frequency; If the type is band pass/stop, the start and end must be entered. The input frequency value is the real frequency value, which can be judged according to the spectrum graph), then select the window function and filter type, and the waveform and spectrum after filtering will be generated.

3.4 Audio Play/Stop: original, noise-added and filtered audio can be played/stopped at any time.

3.5 Image export: Export waveform and spectrum images one by one and save them in JPG, PNG, BMP and EPS formats.

3.6 File Saving: Export and save the filtered audio.

Ii. Source code

function varargout = yanshou(varargin)
% YANSHOU M-file for yanshou.fig
%      YANSHOU, by itself, creates a new YANSHOU or raises the existing
%      singleton*.
%
%      H = YANSHOU returns the handle to a new YANSHOU or the handle to
%      the existing singleton*.
%
%      YANSHOU('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in YANSHOU.M with the given input arguments.
%
%      YANSHOU('Property'.'Value',...). creates anew YANSHOU or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before yanshou_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to yanshou_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 yanshou

% Last Modified by GUIDE v2. 5 23-Apr- 2020. 14:20:34

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @yanshou_OpeningFcn, ...
                   'gui_OutputFcn',  @yanshou_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 yanshou is made visible.
function yanshou_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 yanshou (see VARARGIN)

% Choose default command line output for yanshou
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes yanshou wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = yanshou_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;


% --- Executes on button press in open_pushbutton1.
function open_pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to open_pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global x; % file global Fs; % Sampling frequency global TL; global x2; [filename, pathname] = uigetfile('*.wav'.'Select Audio file');
if isequal(filename,0)
   disp('User selected Cancel')
else
   path = fullfile(pathname, filename);
   [handles.x,handles.Fs]=audioread(path);
   x=handles.x;
   Fs=handles.Fs;
   axes(handles.axes1);
   tl=[0:1/Fs:(length(handles.x)- 1)/Fs]; % time scale plot(tl,handles. X); title('Speech time domain waveform');
   xlabel('time/s');
   grid on;
   
   N=length(handles.x);
   df=Fs/N;
   w=[0:df:df*(N- 1)] - Fs/2; % X= FFT (handles. X); X=fftshift(X); axes(handles.axes2); plot(w,abs(X)/max(abs(X)));
   axis([- 10000..10000.0.1]);
   title('Speech spectrum');
   xlabel('frequency/Hz');
   grid on;
   x2=x;
end



% --- Executes on button press in play_pushbutton2.
function play_pushbutton2_Callback(hObject, eventdata, handles)
% hObject    handle to play_pushbutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global x2;
global Fs;
sound(x2,Fs);


% --- Executes on button press in add_pushbutton3.
function add_pushbutton3_Callback(hObject, eventdata, handles)
% hObject    handle to add_pushbutton3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global x;
global Fs;
global tl;
global x2;
axes(handles.axes1);
size(x);
t=0:1/Fs:(length(x)- 1)/Fs; % Adjust the points of the added noise signal to the same as the original signal Au=0.07;
fn =  get(handles.noise_edit2,'string'); % noise frequency fn = str2double(fn); noise=Au*cos(2*pi*fn*t)'; % noise is frequency x=x+noise; plot(tl,x); title('Speech time domain waveform after adding noise');
xlabel('Time/s');
grid on;
N=length(x);
df=Fs/N;
w=[0:df:df*(N- 1)] - Fs/2; % frequency scale X= FFT (X); X=fftshift(X); axes(handles.axes2); plot(w,abs(X)/max(abs(X)));
axis([- 10000..10000.0.1]);
title('Spectrum of speech after noise');
xlabel('frequency/Hz');
grid on;    
x2=x;

% --- Executes on button press in low_pushbutton5.
function low_pushbutton5_Callback(hObject, eventdata, handles)
% hObject    handle to low_pushbutton5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

global x;
global Fs;
global tl;
global x2;

x1=x;
% fp=1000;
% fs = 1000;
% Wp = 2*fp/Fs;
% Ws = 2*fs/Fs;
% if(Wp >= 1)
%     Wp = 0.99;
% end
% if(Ws >= 1)
%     Ws = 0.99;  
% end
fp =  get(handles.edit3,'string');     
fp = str2double(fp)*2;
if get(handles.radiobutton1,'value')
    [n, Wn]=buttord(Wp,Ws, 2.15);
    [b, a]=butter(n, Wn,'low');
    axes(handles.axes3);
    [h,w]=freqz(b,a);
    plot(w/pi*Fs/2.abs(h)); x1=filter(b,a,x1); % calls the function filterelseif get(handles.radiobutton4,'value')
    b2=fir1(30, fp/Fs, boxcar(31)); 
    axes(handles.axes3);
    [h,w]=freqz(b2, 1.512); 
    plot(w/pi*Fs/2.20*log(abs(h))); 
    x1=fftfilt(b2,x1);
    elseif get(handles.radiobutton5,'value')
    b2=fir1(30, fp/Fs, triang(31)); 
    axes(handles.axes3);
    [h,w]=freqz(b2, 1.512); 
    plot(w/pi*Fs/2.20*log(abs(h))); 
    x1=fftfilt(b2,x1);
    elseif get(handles.radiobutton6,'value')
    b2=fir1(30, fp/Fs, hamming(31)); 
    axes(handles.axes3);
    [h,w]=freqz(b2, 1.512); 
    plot(w/pi*Fs/2.20*log(abs(h))); 
    x1=fftfilt(b2,x1);
    elseif get(handles.radiobutton7,'value')
    b2=fir1(30, fp/Fs, hanning(31)); 
    axes(handles.axes3);
    [h,w]=freqz(b2, 1.512); 
    plot(w/pi*Fs/2.20*log(abs(h))); 
    x1=fftfilt(b2,x1);
    elseif get(handles.radiobutton8,'value')
    b2=fir1(30, fp/Fs, blackman(31)); 
    axes(handles.axes3);
    [h,w]=freqz(b2, 1.512); 
    plot(w/pi*Fs/2.20*log(abs(h))); 
    x1=fftfilt(b2,x1);
    elseif get(handles.radiobutton9,'value')
    b2=fir1(30,fp/Fs, kaiser(31)); 
    axes(handles.axes3);
    [h,w]=freqz(b2, 1.512); 
    plot(w/pi*Fs/2.20*log(abs(h))); 
    x1=fftfilt(b2,x1);
end;
axes(handles.axes5);
plot(tl,x1);
title('Speech time domain waveform after noise filtering');
xlabel('time/s');
N=length(x1);
df=Fs/N;
w=[0:df:df*(N- 1)] - Fs/2; % frequency scale X= FFT (x1); X=fftshift(X); axes(handles.axes6); plot(w,abs(X)/max(abs(X)));
axis([- 10000..10000.0.1]);
title('Spectrum of speech after noise exclusion');
xlabel('frequency/Hz');
grid on;
x2=x1;




% --- Executes during object creation, after setting all properties.
function low_pushbutton5_CreateFcn(hObject, eventdata, handles)
% hObject    handle to low_pushbutton5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called


% --- Executes on button press in pushbutton6.



function noise_edit2_Callback(hObject, eventdata, handles)
% hObject    handle to noise_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 noise_edit2 as text
%        str2double(get(hObject,'String')) returns contents of noise_edit2 as a double


% --- Executes during object creation, after setting all properties.
function noise_edit2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to noise_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 during object creation, after setting all properties.
function add_pushbutton3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to add_pushbutton3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called


% --- Executes on button press in guass_pushbutton8.
function guass_pushbutton8_Callback(hObject, eventdata, handles)
% hObject    handle to guass_pushbutton8 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global x;
global Fs;
global tl;
global x2;
N=length(x);
axes(handles.axes1);
%x = awgn(x,15);
noise=(max(x(:,1)) /5)*randn(N,2);
x=x+noise;
plot(tl,x);
title('Time domain waveform of speech after adding noise');
xlabel('time/s');
grid on;
Copy the code

3. Operation results

Fourth, note

Version: 2014