Spectrogram plotting (giving me errors) using GUI (guide)

Hello, i am trying to plot spectrogram of audio signal from microphone at real time, here is the code:
function varargout = sp(varargin)
% Last Modified by GUIDE v2.5 15-Jul-2011 12:49:33
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @sp_OpeningFcn, ...
'gui_OutputFcn', @sp_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 sp is made visible.
function sp_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 sp (see VARARGIN)
% Choose default command line output for sp
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% My coded part
daq_object = analoginput('winsound');
chan = addchannel(daq_object,[1 2]);
num_samples=1000;
axes(handles.axes1);
phandle= spectrogram(zeros(num_samples,1));
handles.daq_object=daq_object;
handles.phandle=phandle;
handles.num_samples=num_samples;
guidata(hObject,handles);
set(daq_object,'SamplesPerTrigger',inf,'SamplesAcquiredFcnCount',num_samples,...
'SamplesAcquiredFcn',{@update_plot,handles});
% End of my coded part (more in the start call back and
% update_plot function.
% UIWAIT makes sp wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = sp_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 start.
function start_Callback(hObject, eventdata, handles)
% hObject handle to start (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% My coded part
if(strcmp(handles.daq_object.running,'On'))
return;
else
start(handles.daq_object);
end
% My coded end
% My coded part
function update_plot(hObject, eventdata, handles)
data=getdata(handles.daq_object,handles.num_samples);
for i=1:length(handles.phandle)
set(handles.phandle(i),'YData',data(:));
end
% My coded part
but i am getting this error: ??? Error using ==> set There is no 'YData' property in the 'root' class.
Error in ==> sp>update_plot at 107
set(handles.phandle(i),'YData',data(:));
Warning: The SamplesAcquiredFcn callback is being disabled.
To enable the callback, set the SamplesAcquiredFcn property.
basically i am trying to read input from microphone and plot it at real time. I been trying to do this for a while and kind of struggling, if you can help it would be great.
if its hard to read that: in the function sp_OpeningFcn, i added this code: (right after:guidata(hObject, handles);) daq_object = analoginput('winsound'); chan = addchannel(daq_object,[1 2]);
num_samples=1000;
axes(handles.axes1);
phandle= spectrogram(zeros(num_samples,1));
handles.daq_object=daq_object;
handles.phandle=phandle;
handles.num_samples=num_samples;
guidata(hObject,handles);
set(daq_object,'SamplesPerTrigger',inf,'SamplesAcquiredFcnCount',num_samples,...
'SamplesAcquiredFcn',{@update_plot,handles});
and in the start call back function: if(strcmp(handles.daq_object.running,'On')) return; else start(handles.daq_object); end
and at the end update_plot function. function update_plot(hObject, eventdata, handles) data=getdata(handles.daq_object,handles.num_samples); for i=1:length(handles.phandle) set(handles.phandle(i),'YData',data(:)); end
In the GUI i have two this an axis1 and an start button called start

Réponses (1)

Walter Roberson
Walter Roberson le 16 Juil 2011

0 votes

If you are using the signal processing spectrogram then note that when you ask to return an output argument from spectrogram(), no plot will be created and instead the fft of the data will be returned. The fft happens to include at least one 0, and attempting to access the YData property of the handle 0 fails.
The above-referenced documentation shows an example of how to return values from the spectrogram and plot them.

Catégories

Produits

Tags

Question posée :

le 15 Juil 2011

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by