Mercurial > hg > gccphat-windowing
changeset 0:ab043bd3b162 tip
First commit
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Functions/createMat.m Mon Jun 11 17:42:13 2012 +0100 @@ -0,0 +1,69 @@ +function [matOut,numFrames]=createMat(x,frameSize,hopSize) + +% create a matrix of frames of input x +% +% Input: +% - x: 1 or 2 column vector (audio data) +% - frameSize: size of frames +% - hopSize: number of samples overlap +% +% Output: +% - matOut: matrix of frames, either (frameSize x numFrames) for 1 +% channel or (framSize x 2 x numFrames) for stereo +% - numFrames: number of frames in matOut +% +% Developer: - Alice Clifford (alice.clifford@eecs.qmul.ac.uk) + +sizeX=size(x); + +if sizeX(1)==1 || sizeX(1)==2 + x=x'; %make columns +end + +sizeX=size(x); + +if sizeX(2)==1 + fileType='mono'; +elseif sizeX(2)==2 + fileType='stereo'; +else + error('Input is neither mono or stereo') +end + + +numFrames=(floor(length(x)/hopSize)); + +for n=1:numFrames + + xStart=(n-1)*(hopSize)+1; + xEnd=(n-1)*(hopSize)+frameSize; + + %Break if frame index goes over length of x + if(xEnd>length(x)) + break + end + + + if strcmp(fileType,'stereo') + xframe=x(xStart:xEnd,:); + matOut(:,:,n)=xframe; + + elseif strcmp(fileType,'mono') + xframe=x(xStart:xEnd); + matOut(:,n)=xframe; + else + error('File type unknown') + end + +end + +sMat=size(matOut); + +if strcmp(fileType,'stereo') + + numFrames=sMat(3); + +elseif strcmp(fileType,'mono') + + numFrames=sMat(2); +end \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Functions/gccPHATFunc_win.m Mon Jun 11 17:42:13 2012 +0100 @@ -0,0 +1,35 @@ +function [frameDelayVec]=gccPHATFunc_win(x,frameSize,hopSize,windowShape) +% calculate the GCC-PHAT delay estimation on frames of data +% +% Input: +% - x: stereo audio file. x(:,2) is delayed +% - frameSize: size of frames (samples) +% - hopSize: overlap between frames (samples) +% - windowShape: string passed to window() +% +% Output: +% - frameDelayVec: array of delay estimation for each frame +% +% Developers: - Alice Clifford (alice.clifford@eecs.qmul.ac.uk) + +[xMat,numFrames]=createMat(x,frameSize,hopSize); + +w=repmat(window(windowShape,frameSize),[1 2 numFrames]); + +X=fft(xMat.*w); %FFT of each frame with window applied + +for n=1:numFrames + + %GCC-PHAT + Sxs=X(:,2,n).*conj(X(:,1,n)); + + S=Sxs./abs(Sxs); + + s=ifft(S); + + [dummy,frameDelay]=max(s(1:frameSize/2)); %assume delay in first frameSize/2 samples + + frameDelayVec(n)=frameDelay-1; %compensate for index starting at 1 + + +end
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Functions/percCorr.m Mon Jun 11 17:42:13 2012 +0100 @@ -0,0 +1,31 @@ +function [percHits]=percCorr(in,delay,err) +%calculate percentage of values in an array are within a defined value with +%an error +% Input: +% - in: vector to test +% - delay: correct value +% - err: error +/- +% +% Output: +% - percHits: percentage of correct values +% +% Developers: - Alice Clifford (alice.clifford@eecs.qmul.ac.uk) + + +y=zeros(length(in),1); + +for n=1:length(in); + + for k=-err:err + if in(n)==delay+k + y(n)=1; + end + end +end + +y=y(y==1); + + +numHits=length(y); + +percHits=(numHits/length(in))*100;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Real/SpectralAnalysis/README.txt Mon Jun 11 17:42:13 2012 +0100 @@ -0,0 +1,5 @@ +This data was collected using the MIRToolbox + +[Lartillot and Toiviainen, 2007] Lartillot, O. and Toiviainen, P. (2007). A matlab toolbox for musical feature extraction from audio. In Proc. of the 10 th Int. Conference on Digital Audio Effects (DAFx-07),. + +'specSpreadData.mat' contains spectral spread data for all audio samples. \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Real/accuracyVspecSpread.m Mon Jun 11 17:42:13 2012 +0100 @@ -0,0 +1,143 @@ +%script to plot the accuracy of Rectangular and Hann window for different windowshapes against spectral spread of audio file + +%Developer: - Alice Clifford (alice.clifford@eecs.qmul.ac.uk) + +clear all +close all + + +load 'Results/accuracyData_290512_frameSize2048' +load 'SpectralAnalysis/specSpreadData' + + +figWidth=7; +figHeight=4; + +fid=fopen('analysisInstNames_041112.txt'); +tempNames=textscan(fid,'%s'); +numNames=length(tempNames{1}); + +instNames=cell(numNames,1); + + +for n=1:numNames + instNames{n}=tempNames{1}{n}; +end + + + + + +percHits_rect=percHitsMat(:,7); %extract data for rectangular window + +figure + +set(gcf, 'units', 'inches', 'pos', [0 1000 figWidth figHeight]) + +scatter(spreadData,percHits_rect,'k.') + +set(gca,'FontSize',8) +ylim([0 100]) +xlim([min(spreadData)-100 max(spreadData)+100]) + + + +%PLOT TEXT LABELS +for n=1:length(percHits_rect) + if n==11 %Electric Guitar + text(spreadData(n)-600,percHits_rect(n),instNames{n},'FontSize',8); + + elseif n==17 %Bass Recorder + + text(spreadData(n)+50,percHits_rect(n),instNames{n},'FontSize',8); + elseif n==1 %Female Vocal + + text(spreadData(n)+50,percHits_rect(n),instNames{n},'FontSize',8); + elseif n==14 %Shaker + + text(spreadData(n)-350,percHits_rect(n)-2,instNames{n},'FontSize',8); + + elseif n==15 %Tambourine + + text(spreadData(n)-550,percHits_rect(n),instNames{n},'FontSize',8); + + + elseif n==4 %Snare + + text(spreadData(n)+50,percHits_rect(n),instNames{n},'FontSize',8); + + + elseif n==12 %Male Vocal + + text(spreadData(n)-450,percHits_rect(n),instNames{n},'FontSize',8); + + elseif n==8 %Violin + + text(spreadData(n)+50,percHits_rect(n)-2,instNames{n},'FontSize',8); + elseif n==13 %Rhodes + + text(spreadData(n)+50,percHits_rect(n)+2,instNames{n},'FontSize',8); + + elseif n==16 %Acoustic Guitar + + text(spreadData(n)-625,percHits_rect(n),instNames{n},'FontSize',8); + + else + text(spreadData(n)+50,percHits_rect(n),instNames{n},'FontSize',8); + end +end + + +lsline + + +ylabel('Accuracy (%)') +xlabel('Spectral Spread') + + + + + + + + + + + + + + +%HANN WINDOW + + + +percHits_hann=percHitsMat(:,6); %set data for hann window + + +figure +set(gcf, 'units', 'inches', 'pos', [1000 300 figWidth figHeight]) + +scatter(spreadData,percHits_hann,'k.') +set(gca,'FontSize',8) + +ylim([99.3 100]) +xlim([min(spreadData)-100 max(spreadData)+100]) + +%PLOT TEXT LABELS + +for n=1:length(percHits_hann) + if n==13 %Rhodes + text(spreadData(n)+50,percHits_hann(n),instNames{n},'FontSize',8); + elseif n==11 %Electric Guitar + text(spreadData(n)-550,percHits_hann(n),instNames{n},'FontSize',8); + elseif n==16 %Acoustic Guitar + text(spreadData(n)-600,percHits_hann(n),instNames{n},'FontSize',8); + else + text(spreadData(n)+50,percHits_hann(n),instNames{n},'FontSize',8); + end +end + +lsline + +ylabel('Accuracy (%)') +xlabel('Spectral Spread')
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Real/analysisFileNames_041112.txt Mon Jun 11 17:42:13 2012 +0100 @@ -0,0 +1,20 @@ +angthom_FemaleLeadVox.wav +angthom_Kick.wav +angthom_Piano.wav +angthom_Snare.wav +anim_BassSynth.wav +merc_Horns.wav +merc_Tubas.wav +merc_Violin.wav +moos_BassGtrDI.wav +moos_Claps.wav +moos_ElecGtr.wav +moos_MaleLeadVox.wav +moos_Rhodes.wav +moos_Shaker.wav +moos_Tambourine.wav +wolf_AcGuitar.wav +wolf_BassRecorder.wav +wolf_Mandolin.wav +wolf_Recorder.wav +wolf_TinWhistle.wav \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Real/analysisInstNames_041112.txt Mon Jun 11 17:42:13 2012 +0100 @@ -0,0 +1,20 @@ +FemaleVocal +Kick +Piano +Snare +BassSynth +Horns +Tubas +Violin +BassGuitar +Claps +ElectricGuitar +MaleVocal +Rhodes +Shaker +Tambourine +AcousticGuitar +BassRecorder +Mandolin +Recorder +TinWhistle \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Real/plotAllFramesAllWindows.m Mon Jun 11 17:42:13 2012 +0100 @@ -0,0 +1,53 @@ +%Script to plot mean accuracy data of all audio samples for each window +%against frame size + +% Developer: - Alice Clifford (alice.clifford@eecs.qmul.ac.uk) + + +clear all +close all + +frameSizeVec=[128 256 512 1024 2048 4096 8192]; %framesizes tested +frameSizeLabels=cell(length(frameSizeVec),1); + + +for f=1:length(frameSizeVec) + load(strcat('accuracyData_290512_framesize',int2str(frameSizeVec(f)))); + meanPercHits(f,:)=mean(percHitsMat); + + frameSizeLabels{f}=int2str(frameSizeVec(f)); + +end + + + +figure +figWidth=7; +figHeight=3.5; +set(gcf, 'units', 'inches', 'pos', [0 1000 figWidth figHeight]) + +colorVec=(linspace(0,0.5,2))'; +colorMat=[colorVec colorVec colorVec]; + +set(gcf,'DefaultAxesColorOrder',colorMat) +set(gcf,'DefaultAxesLineStyleOrder','-|--|:|-.') + +set(gca,'FontSize',8) + + +plot(meanPercHits,'LineWidth',2) + + +winShapesLabels={ + 'Blackman'; + 'Blackman-Harris'; + 'Flat Top'; + 'Gaussian'; + 'Hamming'; + 'Hann'; + 'Rectangular';} + +set(gca,'xticklabel',frameSizeLabels) +xlabel('Framesize (samples)') +ylabel('Mean accuracy (%)') +legend(winShapesLabels,'Location','SouthEast') \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Real/runAllAnalysis_20files_7windows_7framesizes.m Mon Jun 11 17:42:13 2012 +0100 @@ -0,0 +1,78 @@ +%Script to run analysis of 20 audio samples. GCC-PHAT is calculated for +%each audio sample using all framesizes in frameSizeVec and windows in +%winShapes + + +% Developer: - Alice Clifford (alice.clifford@eecs.qmul.ac.uk) + + +close all +clear all + +Fs=44100; + + +frameSizeVec=[128 256 512 1024 2048 4096 8192]; %framesizes to test + +winShapes={ %window shapes to test + 'blackman', + 'blackmanharris', + 'flattopwin', + 'gausswin', + 'hamming', + 'hann', + 'rectwin', + }; + +ds=50; %actual delay derived from visual analysis + +PATH='audio/'; +fid=fopen('analysisFileNames_041112.txt'); +tempNames=textscan(fid,'%s'); + +numFiles=length(tempNames{1}); + +fileNames=cell(numFiles,1); + + +for f=1:length(frameSizeVec) + f + frameSize=frameSizeVec(f); + hopSize=frameSize/4; + + for n=1:numFiles + n + fileNames{n}=tempNames{1}{n}; + fullPath=strcat(PATH,fileNames{n}); + + + + [x,Fs]=wavread(fullPath); + + for w=1:length(winShapes) + w + + delayVec(:,n,w)=gccPHATFunc_win(x,frameSize,hopSize,winShapes{w}); + percHitsMat(n,w)=percCorr(delayVec(:,n,w),ds,2); %estimate percentage correct + end + + + + + end + + +% save(strcat('Results/accuracyData_240512_framesize',int2str(frameSize))) +% %uncomment to save results + + clear delayVec percHitsMat mseMat euclidMat + + + + + + + +end + +display('Instrument audio analysis complete')
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Simulation/createFiltNoise.m Mon Jun 11 17:42:13 2012 +0100 @@ -0,0 +1,60 @@ +function [output]=createFiltNoise(input,centreFreq,bandWidth,filterOrder,Fs) + +% create filtered noise for bandwidth simulation +% +% Input: +% - input: input to be filtered +% - centreFreq: centre frequency or cutoff frequency +% - bandWidth: width of filter +% - filterOrder: order of butterworth filter (4) +% - Fs: sampling frequency (44100) +% +% Output: +% - output: array +% + +% Developer: - Alice Clifford (alice.clifford@eecs.qmul.ac.uk) + + + +if centreFreq==0 %LOW PASS FILTER FOR CENTRE FREQ ==0 + + cutoffFreq=bandWidth; + + normCutFreq=(cutoffFreq/(Fs/2)); + + [b,a]=butter(filterOrder,normCutFreq,'low'); + + output=filter(b,a,input); + + + +elseif centreFreq==22050 %HIGH PASS FILTER FOR CENTREFREQ == FS/2 + + cutoffFreq=(Fs/2)-bandWidth; + + normCutFreq=(cutoffFreq/(Fs/2)); + + [b,a]=butter(filterOrder,normCutFreq,'high'); %HIGH PASS FILTER + + output=filter(b,a,input); + + + + +else% %BAND PASS - NEED LOW AND HIGH PASS + + lowBandFreq=centreFreq-(bandWidth/2); + highBandFreq=centreFreq+(bandWidth/2); + + highNormBandFreq=(highBandFreq/(Fs/2)); + lowNormBandFreq=(lowBandFreq/(Fs/2)); + + + [b,a]=butter(filterOrder,[lowNormBandFreq highNormBandFreq]); + + + + output=filter(b,a,input); + +end \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Simulation/plotAllWin_lowPass.m Mon Jun 11 17:42:13 2012 +0100 @@ -0,0 +1,61 @@ +%Script to plot accuracy for all windows with low pass filtered noise as +%input + +% Developer: - Alice Clifford (alice.clifford@eecs.qmul.ac.uk) + + +clear all +close all + +winShapes={ + 'blackman', + 'blackmanharris', + 'flattopwin', + 'gausswin', + 'hamming', + 'hann', + 'rectwin', + }; + +winShapesLabels={ + 'Blackman'; + 'Blackman-Harris'; + 'Flat Top'; + 'Gaussian'; + 'Hamming'; + 'Hann'; + 'Rectangular';} + + +for w=1:length(winShapes) + load(strcat('noiseExpandBand_',winShapes{w})); + percHitsMat=percHitsMat'; + + allWinPercHitsMat(:,w)=percHitsMat(:,1); + + +end + + + +figure + +figWidth=7; +figHeight=3; +set(gcf, 'units', 'inches', 'pos', [0 1000 figWidth figHeight]) + +colorVec=(linspace(0,0.5,2))'; + +colorMat=[colorVec colorVec colorVec]; + +set(gcf,'DefaultAxesColorOrder',colorMat) +set(gcf,'DefaultAxesLineStyleOrder','-|--|:|-.') + +set(gca,'FontSize',8) + +semilogx(bandWidth,allWinPercHitsMat,'LineWidth',2) +xlim([min(bandWidth) 22050]) + +xlabel('Bandwidth (Hz)') +ylabel('Accuracy (%)') +legend(winShapesLabels,'Location','SouthEast') \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Simulation/plotRectWin_allBandwidth.m Mon Jun 11 17:42:13 2012 +0100 @@ -0,0 +1,46 @@ +%Plots accuracy for all filters for rectangular window + +% Developer: - Alice Clifford (alice.clifford@eecs.qmul.ac.uk) + + +clear all +close all + +load noiseExpandBand_rectwin + +clear percHits %ZERO MATRIX ACCIDENTAL + +percHitsMat=percHitsMat'; + + + +for c=1:length(centreFreq) + centreFreqLegend{c}=strcat(int2str(centreFreq(c)),' Hz'); +end + +figure + +figWidth=3.7; +figHeight=3.5; +set(gcf, 'units', 'inches', 'pos', [0 1000 figWidth figHeight]) + + + +colorVec=(linspace(0,0.5,2))'; +colorMat=[colorVec colorVec colorVec]; + +set(gcf,'DefaultAxesColorOrder',colorMat) +set(gcf,'DefaultAxesLineStyleOrder','-|--|:|-.') + +set(gca,'FontSize',8) + +semilogx(bandWidth,percHitsMat,'LineWidth',2) + +xlim([min(bandWidth) 22050]) + + +xlabel('Bandwidth (Hz)') +ylabel('Accuracy (%)') + +legend('Low Pass','Band Pass','High Pass','Location','NorthWest') +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Simulation/runAnalysis_filteredNoise_simulation.m Mon Jun 11 17:42:13 2012 +0100 @@ -0,0 +1,88 @@ +%Script to run delay estimation analysis of filtered white noise at various +%bandwidths and with different window shapes + + +% Developer: - Alice Clifford (alice.clifford@eecs.qmul.ac.uk) + + + +clear all +close all + +addpath ../Functions + +Fs=44100; +T=10; + + +winShapes={ + 'blackman', + 'blackmanharris', + 'flattopwin', + 'gausswin', + 'hamming', + 'hann', + 'rectwin', + }; + + +ds=10; %simulated delay (samples) + +input=randn((T*Fs)+ds+1,1); +input=input./max(abs(input)); %white noise input + +centreFreq=[0 11025 22050]; %centre frequencies (LP, BP, HP) + +bandWidth=logspace(1,5,500); %bandwidths + +bandWidth=(bandWidth(bandWidth>50)); +bandWidth=bandWidth(bandWidth<22050); +bandWidth=round(bandWidth); + + +percHits=zeros(length(bandWidth),length(centreFreq)); + +filterOrder=4; +freqVec=linspace(0,Fs,length(input)); + +frameSize=2048; +hopSize=frameSize/4; + + +for w=1:length(winShapes) + + for n=1:length(centreFreq) + + for m=1:length(bandWidth) + + + [w n m] + %CREATE FILTERED NOISE VECTOR FROM CENTRE FREQ AND BANDWIDTH + filtNoise=createFiltNoise(input,centreFreq(n),bandWidth(m),filterOrder,Fs); + + %CREATE DELAYED SIGNAL + x=zeros(length(filtNoise),2); + + x(:,1)=filtNoise; + x(:,2)=filter([zeros(ds,1);1],1,filtNoise); + + x=x(ds+1:end,:); + + + delayVec=gccPHATFunc_win(x,frameSize,hopSize,winShapes{w}); + percHitsMat(n,m)=percCorr(delayVec,ds,2); + + + end + + + end + clear x filtNoise + + %save(strcat('Results/noiseExpandBand_',winShapes{w})); %uncomment to + %save data + +end + +toc +