image thumbnail

EXPO 2011 Signal Processing Workflow Demo Files

by

 

MATLAB EXPO 2011 Signal Processing Workflow Demo Files

wkf_spect_filt.m
%% M̃nEOLZ[f
% ̃fł́AMtB^p
% nEOmCYvZXЉ܂B
% gpIvVFSignal Processing Toolbox, DSP System Toolbox
%%
% 
clear all, close all

%% f[^̎荞
recObj = audiorecorder(22050, 16, 1);
recordblocking(recObj, 5);     % ^

%% ĐĊmF
if 0
	play(recObj);
end
%% vbgƃf[^ۑ
mySpeech = getaudiodata(recObj, 'double'); % f[^ int16 zƂ
plot(mySpeech),grid on
wavwrite(mySpeech,22050,'wave_from_matlab.wav')
clear recObj mySpeech

%% nEO܂WAVt@C̓ǂݍ
% WAVt@C[hĎԎ\܂B
[noised_sig,Fs] = wavread('voice_howling.wav');
% [noised_sig,Fs] = wavread('wave_from_matlab.wav');

t = (0:length(noised_sig)-1)/Fs;
figure(1)
plot(t,noised_sig),grid on
xlim([0 t(end)]),ylim([-1 1])
title('M+nEO̎Ԏ'),xlabel('ԁisecj'),ylabel('U')

%% t@C̍Đ
playObj = audioplayer(noised_sig, Fs);
play(playObj);
%% mCYM̎g̕\
% ‚̃XyNg͎@pĎgXyNg\܂B
% CU@ł̃s[NƃXyNgOňg̐M
% nEOmCYƗ\złB
figure(2)
subplot(3,1,1)
% [s1, f1] = pwelch(noised_sig, hamming(2048), 2048, Fs);
[s1, f1] = periodogram(noised_sig, hamming(length(noised_sig)), length(noised_sig), Fs);
plot(f1, 20*log10(s1),'b-.'),grid
xlim([0 f1(end)])
title('Periodogram'),xlabel('giHzj'),ylabel('p[/gidB/Hzj')

subplot(3,1,2)
[s2, f1] = pmcov(noised_sig, 16, 512, Fs);
plot(f1, 20*log10(s2),'b-.'),grid
xlim([0 f1(end)])
title('CU@'),xlabel('giHzj'),ylabel('p[idBj')

subplot(3,1,3)
spectrogram(noised_sig,hamming(512),256,512,Fs);
title('XyNgO'),xlabel('giHzj'),ylabel('ԁisecj')
set(gcf,'Position',[10 180 560 800])

%% s[No
% nEOmCY̎g𑪒肷邽߂ɃXyNg̃s[N
% oăvbgBXyNg͂ɂg\́AFFT_
% ˑ̂ŁAő肳ꂽs[Ng͂x̌덷܂ށB
figure(2)
[Pks,Locs]=findpeaks(20*log10(s2),'NPeaks',10,'Sortstr','descend'); % dB
peak_freq = f1(Locs)
subplot(3,1,2)
hold on
plot(peak_freq,Pks,'ro')
hold off

%% GUIŃtB^݌v
% ̃p[^ŃtB^݌v
% ^Cv VOmb`
% ݌v@ IIR VOmb`
% Fs: 22050
% Fnotch: peak_freq
% ш敝F80
% Udl Apass: 15
if 0
	fdatool
end
%% vOŃtB^݌v
% FDATooltB^݌vpMATLABt@CGNX|[gĎgp܂B
% Hd = design_notch_fcn(Fnotch,BW,Apass)
% Hd1 = design_notch_fcn(peak_freq(1),80,15);
% Hd2 = design_notch_fcn(peak_freq(3),80,15);
% [b1, a1] = iirnotch(peak_freq(1)/(Fs/2), 80/(Fs/2), 15);
% Hd1     = dfilt.df2(b1, a1);
% [b2, a2] = iirnotch(peak_freq(3)/(Fs/2), 80/(Fs/2), 15);
% Hd2     = dfilt.df2(b1, a2);

Fd1  = fdesign.notch('N,F0,BW,Ast',2,peak_freq(1)/(Fs/2),500/(Fs/2),30);
designmethods(Fd1)
Hd1 = design(Fd1);
Fd2  = fdesign.notch('N,F0,BW,Ast',2,peak_freq(3)/(Fs/2),500/(Fs/2),30);
designmethods(Fd2)
Hd2 = design(Fd2);

Hd = cascade(Hd1, Hd2)
hfv = fvtool(Hd,'Fs',Fs)
save notchfilterobj Hd1 Hd2 Fd1 Fd2 peak_freq

%% ݌vtB^Kp
% mb`tB^mCYMɓKpAnEOmCY܂B
denoise_sig = filter(Hd, noised_sig);

%% mCYM̎g
% mCYꂽƂgXyNg\ĊmF܂B
figure(2)
subplot(3,1,1)
hold on
[s1, f1] = periodogram(denoise_sig, hamming(length(denoise_sig)), length(denoise_sig), Fs);
plot(f1, 20*log10(s1), 'r')

subplot(3,1,2)
hold on
[s2, f1] = pmcov(denoise_sig, 16, 512, Fs);
plot(f1, 20*log10(s2), 'r')

subplot(3,1,3)
hold off
spectrogram(denoise_sig,hamming(512),256,512,Fs);
title('XyNgO'),xlabel('giHzj'),ylabel('ԁisecj')

%% t@C̍Đ
playObj = audioplayer(denoise_sig, Fs);
play(playObj);

%% t@C̕ۑ
wavwrite(denoise_sig,Fs, 'denoise.wav')
dlmwrite('denoise.txt',denoise_sig,'precision','%.10f','delimiter','\n')

%% gωnEO܂WAVt@C̓ǂݍ
% WAVt@C[hĎԎ\܂B
clear noised_sig Fs
[noised_sig,Fs] = wavread('voice_multi_howling.wav');
t = (0:length(noised_sig)-1)/Fs;
figure(4)
plot(t,noised_sig),grid on
xlim([0 t(end)]),ylim([-1 1])
title('M+nEO̎Ԏ'),xlabel('ԁisecj'),ylabel('U')

%% t@C̍Đ
playObj = audioplayer(noised_sig, Fs);
play(playObj);

%% mCYM̎gmF
% g͓Iȓ͔cłȂAZFFŤʂԎɕׂ
% XyNgOł͓Iȓc邱Ƃo܂B
figure(5)
subplot(3,1,1)
[s1, f1] = periodogram(noised_sig, hamming(length(noised_sig)), length(noised_sig), Fs);
plot(f1, 20*log10(s1),'b-.'),grid
xlim([0 f1(end)])
title('Periodogram'),xlabel('giHzj'),ylabel('p[/gidB/Hzj')

subplot(3,1,2)
[s2, f1] = pmcov(noised_sig, 16, 512, Fs);
plot(f1, 20*log10(s2),'b-.'),grid
xlim([0 f1(end)])
title('CU@'),xlabel('giHzj'),ylabel('p[idBj')

subplot(3,1,3)
spectrogram(noised_sig,hamming(512),256,512,Fs);
title('XyNgO'),xlabel('giHzj'),ylabel('ԁisecj')
set(gcf,'Position',[10 180 560 800])

%% s[No
% XyNg̃s[Noăvbg
figure(5)
[Pks,Locs]=findpeaks(20*log10(s2),'NPeaks',10,'Sortstr','descend'); % dB
peak_freq = f1(Locs)
subplot(3,1,2)
hold on
plot(peak_freq,Pks,'ro'), hold off

%% Simulinkf̃I[vƎs
% ̃nEOmCY͕gƒ_Ci~bNɕω邽
% Œ̃tB^ł͏B_Ci~bNV~[^Simulink
% Cӎg邱Ƃ̂łKtB^pB
% LMSA_veBuEtB^̌WXVw_k(n+1)=w_k(n)+e(n)x(n-k)
open_system('adapt_notch_wav');
FrameSize = 256;

%% V~[V̎s
sim('adapt_notch_wav');

%% MOM̉Ž
clear all
[sl_signal, Fs] = wavread('filtered.wav');
figure(5)
subplot(3,1,1)
hold on
[s1, f1] = periodogram(sl_signal, hamming(length(sl_signal)), length(sl_signal), Fs);
plot(f1, 20*log10(s1), 'r')

subplot(3,1,2)
hold on
[s2, f1] = pmcov(sl_signal, 16, 512, Fs);
plot(f1, 20*log10(s2), 'r')

subplot(3,1,3)
spectrogram(sl_signal,hamming(512),256,512,Fs);
title('XyNgO')
xlabel('giHzj')
ylabel('ԁisecj')

%% t@C̍Đ
% mCYłĂ邱Ƃt@CĐĊmFB
playObj = audioplayer(sl_signal, Fs);
play(playObj);




% eof

Contact us