Professional Documents
Culture Documents
BÀI THI GIỮA KỲ MÔN XỬ LÝ TIẾNG
BÀI THI GIỮA KỲ MÔN XỬ LÝ TIẾNG
Chương 2
Câu 1: thực hiện ghi âm và lưu file
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% date: 30-11-2010 %
% File: record.m %
% Editor: cuong %
% Email: dangvietcuong85@gmail.com %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function record(op)
% global variables
global H_RECORD F_RECORD AXIS_RECORD ai data z_data R_fs R_samp_len
global ZOOM_HISTORY
%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 = 950;
height = 700;
H_RECORD(2) = uicontrol('Style','text',...
'Units','normalized', ...
'Position',[190/width (height-45)/height 80/width 20/height],...
'BackgroundColor',[.8 .8 .8],...
'String',' ');
case 4
xmin = RECT(1);
xmax = RECT(1) + RECT(3);
ymin = RECT(2);
ymax = RECT(2) + RECT(4);
end
case 5
zoom_level = length(ZOOM_HISTORY);
if zoom_level > 1
[ZOOM_HISTORY,axis_limits] = pop(ZOOM_HISTORY);
else
axis_limits = ZOOM_HISTORY{1};
end
% zoom out to the full time data
axes(AXIS_RECORD(1))
axis(axis_limits);
if filename ~= 0
cd(pathname);
z_data = data;
% displays the time graph of the voice signal
AXIS_RECORD(1) = timedata(F_RECORD,data,R_fs,0.06,0.50,0.88,0.30);
xlims = get(AXIS_RECORD(1),'XLim');
ylims = get(AXIS_RECORD(1),'YLim');
ZOOM_HISTORY = [];
ZOOM_HISTORY = push(ZOOM_HISTORY,[xlims ylims]);
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);
%---------------------------------------------------------------
% SUBFUNCTION
function H = spectdata(Fig,x,fs,step,ww,left,bottom,width,height)
% This function plots spectral data at location specified by user
% Left, bottom, width, height are relative locations less than 1
figure(Fig);
%---------------------------------------------------------------
% 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);
Sau khi chạy chương trình thì sẽ hiện ra giao diện để ta thực hiện ghi âm
Câu 2 : Biểu diễn tín hiệu trong miền thời gian.
[xtemp,fs,bits] = wavread('nghenoi');
0.4
0.2
0
Amplitude
-0.2
-0.4
-0.6
-0.8
-1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Times (s)
Câu 3) Biểu diễn tín hiệu và phổ của nó dùng các hàm cửa sổ sau đây:
a) Tam giác:
y=triang(length(x));
y= fft(x.*triang(length (x))) ;%nhân ch?p tín hi?u v?i c?a s? r?i
chuy?n qua mi?n t?n s?
hz =5000* length (y)/fs;
f= (0:hz)*fs/length (y);
plot(f,20*log10(abs(y(1:length(f)))+eps));% v?i ph?n tín hi?u
trong mi?n th?i gian?
grid on;
legend('Cua so tam giac');
xlabel('Tan so (Hz)');
ylabel('Do lon (dB)');
60
40
Do lon (dB)
20
-20
-40
0 500 1000 1500 2000 2500 3000 3500 4000 4500 5000
Tan so (Hz)
y=rectwin(length(x));
y= fft(x.*rectwin(length (x))) ;%nhân ch?p tín hi?u v?i c?a s? r?i
chuy?n qua mi?n t?n s?
hz =5000* length (y)/fs;
f= (0:hz)*fs/length (y);
plot(f,20*log10(abs(y(1:length(f)))+eps));% v?i ph?n tín hi?u
trong mi?n th?i gian?
grid on;
legend('Cua so chu nhat');
xlabel('Tan so (Hz)');
ylabel('Do lon (dB)');
disp('Nhan phim bat ki de tiep tuc');
pause
100
Cua so chu nhat
80
60
40
Do lon (dB)
20
-20
-40
0 500 1000 1500 2000 2500 3000 3500 4000 4500 5000
Tan so (Hz)
c) Hamming
y=hamming(length(x));
y= fft(x.*hamming(length (x))) ;%nhân ch?p tín hi?u v?i c?a s? r?i
chuy?n qua mi?n t?n s?
hz =5000* length (y)/fs;
f= (0:hz)*fs/length (y);
plot(f,20*log10(abs(y(1:length(f)))+eps));% v?i ph?n tín hi?u
trong mi?n th?i gian?
grid on;
legend('Cua so Hamming');
xlabel('Tan so (Hz)');
ylabel('Do lon (dB)');
disp('Nhan phim bat ki de tiep tuc');
pause d
80
Cua so Hamming
60
40
Do lon (dB)
20
-20
-40
0 500 1000 1500 2000 2500 3000 3500 4000 4500 5000
Tan so (Hz)
d) Hanming
y=hann(length(x));
y= fft(x.*hann(length (x))) ;%nhân ch?p tín hi?u v?i c?a s? r?i chuy?n
qua mi?n t?n s?
hz =5000* length (y)/fs;
f= (0:hz)*fs/length (y);
plot(f,20*log10(abs(y(1:length(f)))+eps));% v?i ph?n tín hi?u trong
mi?n th?i gian?
grid on;
legend('Cua so hanming');
xlabel('Tan so (Hz)');
ylabel('Do lon (dB)');
disp('Nhan phim bat ki de tiep tuc');
pause
80
Cua so hanming
60
40
Do lon (dB)
20
-20
-40
0 500 1000 1500 2000 2500 3000 3500 4000 4500 5000
Tan so (Hz)
Câu 4) Dùng phương pháp điều chế DPCM để điều chế tín hiệu, giải mã tín hiệu và đánh giá sai
số.
2000
1000
-1000
-2000
-3000
-4000
-5000
-6000
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Chương 3
Câu 2: xác định tần số cơ bản
[x,fs]=wavread('nghenoi');
% plot waveform
subplot(2,1,1);
plot(t,x);
legend('Waveform');
xlabel('Time (s)');
ylabel('Amplitude');
% calculate autocorrelation
r=xcorr(x,ms20,'coeff');
% plot autocorrelation
subplot(2,1,2);
plot(d,r);
legend('Autocorrelation');
xlabel('Delay (s)');
ylabel('Correlation coeff.');
ms2=fs/500 % maximum speech Fx at 500Hz
r=r(ms20+1:2*ms20+1)
[rmax,tx]=max(r(ms2:ms20))
fprintf('rmax=%g Fx=%gHz\n',rmax,fs/(ms2+tx-1));
0.6
Waveform
0.4
0.2
Amplitude
-0.2
-0.4
-0.6
-0.8
-1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Time (s)
1
Autocorrelation
0.99
Correlation coeff.
0.98
0.97
0.96
0.95
0.94
-0.02 -0.015 -0.01 -0.005 0 0.005 0.01 0.015 0.02
Delay (s)
[xtemp,fs,bits] = wavread('nghenoi');
x=resample(x,10000,fs);
fs=10000;
% plot waveform
subplot(2,1,1);
plot(t,x);
legend('Waveform');
xlabel('Time (s)');
ylabel('Amplitude');
[h,f]=freqz(1,a,512,fs);
subplot(2,1,2);
plot(f,20*log10(abs(h)+eps));
legend('LP Filter');
xlabel('Frequency (Hz)');
ylabel('Gain (dB)');
% find frequencies by root-solving
ffreq=sort(atan2(imag(r),real(r))*fs/(2*pi));
for i=1:length(ffreq)
end
0.5
Waveform
0
Amplitude
-0.5
-1
-1.5
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Time (s)
60
LP Filter
50
40
30
Gain (dB)
20
10
-10
-20
0 500 1000 1500 2000 2500 3000 3500 4000 4500 5000
Frequency (Hz)