Matlab - Ayuda con proyecto de procesamiento de señales de audio en Matlab

 
Vista:
sin imagen de perfil
Val: 1
Ha aumentado su posición en 7 puestos en Matlab (en relación al último mes)
Gráfica de Matlab

Ayuda con proyecto de procesamiento de señales de audio en Matlab

Publicado por Mario (1 intervención) el 28/11/2019 03:00:08
Hola programadores, hoy les solicito ayuda puesto que tengo el proyecto final del curso de procesamiento digital de señales de audio y estoy estancado en uno de los puntos.

Requiero diseñar un programa el cual tiene almacenado un archivo de audio, el programa debe captar sonido a través del micrófono del PC y debe poder detectar si en el sonido captado a través del micrófono se encuentra o no el sonido que tenía almacenado.

La idea sería captar el audio usando el micrófono (Ya logré hacer esto) y compararlo con el audio almacenado usando correlación cruzada (Es lo que no he logrado) y a través de la correlación determinar si las señales son o no similares.

dejo a disposición el código que llevo hasta el momento, además de una captura de pantalla de la interfaz.

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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
function varargout = punto_5(varargin)
% PUNTO_5 MATLAB code for punto_5.fig
%      PUNTO_5, by itself, creates a new PUNTO_5 or raises the existing
%      singleton*.
%
%      H = PUNTO_5 returns the handle to a new PUNTO_5 or the handle to
%      the existing singleton*.
%
%      PUNTO_5('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in PUNTO_5.M with the given input arguments.
%
%      PUNTO_5('Property','Value',...) creates a new PUNTO_5 or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before punto_5_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to punto_5_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 punto_5

% Last Modified by GUIDE v2.5 22-Nov-2019 21:06:49

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @punto_5_OpeningFcn, ...
                   'gui_OutputFcn',  @punto_5_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 punto_5 is made visible.
function punto_5_OpeningFcn(hObject, eventdata, handles, varargin)
axes(handles.axes1);xlabel('tiempo'); ylabel('y(t)');title('SEÑAL ORIGINAL');grid on;
axes(handles.axes3);xlabel('frecuencia'); ylabel('amplitud');title('SEÑAL FILTRADA'); grid on;
%%----------------------PARA LOGO---------------------------%%
%axes(handles.axes4)
%matlabImage = imread('C:\Users\Daniel\Documents\MATLAB\proyecto_f\proyecto_DSP/lauao.png');
%image(matlabImage)
%axis off
%axis image
 
handles.output = hObject;
 
% Update handles structure
guidata(hObject, handles);
 
% UIWAIT makes punto_5 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
 
 
% --- Outputs from this function are returned to the command line.
function varargout = punto_5_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 pushbutton1.
function grabar_en_vivo_Callback(hObject, eventdata, handles)
recObj = audiorecorder;
% disp('Start speaking.'); recordblocking(recObj, 5); disp('End of Recording.');
set(handles.text1, 'String', 'hable ahora');
% play(recObj);
% audi = getaudiodata(recObj);
% plot(audi);
% 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)
 
 
 
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
 
 
%%--------------------------BOTON GRABAR------------------------------%%
function pushbutton2_Callback(hObject, eventdata, handles)
 
Fs=44100;
duracion=6;
 
recObj = audiorecorder(Fs,16,1);
set(handles.text3, 'ForegroundColor','red'); % cambia color texto
set(handles.text3, 'String', 'GRABANDO...'); % primer texto despues de presionar el boton
recordblocking(recObj, duracion); % grabando audio microfono
set(handles.text3, 'String', 'FIN GRABACIÓN'); % segundo texto despues de presionar el boton
audi = getaudiodata(recObj);
audiowrite('sonido_grabado.wav',audi, Fs );
axes(handles.axes1);xlabel('tiempo'); ylabel('y(t)');title('SEÑAL ORIGINAL');grid on;
plot(audi);
 
 
 
%%------------------------------BOTON CERRAR------------------------------%%
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
 
close punto_5;
 
 
 
%%-----------------------BOTON PLAY SEÑAL ORIGINAL---------------------------%%
% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
[z1,Fs] = audioread('sonido_grabado.wav');
soundsc(z1,Fs);
plot(handles.axes1,z1);
axes(handles.axes1);;xlabel('tiempo'); ylabel('y(t)');title('SEÑAL ORIGINAL');grid on;
 
 
%%-----------------------BOTON FFT---------------------------%%
function pushbutton5_Callback(hObject, eventdata, handles)
[z2,Fs] = audioread('sonido_grabado.wav');
info = audioinfo('sonido_grabado.wav');
plot(handles.axes3,abs(fft(z2)));
axes(handles.axes3);;xlabel('frecuencia'); ylabel('amplitud');title('SEÑAL CON FFT'); grid on;
 
 
%%-----------------------BOTON PLAY SEÑAL FFT---------------------------%%
function pushbutton6_Callback(hObject, eventdata, handles)
[z2,Fs] = audioread('sonido_grabado.wav');
info = audioinfo('sonido_grabado.wav');
nBits = 16;
soundsc(z2,Fs,nBits);
 
 
 
%%-----------------------BOTON CORRELACIONAR---------------------------%%
 
function pushbutton7_Callback(hObject, eventdata, handles)
[z2,Fs] = audioread('sonido_grabado.wav');
info = audioinfo('sonido_grabado.wav');
[z3,Fs1] = audioread('ID_audiencia.wav');
info3 = audioinfo('ID_audiencia.wav');
c = xcorr(z2,z3);
cn=c./max(c);
plot(handles.axes5, cn);
axes(handles.axes5);xlabel('frecuencia'); ylabel('amplitud');title('SEÑAL CORRELACIONADA'); grid on;
valor_max=max(cn);
 
if valor_max ==1
set(handles.text15, 'String', '1 oyente');
else set(handles.text15, 'String', 'se putio');
end
 
% hObject    handle to pushbutton7 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
 
 
% --- Executes on button press in togglebutton1.
function togglebutton1_Callback(hObject, eventdata, handles)
% hObject    handle to togglebutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
 
% Hint: get(hObject,'Value') returns toggle state of togglebutton1
 
 
% --- Executes on button press in pushbutton8.
function pushbutton8_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton8 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
 
 
% --------------------------------------------------------------------
function Untitled_2_Callback(hObject, eventdata, handles)
% hObject    handle to Untitled_2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
 
 
% --------------------------------------------------------------------
function Untitled_3_Callback(hObject, eventdata, handles)
% hObject    handle to Untitled_3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


Captura
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder