Why can't I plot a spectrogram in my GUI?!?
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
So I have a gui that allows me to record audio, and then either plot a time history or a spectrogram of the data depending on a pop-up menu choice; but I can't get the spectrogram to plot. There is only on set of axis. My code for this section is -
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)
fs = str2num(get(handles.Fs,'string'));
bits = str2num(get(handles.nbits,'string'));
tend = str2num(get(handles.tstart,'string'));
w = 1000;
ptype = get(handles.popupmenu,'value');
AudioRaw = audiorecorder(fs,bits,1); %define recording parameters
recordblocking(AudioRaw,tend); %record audio
th = getaudiodata(AudioRaw);
dt = 1/fs;
t = 0 :dt: length(th)*dt - dt;
% spectrogram(th,w,w/2,[],fs,'yaxis')
if ptype == 1
plot(t,th);
xlabel('Time, s')
ylabel('Amplitude, v')
elseif ptype == 2
spectrogram(th,w,w/2,[],fs,'yaxis')
end
This gives me a number of errors:
Struct contents reference from a non-struct array object.
Error in spectrogram>displayspectrogram (line 282)
if strcmp(hRotate.State,'off')
Error in spectrogram (line 237)
displayspectrogram(t,f,Pxx,isnormfreq,faxisloc,esttype,threshold);
Error in quickRecord>Start_Callback (line 103)
spectrogram(th,w,w/2,[],fs,'yaxis')
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in quickRecord (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)quickRecord('Start_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback
I've checked the data etc and the spectrogram should plot fine. Any tips would be great!!! I'm pretty flummoxed.
1 comentario
Geoff Hayes
el 16 de Nov. de 2016
Jack - which version of MATLAB are you using? Can you create a spectrogram from the command line (outside of your GUI) using an example found at spectrogram?
Respuestas (1)
Greg Dionne
el 17 de Nov. de 2016
Editada: Greg Dionne
el 17 de Nov. de 2016
Looks like you're trying to redirect the auto-generated debug plot of the spectrogram to a dedicated figure, and it's failing because you don't have the "Rotate 3D" button defined in your figure.
You can rotate the spectrogram plot into a nice 3D image by clicking the rotation button in the debug plot. If you don't see it, in your figure's "View" menu check the View->FigureToolbar item, then click on the icon that has a cube circumscribed with a counterclockwise arrow (next to the "hand" icon). Then drag around in the axes.
Normally, spectrogram will generate a new figure with the button enabled. Make sure that button exists in your GUI before calling spectrogram.
0 comentarios
Ver también
Categorías
Más información sobre Time-Frequency Analysis en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!