⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 speakerwc.m

📁 matlab code for EMT field theory project stating mashgrid quiver
💻 M
字号:

[y, fs, nbits] = wavread('s11.wav'); %read in the wav file
sound(y,fs) %play back the wav file
t = 0:1/fs:length(y)/fs-1/fs; %create the proper time vector
subplot(211) %create a subplot
plot(t,y) %plot the original waveform
yfirst=y(1:15000); %partition the vector into two parts
ysecond=y(15001:30000);
% save darren ysecond yfirst -ascii %save the vector in reverse order
% load darren -ascii %read back in the new file
% subplot(212) %prepare a new subplot
% %plot(t,darren) %plot the new file to compare it to the original
% pause(2) %create a 2 second pause
% %sound(darren,fs); %play back the new sound file

[y, fs, nbits] = wavread('s1.wav'); %read in the wav file
 t = 0:1/fs:length(y)/fs-1/fs; %generate the correct time vector
 subplot(311) %set up a subplot
 plot(t,y) %plot the signal in the time domain
sigma = 0.02;
mu = 0;
n = randn(size(y))*sigma + mu*ones(size(y));

signal=n+y; %add the gaussian noise to the original signal
yfft=fft(y); %take the FFT of the original signal.
xfft=fft(signal); %take the FFT of the signal with noise added
f = -length(y)/2:length(y)/2-1; %generate the appropriate frequency

ysfft=fftshift(yfft); %calculate the shifted FFT of the original

xsfft=fftshift(xfft); %same as above but for the signal with noise

subplot(312)

plot(f,abs(ysfft));
subplot(313)

plot(f,abs(xsfft));

[y, fs, nbits] = wavread('s5.wav'); %read in the wav file
t = 0:1/fs:length(y)/fs-1/fs; %generate the correct time vector
subplot(311) %create a subplot
plot(t,y) %plot the signal in the time domain
sound(y,fs) %play back the wav file
yfft=fft(y); %take the FFT of the original signal
f = -length(y)/2:length(y)/2-1; %create the appropriate
ysfft=fftshift(yfft); %Shift the FFT of the

subplot(312)
plot(f,abs(ysfft)); 
order = 3;
cut = 0.05;
[B, A] = butter(order, cut);
filtersignal = filter(B, A, ysfft);

subplot(313)
plot(f,21*abs(filtersignal)); %plot the scaled and filtered

[y, fs, nbits] = wavread('s11.wav'); %read in the wav file
% [t, f0, avgF0] = pitch(y,fs) %call the pitch.m routine
% plot(t,f0) %plot pitch contour versus time frame
%avgF0 %display the average pitch
sound(y) %play back the sound file

ns = length(y);

mu = mean(y);
%y = y - mu;

fRate = floor(120*fs/1000);
updRate = floor(110*fs/1000);
nFrames = floor(ns/updRate)-1;
% the pitch contour is then a 1 x nFrames vector
f0 = zeros(1, nFrames);
f01 = zeros(1, nFrames);
% get the pitch from each segmented frame
k = 1;
avgF0 = 0;
m = 1;
for i=1:nFrames
xseg = y(k:k+fRate-1);
%f01(i) = pitchacorr(fRate, fs, xseg);
% do some median filtering, less affected by noise
if i>2 & nFrames>3
z = f01(i-2:i);
md = median(z);
f0(i-2) = md;
if md > 0
avgF0 = avgF0 + md;
m = m + 1;
end
elseif nFrames<=3
f0(i) = a;
avgF0 = avgF0 + a;
m = m + 1;
end
k = k + updRate;
end
t = 1:nFrames;
t = 20 * t;
if m==1
avgF0 = 0;
else
avgF0 = avgF0/(m-1);
end







results=zeros(12,1); %create a vector for results.
diff=zeros(82,1); %create a vector for differences in pitch.
formantdiff=zeros(12,1); %create a vector for diff in formant vector
[y17, fs17, nbits17] = wavread('s11.wav'); %read in the wav file to
%compare all others to.
%[t17, f017, avgF017] = pitch(y17,fs17); %call the pitch rouine for
%ref. wav file.
%[P17,F17,I17] = formant(y17); %call the formant routine
%for ref. wav file.
%plot(t17,f017) %plot the pitch contour of the ref. file
%avgF17 = avgF017 %set the average pitch equal to avg17
sound(y17)
pause(3) %pause for 3 seconds
%This code was provided by Dr. Qi
%file name based on the index, i
for i=1:83
if i<10
filename = sprintf('a0%i.wav', i);
else
filename = sprintf('a%i.wav', i);
end
%[y, fs, nbits] = wavread(filename);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%[t, f0, avgF0] = pitch(y,fs); %call the pitch.m routine for the
%current wav file.
plot(t,f0) %plot the current wav file contour plot.
%avgF0(i) = avgF0; %find the average pitch for the current wav file.
%diff(i,1)=norm(avgF0(i)-avgF17);
end
[Y,H]=sort(diff) %sort the pitch correlations in ascending order.
for j=1:12 %pick the lowest 20 pitch correlations to compare formants .
p=H(j) %set p equal to jth position of vector H .
if p<10
filename = sprintf('a0%i.wav', p);
else
filename = sprintf('a%i.wav', p);
end
filename %display the filename of the wav file being compared.
%[y, fs, nbits] = wavread(filename);
%[P,F,I] = formant(y); %call the formant.m routine for the current wav
sound(y) %play back the wav file being compared.
%plot(F,P) %plot the formants for the comparison wav file.
pause(3) %pause for 3 seconds so sound will finish playing back.
%formantdiff(j,1)=norm(I17-I); %create a vector of formant peak
%differences.
end
[Y1,H1]=sort(formantdiff) %sort the vector in ascending order
for k=1:12
results(k,1)=H(H1(k)); %calculate the numerical numbers of the
%closest wav matches.
end
H %display the vector H.
H1 %display the vector H1.
results %display the numerical numbers of the closest wav file
%matches.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -