📄 pitchspectrum.m
字号:
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); % 获得当前的colormap
% cmap = colormap; % 获得当前colormap里的颜色数
% [numColors, nCol] = size(cmap);
% nBckColor = round(numColors*1/3); % 把前1/3的颜色变违背景色, 具体数目你自己调
% cmap(1:nBckColor,:) = ones(nBckColor, nCol); % 改变当前的colormap
% colormap(cmap);
% xlabel('1_Time (seconds)');
% y坐标轴
% 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; % 等高线的数目
% 产生划分等高线的一系列数值
% cLines = linspace(min(min(abs(B))), max(max(abs(B))), numCLines);
% 开始画填充的等高线,把最小的那一段去掉,也就没有背景了
% 或者从第三块开始,这些都可以通过修改下面的cLines里的下标来实现
% contourf(t, f, abs(B), cLines(2:numCLines));
% xlabel('2_Time (seconds)'); % x坐标轴
% ylabel('2_Frequency (Hz)'); % y坐标轴
% title('2_Spectrogram'); % title('The frequency');
%----------- 基音提取--------------------------------------------
p = PitchContour(v,fs,window,shift)
figure;
length(p)
length(T)
%for (k = 0:length(T))
% (floor)T1 = T(k):T(k+1)
plot(0:0.0116:3.5875,p(1:length(p)));
%end
set(gcf, 'Color',[0.8,0.8,0.8]); % outside
set(gca,'Color',[0.8,0.8,0.6]); % inside
% End of .M file.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -