هوش مصنوعی

کامپیوتر - هوش مصنوعی

هوش مصنوعی

کامپیوتر - هوش مصنوعی

چگونگی ضبط صدا در متلب

Recording from Microphone


http://neural.cs.nthu.edu.tw/jang/books/...Microphone

function [zz_data]=record(op)

global H_RECORD F_RECORD AXIS_RECORD ai data z_data R_fs R_samp_len

global ZOOM_HISTORY

if nargin == 0 % if no input argument, draw the GUI
op = 0;
end

%spec = 'wideband';
spec = 'narrowband';
wideband_time = 4e-3;
narrowband_time = 25e-3;
%window_width = 200; % window width for FFT
%step_size = 100; % window movement
fft_pts = 2048; % # of points in the FFT

switch op

case 0 % Draw figure

clear global data % erase any previously recorded data

width = 600;
height = 400;
% ح¼ذخ½çأو×ـجهµؤةèضأ
F_RECORD = figure('numbertitle','off',...
'position',[120 120 600 400],...
'name','Record ',...
'color',[0.8 0.8 0.8],...
'MenuBar','none');


uicontrol(F_RECORD,'style','push','units','normalized','position',[0.395 0.12 0.13 0.08],...
'string','Record','fontsize',8,'callback','record(1)');


uicontrol(F_RECORD,'style','push','units','normalized','position',[0.595 0.12 0.13 0.08],...
'string','Play ','fontsize',8,'callback','record(2)');
uicontrol(F_RECORD,'style','push','units','normalized','position',[0.795 0.12 0.13 0.08],...
'string','Save','fontsize',8,'callback','record(4)');





uicontrol(F_RECORD,'style','text','units','normalized','position',[0.095 0.18 0.13 0.08],...
'string','Name:','back',[0.8 0.8 0.8],'horizontal','left','fontsize',12);
F_RECORD_ltol1=uicontrol(F_RECORD,'style','edit','units','normalized','position'​,[0.095 0.12 0.13 0.08],...
'string','','back',[0.8 0.8 0.8],'horizontal','left','fontsize',12);






RECORD_axes1=axes('position',[60/width (height-245)/height 500/width 180/height]);



H_RECORD(1) = uicontrol('Style','text',...
'Units','normalized', ...
'Position',[200/width (height-30)/height 180/width 20/height],...
'BackgroundColor',[.8 .8 .8],...
'fontsize',12,...
'String','Welecom');

H_RECORD(2) = uicontrol('Style','text',...
'Units','normalized', ...
'Position',[200/width (height-55)/height 180/width 20/height],...
'BackgroundColor',[.8 .8 .8],...
'fontsize',12,...
'String',' ');
H_RECORD(4) = uicontrol('Style','Slider',... % user selects time length
'Units','normalized', ...
'Position',[490/width (height-35)/height 80/width 14/height],...
'Min',0.1,'Max',0.5,'Value',0.5,...
'SliderStep',[1/5-0.000001 1/5],...
'Callback','record(3)');
H_RECORD(5) = uicontrol('Style','text',... % diplays time length
'Units','normalized', ...
'Position',[480/width (height-54)/height 100/width 14/height],...
'BackgroundColor',[.8 .8 .8],...
'String','Length - 0.5 sec');

case 1 % record button

R_fs = 16000;
R_samp_len = get(H_RECORD(4),'Value');

% get handles for sound input and output
ai = init_sound(R_fs,R_samp_len);
R_fs = get(ai, 'SampleRate'); % in case actual rate doesn't match desired

% gets an array named data from the microphone
nogo=0;

while not (nogo)
set(H_RECORD(1),'String','Recording');

start(ai);
try
data = getdata(ai);
nogo=1;
catch
disp('0.5 seconds elapsed... try again!');
stop(ai);
end
end
delete(ai);
set(H_RECORD(1),'String','Record');


% normalize sound data to 99% of max
data = 0.99*data/max(abs(data));
z_data = data;
% displays the time graph of the voice signal
AXIS_RECORD(1) = timedata(F_RECORD,data,R_fs,70/600,(400-245)/400, 500/600, 180/400);

xlims = get(AXIS_RECORD(1),'XLim');
ylims = get(AXIS_RECORD(1),'YLim');
ZOOM_HISTORY = [];
ZOOM_HISTORY = push(ZOOM_HISTORY,[xlims ylims]);

% Sampling rate dependent window width
if strcmp(spec,'narrowband')
window_width = round(R_fs*narrowband_time);
step_size = round(window_width/8);
elseif strcmp(spec,'wideband')
window_width = round(R_fs*wideband_time);
step_size = round(window_width/2);
end

% calculates the spectrum of the voice signal
X = specgram(data,fft_pts,1,hamming(window_width),window_width-step_size);
X = abs(X);
% displays the spectrum of the voice signal

axis([xlims get(gca,'YLim')])

case 2 % Play recording

% sends an array named z_data to the speakers/headphones
if length(z_data) ~= 0
sound(z_data,R_fs)
end

case 3 % Display time length text

% Allow the user to set the time length of sample
num = get(H_RECORD(4),'Value');
set(H_RECORD(5),'String',['Length - ' num2str(num) ' sec']);

case 4 % Save waveform

%[filename, pathname] = uiputfile('d:\aaa.wav', 'Save Data to Wave File');
filename = 'aaa.wav';
pathname = 'd:\aaa.wav';
if filename ~= 0
[x1 x2] = vad(z_data);
zz_data=z_data((x1-1)*127:(x2+1)*128);
wavwrite(zz_data,R_fs,[pathname filename])
end



case 5 % exit
clear all;
close
clc;
end

end



%---------------------------------------------------------------
% SUBFUNCTION
function H = timedata(Fig,x,fs,left,bottom,width,height)
% This function plots time data at location specified by user
% Left, bottom, width, height are relative locations less than 1

figure(Fig);

samp_len = length(x)/fs;
delta_t = 1/fs;
t = 0:delta_t:(samp_len-delta_t);

% display the signal
H = subplot('position',[left bottom width height]);
plot(t,x), xlabel('Time [sec]'), ylabel('Amplitude')
axis([0 t(length(x)-1) -1 1 ]);


%---------------------------------------------------------------

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function H = spectdataa(Fig,x,left,bottom,width,height)
figure(Fig);
a=mfcc(x);
a = svdatanorm(a);
% frequency axis vector
y_len = size(a,1); % num of rows
f =1: y_len ; % kHz scale

% time axis vector
x_len = size(a,2); % num of columns
%t = [0.5:1:x_len+0.5]*step/fs;
%t = [(ww-1)/2-0.5:step:step*x_len+(ww-1)/2-1.5]/fs;
t =1: x_len ;



% display the signal
H = subplot('position',[left bottom width height]);
log_data = a;
imagesc(f,t,log_data), xlabel('Time [sec]'), ylabel('M [16]')
%---------------------------------------------------------------
% SUBFUNCTION
function ai = init_sound(fs,samp_len)
% Function 'init_sound' initializes microphone input for voice
% 'fs' is the sampling rate, 'samp_len' is the time to record
% in seconds.

v = ver;
name = {v.Name};
ind = find(strcmp(name,'MATLAB'));
if isempty(ind)
ind = find(strcmp(name,'MATLAB Toolbox'));
end

v_num = str2num(v(ind).Version);

ai = analoginput('winsound');
addchannel(ai, 1);
if (v_num == 6.1) | (v_num == 6.5)
set(ai, 'StandardSampleRates', 'Off');
end
set(ai, 'SampleRate', fs);
actual_fs = get(ai, 'SampleRate');
set(ai, 'TriggerType', 'software');
set(ai, 'TriggerRepeat', 0);
set(ai, 'TriggerCondition', 'Rising');
set(ai, 'TriggerConditionValue', 0.01);
set(ai, 'TriggerChannel', ai.Channel(1));
set(ai, 'TriggerDelay', -0.1);
set(ai, 'TriggerDelayUnits', 'seconds');
set(ai, 'SamplesPerTrigger', actual_fs*samp_len+1);
set(ai, 'TimeOut', 10);


%---------------------------------------------------------------
% SUBFUNCTION
function s = push(s,new_item)
% Function 'push' adds 'new_item' to stack 's'
if ~isempty(s)
height = length(s);
s{height+1} = new_item;
else
s{1} = new_item;
end

%---------------------------------------------------------------
% SUBFUNCTION
function [s,x] = pop(s)
% Function 'pop' removes item from top of stack 's'
height = length(s);
x = s{height};
s = s(1:height-1);


فایل‌(های) پیوست شده
.m  record.m (اندازه: 7.63 KB / تعداد دفعات دریافت: 7)

استخراج و رسم فورمنت (Formant)

استخراج و رسم فورمنت (Formant)


فایل‌(های) پیوست شده
.pdf  استخراج و رسم فورمنت.pdf (اندازه: 244.28 KB / تعداد دفعات دریافت: 45)

محاسبه انرژی و نرخ عبور از صفر و فرکانس گام

محاسبه انرژی و نرخ عبور از صفر و فرکانس گام


فایل‌(های) پیوست شده
.pdf  محاسبه انرژی و نرخ عبور از صفر و فرکانس گام.pdf (اندازه: 392.49 KB / تعداد دفعات دریافت: 127)