?? pitchspectrum.asv
字號:
function [] = PitchSpectrum();
% Define the function
% read the .wav file and paly the .wav file,add Ham windows draw the pitch on
% the spectrum .
% the main work: spectrum and pitch.
% The commuciation university of china
% For homework.
% TIME :200.02.20 Auther:zhangpengju
%----------------------------------------------------
clear all;
nfft = 512;
window = 512;
shift = 512
numoverlap = 0/4 * nfft;
% read the .wav file
[filename,filepath]=uigetfile('.wav','Open wav file');
if (~filename ) % read error
return ;
end;
[v,fs,bits]=wavread([filepath,filename]);
L1 = length(v);
n = 1:L1;
t = n/fs;
plot(t,v,'color','b');
xlabel('Time [sec]');
ylabel('Amplitude');
title(['Wave of the sound '],'Color','r');
set(gcf,'Position',[10 40 1000 600]);
set(gcf, 'Color',[0.8,0.8,0.8]); % outside
set(gca,'Color',[0.8,0.8,0.6]); % inside
% set(gcf,'Resize','off'); % max button off
pause(L1/fs);
sound(v,fs); % 播放 Play
figure(2);
[B,f,T] = SPECGRAM(v,nfft,fs,window,numoverlap);
%plot(0:512:length(v),f);
%b = specgram(v,nfft,fs,window,numoverlap);
%plot(t,b);
%用specgram來畫
% specgram(v,512,fs); % 獲得當(dāng)前的colormap
% cmap = colormap; % 獲得當(dāng)前colormap里的顏色數(shù)
% [numColors, nCol] = size(cmap);
% nBckColor = round(numColors*1/3); % 把前1/3的顏色變違背景色, 具體數(shù)目你自己調(diào)
% cmap(1:nBckColor,:) = ones(nBckColor, nCol); % 改變當(dāng)前的colormap
% colormap(cmap);
% xlabel('1_Time (seconds)');
% y坐標(biāo)軸
% ylabel('1_Frequency (Hz)');
% title('1_Spectrogram');
%
% figure(3);
% [B,f,t] = specgram(v,512,fs); % window,numoverlap
imagesc(t,f,20*log10(abs(B))), axis xy, colormap(jet);
% numCLines = 50; % 等高線的數(shù)目
% 產(chǎn)生劃分等高線的一系列數(shù)值
% cLines = linspace(min(min(abs(B))), max(max(abs(B))), numCLines);
% 開始畫填充的等高線,把最小的那一段去掉,也就沒有背景了
% 或者從第三塊開始,這些都可以通過修改下面的cLines里的下標(biāo)來實現(xiàn)
% contourf(t, f, abs(B), cLines(2:numCLines));
% xlabel('2_Time (seconds)'); % x坐標(biāo)軸
% ylabel('2_Frequency (Hz)'); % y坐標(biāo)軸
% title('2_Spectrogram'); % title('The frequency');
hold on;
plot(T);
%----------- 基音提取--------------------------------------------
p = PitchContour(v,fs,window,shift);
figure;
for (k = 0:T)
plot(p);
set(gcf, 'Color',[0.8,0.8,0.8]); % outside
set(gca,'Color',[0.8,0.8,0.6]); % inside
% End of .M file.
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -