%aa=wavread('tezhengtiqu1.wav')[x,fs,bits]=wavread('抢地主0.wav');%读入声音文件(*.wav)data1=x(:,1);n=0:length(x)-1;time=n/fs;%对采集数据作滤波处理blocksize=length(data1);%计算窗函数长度window=hanning(blocksize);%计算汉宁窗函数(此函数为MATLAB自带)data2=window.*data1;%对数据先作加窗处理wp=3000*2/fs;[b,a]=ellip(4,0.1,20,wp);%构造椭圆滤波器data=filter(b,a,data2);%plot(data);%求加窗处理后的数据经过滤波器的响应[xmax,index]=max(data1);timewin=floor(0.015*fs);xwin=data1(index-timewin:index+timewin);[y,lags]=xcov(xwin);ylen=length(y);halflen=(ylen+1)/2+30;yy=y(halflen:ylen);%画基频图plot(yy);[ymax,maxindex]=max(yy);fmax=fs/(maxindex+30);%fmaxce2;fmaxce2=fmax;%fmax=roundn(fmax,-3);fmax21=roundn((fmax-5),3);fmax22=roundn((fmax+5),3);%fmax2=[fmax21,'~~',fmax22];projfile=fullfile(matlabroot,'toolbox','yuyin101','PID.pjt')projpath=fileparts(projfile)open(cc,projfile)visible(cc,1)cd(cc,projpath)build(cc,'all',60)load(cc,'Timer.out',30)open(cc,'main.c','text')activate(cc,'main.c','text')insert(cc,'main.c',61)halt(cc)restart(cc)run(cc,'runtohalt',50)ddatV=read(cc,address(cc,'JP1'),'int16',1)JP1=int16(fmaxce2);ddatV=JP1;%idatV=read(cc,address(cc,'fOut'),'single',256)%write(cc,address(cc,'JP1'),fmaxce2));run(cc,'runtohalt')%ddatV=read(cc,address(cc,'fIn'),'single',256)%idattV=read(cc,address(cc,'fOut'),'single',1000)%plot(abs(idattV))