MATLAB help for voice analyzing.

Thread Starter

BuriedMoon

Joined Mar 2, 2010
22
This is the starting point, when it records it will play the waveform for time domain and frequency and there are buttons for you to save and load as well . However , whenever i wanted to load a file., the waveform doesnt show. Anyone
here can enlighten me would be great .
_________________________________________________________________
global H_RECORD%main program

global F_RECORD

width = 950;
height = 700;

F_RECORD = figure('Position',[25 50 width height],...
'NumberTitle','off',...
'Color',[.8 .8 .8],...
'Name','Record');

H_RECORD = uicontrol('Style','pushbutton',...
'Units','normalized', ...
'Position',[(width-450)/width (height-40)/height 80/width 25/height],...
'ForegroundColor',[.2 .4 .2],...
'FontWeight','bold',...
'String','Record',...
'Enable','off',...
'CallBack',['data = record_sound1(4);',...
'hwin1 = subplot(2,1,1);plot(data);xlabel(''Samples'');ylabel(''Signal (Volts)'');',...
'hwin2 = subplot(2,1,2);p = fft(data);plot(abs(p((1:2*fs))));xlabel(''Frequency(Hz)'');'...
'ylabel(''Magnitude'');']);

H_PLAY = uicontrol('Style','pushbutton',...
'Units','normalized', ...
'Position',[(width-150)/width (height-40)/height 80/width 25/height],...
'ForegroundColor',[.2 .4 .2],...
'FontWeight','bold',...
'String','Play',...
'Enable','off',...
'CallBack',['xlim = get(hwin1,''XLim'');xlim(1) = max([xlim(1),1]);xlim(2)=min([xlim(2),length(data)]);sound(data(xlim(1):xlim(2)),fs)']);

H_ZOOM = uicontrol('Style','pushbutton',... % zoom
'Units','normalized',...
'Position',[300/width (height-370)/height 80/width 25/height],...
'ForegroundColor',[1 0 0],...
'FontWeight','bold',...
'String','Play',...
'String','Zoom in',...
'Visible','on',...
'CallBack','mycallbackplot');

H_SAVE = uicontrol('Style','pushbutton',... % save button
'Units','normalized',...
'Position',[580/width (height-40)/height 80/width 25/height],...
'ForegroundColor',[1 0 0],...
'FontWeight','bold',...
'String','Play',...
'String','Save',...
'Visible','on',...
'CallBack',['xlim = get(hwin1,''XLim'');xlim(1) = max([xlim(1),1]);xlim(2)=min([xlim(2),length(data)]);' 'mysave(data(xlim(1):xlim(2),:),fs)']);


H_LOAD = uicontrol('Style','pushbutton',... % load button
'Units','normalized',...
'Position',[660/width (height-40)/height 80/width 25/height],...
'ForegroundColor',[1 0 0],...
'FontWeight','bold',...
'String','Play',...
'String','Load',...
'Visible','on',...
'CallBack','myload(data,fs)');





fs = 11025;
% ts = 10;
% AI = analoginput('winsound');
% addchannel(AI,1:2);
% set(AI,'SampleRate',fs)
% set(AI,'SamplesPerTrigger',ts*fs)
% start(AI)
% data = getdata(AI);

data = zeros(4*fs,2);
% t = (0:(4*fs-1))/fs;
set(H_RECORD,'enable','on');
set(H_PLAY,'enable','on');
set(H_ZOOM, 'enable', 'on');
set(H_LOAD, 'enable', 'on');
set(H_SAVE, 'enable', 'on');
subplot(2,1,1)
plot(data)
xlabel('Samples')
ylabel('Signal (Volts)')
%hold on
subplot(2,1,2)
% f = [(1:2*fs)-1];
p = fft(data);
plot(abs(p((1:2*fs))));
xlabel('Frequency(Hz)');
ylabel('Magnitude');





% sound(data,fs)
% Data=1:64;Data=(Data'*Data)/64;
%h=msgbox('Loser','Win or Lose','custom',Data,hot(64))
%E = uicontrol('Style', 'pushbutton', 'String', 'Clear',...
%'Position', [20 150 100 70], 'Callback', 'cla');
%delete(AI)
%clear AI

%sstop = round(get(gca,'XLim'));
% sound(data(sstop(1):sstop(2)),fs)
_________________________________________________________________
function mycallbackplot%function to plot and zoom in waveform for the %frequency domain

subplot(211)
hchil = get(gca,'children');
data = get(hchil,'YData');
data = [data{1};data{2}];
xlim = get(gca,'XLim');
xlim(1) = ceil(max([xlim(1),1]));
xlim(2)=floor(min([xlim(2),length(data)]));
subplot(212)
p = fft(data(xlim(1):xlim(2)));
semilogy(abs(p(1:0.5*(length(data(xlim(1):xlim(2)))))));
xlabel('Frequency(Hz)');
ylabel('dB');
_________________________________________________________________
function mysave(data,fs)%callback function to allow it to save .

sstop = round(get(gca,'XLim'));
sound(data(sstop(1):sstop(2)),fs)

[filename, pathname] = uiputfile('*.wav', 'Save Data to Wave File');



if filename ~= 0


wavwrite(data,fs,[pathname filename])

end
_________________________________________________________________
function myload(data,fs)%call back function for loading wavfiles .


[filename, pathname] = uigetfile('*.wav','Select Data File');

if filename ~= 0

cd(pathname);

% Get data and sampling rate
[data,fs] = wavread([pathname filename]);

% if min(size(data))>1
% error('Can''t load stereo data')
% end

end
 
Top