├── .gitattributes ├── 3personePCM.wav ├── FrameWorkGenerale.pdf ├── ISTFT.m ├── OLAfft.asv ├── OLAfft.m ├── README.md ├── STFT.m ├── SpazioParametri.pdf ├── Toms_diner.wav ├── appunti.pdf ├── audioappunti ├── Appunti.pdf └── STFT_IFFT.pdf ├── audiopossibili ├── 3personepcm.wav ├── Magica.wav ├── Toms_diner.wav ├── Toms_diner22.wav ├── non_mi_somiglia.wav ├── nonmisomiglia22.wav ├── rotto_le_palle.wav └── voiced_a.wav ├── benigni_new.wav ├── featureF.m ├── features.asv ├── features.m ├── featuresB.asv ├── featuresB.m ├── geometria.asv ├── geometria.m ├── img ├── PowerPoint │ ├── 3personePCM.wav │ ├── Corrispondenza1.fig │ ├── Features.jpg │ ├── FeaturesBW.jpg │ ├── Features_2d.jpg │ ├── Features_2d1.jpg │ ├── Orig_Ric_STFT.jpg │ ├── Orig_Ric_time.jpg │ ├── Rumore_Reg.jpg │ ├── Rumore_Ric.jpg │ ├── Rumore_originali.jpg │ ├── STFT11_bw.jpg │ ├── STFT11_color.jpg │ ├── STFT12_color.jpg │ ├── STFT13_color.jpg │ ├── STFT21_color.jpg │ ├── STFT22_color.jpg │ ├── STFT23_color.jpg │ ├── STFT31_color.jpg │ ├── STFT32_color.jpg │ ├── STFT33_color.jpg │ ├── Thumbs.db │ ├── Toms_diner.wav │ ├── configurazione.jpg │ ├── originali1.jpg │ ├── presentazione.pptx │ ├── reg1_noise.wav │ ├── reg2_noise.wav │ ├── registrazioni1.jpg │ ├── ric11Toms.wav │ ├── ric12Persone.wav │ ├── ric13Masch.wav │ ├── ric1ing.wav │ ├── ric21PersoneWrong.wav │ ├── ric22Wrong.wav │ ├── ric23MaschileWrong.wav │ ├── ric2spa.wav │ ├── ric31Toms.wav │ ├── ric32Persone.wav │ ├── ric33Maschile.wav │ ├── ricostruita_masc.wav │ ├── ricostruita_noise.wav │ ├── ricostruite1.jpg │ ├── ricostruite2.jpg │ ├── ricostruite3.jpg │ ├── rss_mA.wav │ ├── rss_mB.wav │ ├── rumore.wav │ ├── schiera.JPG │ ├── voce_maschile.wav │ └── ~$presentazione.pptx ├── Progetto │ ├── 3mic_mmmm_mix1.wav │ ├── 3mic_mmmm_mix2.wav │ ├── 3mic_mmmm_mix3.wav │ ├── 3mic_mmmm_shift2_1.wav │ ├── 3mic_mmmm_shift2_2.wav │ ├── 3mic_mmmm_shift2_3.wav │ ├── 3mic_mmmm_shift2_4.wav │ ├── 3persone.wav │ ├── 3personePCM.wav │ ├── A_maschile.wav │ ├── Appunti.pdf │ ├── ArticoloInternet1.pdf │ ├── ArticoloSeparazione.pdf │ ├── Articolo_ortogonal.pdf │ ├── Bella_Casa.wav │ ├── Brutta_Casa.wav │ ├── Codice_mod │ │ ├── Toms_diner22.wav │ │ ├── Urlo22.wav │ │ ├── nonmisomiglia22.wav │ │ ├── proveaudio.m │ │ ├── readme.txt │ │ ├── stft.m │ │ └── stft_sintesys.m │ ├── E_femminile.wav │ ├── FrameWorkGenerale.pdf │ ├── ISTFT.asv │ ├── ISTFT.m │ ├── Mic1.wav │ ├── Mic1ric.wav │ ├── Mic2.wav │ ├── Mic2ric.wav │ ├── Nuova_Rob │ │ ├── features.m │ │ ├── featuresB.m │ │ ├── geometria.asv │ │ ├── geometria.m │ │ └── readme.txt │ ├── PowerPoint │ │ ├── Corrispondenza1.fig │ │ ├── Features.jpg │ │ ├── Features_2d.jpg │ │ ├── Orig_Ric_STFT.jpg │ │ ├── Orig_Ric_time.jpg │ │ ├── Thumbs.db │ │ ├── configurazione.jpg │ │ ├── presentazione.pptx │ │ └── ~$presentazione.pptx │ ├── Prove_Varie.m │ ├── Ritardi_2.asv │ ├── Ritardi_2.m │ ├── Ritardig.asv │ ├── Ritardig.m │ ├── STFT.asv │ ├── STFT.m │ ├── STFT3personeRif.jpg │ ├── STFTMicrofoni.jpg │ ├── STFT_FFT.m │ ├── STFT_Sintesys.asv │ ├── STFT_Sintesys.m │ ├── SpazioParametri.pdf │ ├── TataProj_Spect.asv │ ├── TataProj_Spect.m │ ├── TataProj_sin.asv │ ├── TataProj_sin.m │ ├── Thumbs.db │ ├── Toms_diner.wav │ ├── features.m │ ├── finkle.wav │ ├── geometria.m │ ├── gotowork.wav │ ├── ifusayno.wav │ ├── performance.asv │ ├── performance.m │ ├── prestazioni_prove.asv │ ├── prestazioni_prove.m │ ├── progetto.asv │ ├── progetto.m │ ├── progetto3f.m │ ├── progettoFs.m │ ├── progetto_2.asv │ ├── progetto_2.m │ ├── progetto_fraz.asv │ ├── progetto_fraz.m │ ├── progetto_internet.asv │ ├── progetto_internet.m │ ├── progetto_internet1.m │ ├── progetto_internet2.asv │ ├── progetto_internet2.m │ ├── progetto_unwrap.asv │ ├── progetto_unwrap.m │ ├── rihanna.mp3 │ ├── ritardi.m │ ├── rss_mA.wav │ ├── rss_mB.wav │ ├── rssd_A.wav │ ├── rssd_B.wav │ ├── s1.wav │ ├── s2.wav │ ├── s3.wav │ ├── segnali.asv │ ├── segnali.m │ ├── serioustherapy.wav │ ├── sfasamenti.m │ ├── trippy.wav │ ├── voce_maschile.wav │ ├── voiced_a.wav │ ├── wavexread.m │ ├── wavexwrite.m │ ├── x3_1.wav │ └── x3_2.wav ├── ProgettoBSS.odp ├── ProgettoBSS.ppt ├── STFTs.jpg ├── diffefase.jpg ├── maschere.jpg ├── readme.txt ├── segnali.jpg ├── spettro_mic1_orig.jpg ├── spettro_s1.jpg ├── spettro_s2.jpg ├── spettro_s3.jpg └── trasfe.jpg ├── istft.asv ├── istft2.asv ├── istft2.m ├── istftnew.m ├── magica_new.wav ├── newstft.asv ├── newstft.m ├── presentazione.pdf ├── progetto.asv ├── progetto.m ├── progetto_audio_modfile.aup ├── progetto_audio_modfile_data ├── b00010.auf ├── b00019.au ├── b00028.au ├── b00029.au ├── b00031.au └── b00033.au ├── readme.txt ├── ritfraz.asv ├── ritfraz.m ├── stft.asv ├── stft_sintesys.asv ├── stft_sintesys.m ├── tipoB.asv ├── tipoB.m ├── toms_new.wav ├── voce_maschile.wav ├── wavexread.m └── wavexwrite.m /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto -------------------------------------------------------------------------------- /3personePCM.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/3personePCM.wav -------------------------------------------------------------------------------- /FrameWorkGenerale.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/FrameWorkGenerale.pdf -------------------------------------------------------------------------------- /ISTFT.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/ISTFT.m -------------------------------------------------------------------------------- /OLAfft.asv: -------------------------------------------------------------------------------- 1 | %&Implementazione STFT 2 | % 3 | % av=percentuale di avanzamento espressa in forma decimale es. 50%=0.5 4 | % win=tipo di finestra 5 | 6 | 7 | 8 | function [fourier1]=OLAfft(signal1,win,av) 9 | 10 | durata=length(signal1); %durata segnale 11 | pas=length(win); %durata finestra 12 | 13 | splice1=zeros(pas,(fix(durata/(pas*av)))+1); 14 | part1=zeros(pas,(fix(durata/(pas*av)))+1); 15 | 16 | splice1(1:pas,1)=signal1(1:pas,1)'.*win'; 17 | part1(1:pas,1)=splice1(1:pas,1); 18 | 19 | cicli=fix((durata-pas)/(pas/2)); 20 | 21 | for i=2:cicli; 22 | 23 | start=1+(i-1)*(pas*av); %avanza del 50% 24 | fin=start+pas-1; 25 | part1(1:pas,i)=signal1(start:fin,1); 26 | splice1(1:pas,i)=part1(1:pas,i)'.*win'; 27 | end; 28 | resto=rem(durata,(pas*av)); 29 | fin=fix(durata/(pas*av))*(pas*av); 30 | part1(1:pas,(fix(durata/(pas*av))-1))=[signal1(fin:durata,1); zeros((pas-resto-1),1)]; 31 | splice1(1:pas,(fix(durata/(pas*av))-1))=part1(1:pas,(fix(durata/(pas*av))-1))'.*win'; 32 | 33 | for i=1:fix(durata/(pas*av))-1; 34 | 35 | fourier1(1:pas,i)=fftshift(fft(splice1(1:pas,i))); 36 | 37 | end; 38 | 39 | -------------------------------------------------------------------------------- /OLAfft.m: -------------------------------------------------------------------------------- 1 | %&Implementazione STFT 2 | % 3 | % av=percentuale di avanzamento espressa in forma decimale es. 50%=0.5 4 | % win=tipo di finestra 5 | 6 | 7 | 8 | function [fourier1]=OLAfft(signal1,win,av) 9 | 10 | durata=length(signal1); %durata segnale 11 | pas=length(win); %durata finestra 12 | 13 | splice1=zeros(pas,(fix(durata/(pas*av)))+1); 14 | part1=zeros(pas,(fix(durata/(pas*av)))+1); 15 | 16 | splice1(1:pas,1)=signal1(1:pas,1)'.*win'; 17 | part1(1:pas,1)=splice1(1:pas,1); 18 | 19 | cicli=fix((durata-pas)/(pas/2)); 20 | 21 | for i=2:cicli; 22 | 23 | start=1+(i-1)*(pas*av); %avanza del 50% 24 | fin=start+pas-1; 25 | part1(1:pas,i)=signal1(start:fin,1); 26 | splice1(1:pas,i)=part1(1:pas,i)'.*win'; 27 | end; 28 | resto=rem(durata,(pas*av)); 29 | fin=fix(durata/(pas*av))*(pas*av); 30 | part1(1:pas,(fix(durata/(pas*av))-1))=[signal1(fin:durata,1); zeros((pas-resto-1),1)]; 31 | splice1(1:pas,(fix(durata/(pas*av))-1))=part1(1:pas,(fix(durata/(pas*av))-1))'.*win'; 32 | 33 | for i=1:fix(durata/(pas*av))-1; 34 | 35 | fourier1(1:pas,i)=fftshift(fft(splice1(1:pas,i))); 36 | 37 | end; 38 | 39 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BlindSourceSeparation 2 | -------------------------------------------------------------------------------- /STFT.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/STFT.m -------------------------------------------------------------------------------- /SpazioParametri.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/SpazioParametri.pdf -------------------------------------------------------------------------------- /Toms_diner.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/Toms_diner.wav -------------------------------------------------------------------------------- /appunti.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/appunti.pdf -------------------------------------------------------------------------------- /audioappunti/Appunti.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/audioappunti/Appunti.pdf -------------------------------------------------------------------------------- /audioappunti/STFT_IFFT.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/audioappunti/STFT_IFFT.pdf -------------------------------------------------------------------------------- /audiopossibili/3personepcm.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/audiopossibili/3personepcm.wav -------------------------------------------------------------------------------- /audiopossibili/Magica.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/audiopossibili/Magica.wav -------------------------------------------------------------------------------- /audiopossibili/Toms_diner.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/audiopossibili/Toms_diner.wav -------------------------------------------------------------------------------- /audiopossibili/Toms_diner22.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/audiopossibili/Toms_diner22.wav -------------------------------------------------------------------------------- /audiopossibili/non_mi_somiglia.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/audiopossibili/non_mi_somiglia.wav -------------------------------------------------------------------------------- /audiopossibili/nonmisomiglia22.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/audiopossibili/nonmisomiglia22.wav -------------------------------------------------------------------------------- /audiopossibili/rotto_le_palle.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/audiopossibili/rotto_le_palle.wav -------------------------------------------------------------------------------- /audiopossibili/voiced_a.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/audiopossibili/voiced_a.wav -------------------------------------------------------------------------------- /benigni_new.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/benigni_new.wav -------------------------------------------------------------------------------- /featureF.m: -------------------------------------------------------------------------------- 1 | function [theta]=featureF(fmic1,fmic2) 2 | 3 | A=abs(fmic1).^2+abs(fmic2).^2; 4 | 5 | og1=abs(fmic1)./A; 6 | og2=abs(fmic2)./A; 7 | -------------------------------------------------------------------------------- /features.asv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/features.asv -------------------------------------------------------------------------------- /features.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/features.m -------------------------------------------------------------------------------- /featuresB.asv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/featuresB.asv -------------------------------------------------------------------------------- /featuresB.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/featuresB.m -------------------------------------------------------------------------------- /geometria.asv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/geometria.asv -------------------------------------------------------------------------------- /geometria.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/geometria.m -------------------------------------------------------------------------------- /img/PowerPoint/3personePCM.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/PowerPoint/3personePCM.wav -------------------------------------------------------------------------------- /img/PowerPoint/Corrispondenza1.fig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/PowerPoint/Corrispondenza1.fig -------------------------------------------------------------------------------- /img/PowerPoint/Features.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/PowerPoint/Features.jpg -------------------------------------------------------------------------------- /img/PowerPoint/FeaturesBW.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/PowerPoint/FeaturesBW.jpg -------------------------------------------------------------------------------- /img/PowerPoint/Features_2d.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/PowerPoint/Features_2d.jpg -------------------------------------------------------------------------------- /img/PowerPoint/Features_2d1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/PowerPoint/Features_2d1.jpg -------------------------------------------------------------------------------- /img/PowerPoint/Orig_Ric_STFT.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/PowerPoint/Orig_Ric_STFT.jpg -------------------------------------------------------------------------------- /img/PowerPoint/Orig_Ric_time.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/PowerPoint/Orig_Ric_time.jpg -------------------------------------------------------------------------------- /img/PowerPoint/Rumore_Reg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/PowerPoint/Rumore_Reg.jpg -------------------------------------------------------------------------------- /img/PowerPoint/Rumore_Ric.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/PowerPoint/Rumore_Ric.jpg -------------------------------------------------------------------------------- /img/PowerPoint/Rumore_originali.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/PowerPoint/Rumore_originali.jpg -------------------------------------------------------------------------------- /img/PowerPoint/STFT11_bw.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/PowerPoint/STFT11_bw.jpg -------------------------------------------------------------------------------- /img/PowerPoint/STFT11_color.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/PowerPoint/STFT11_color.jpg -------------------------------------------------------------------------------- /img/PowerPoint/STFT12_color.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/PowerPoint/STFT12_color.jpg -------------------------------------------------------------------------------- /img/PowerPoint/STFT13_color.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/PowerPoint/STFT13_color.jpg -------------------------------------------------------------------------------- /img/PowerPoint/STFT21_color.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/PowerPoint/STFT21_color.jpg -------------------------------------------------------------------------------- /img/PowerPoint/STFT22_color.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/PowerPoint/STFT22_color.jpg -------------------------------------------------------------------------------- /img/PowerPoint/STFT23_color.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/PowerPoint/STFT23_color.jpg -------------------------------------------------------------------------------- /img/PowerPoint/STFT31_color.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/PowerPoint/STFT31_color.jpg -------------------------------------------------------------------------------- /img/PowerPoint/STFT32_color.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/PowerPoint/STFT32_color.jpg -------------------------------------------------------------------------------- /img/PowerPoint/STFT33_color.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/PowerPoint/STFT33_color.jpg -------------------------------------------------------------------------------- /img/PowerPoint/Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/PowerPoint/Thumbs.db -------------------------------------------------------------------------------- /img/PowerPoint/Toms_diner.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/PowerPoint/Toms_diner.wav -------------------------------------------------------------------------------- /img/PowerPoint/configurazione.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/PowerPoint/configurazione.jpg -------------------------------------------------------------------------------- /img/PowerPoint/originali1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/PowerPoint/originali1.jpg -------------------------------------------------------------------------------- /img/PowerPoint/presentazione.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/PowerPoint/presentazione.pptx -------------------------------------------------------------------------------- /img/PowerPoint/reg1_noise.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/PowerPoint/reg1_noise.wav -------------------------------------------------------------------------------- /img/PowerPoint/reg2_noise.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/PowerPoint/reg2_noise.wav -------------------------------------------------------------------------------- /img/PowerPoint/registrazioni1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/PowerPoint/registrazioni1.jpg -------------------------------------------------------------------------------- /img/PowerPoint/ric11Toms.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/PowerPoint/ric11Toms.wav -------------------------------------------------------------------------------- /img/PowerPoint/ric12Persone.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/PowerPoint/ric12Persone.wav -------------------------------------------------------------------------------- /img/PowerPoint/ric13Masch.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/PowerPoint/ric13Masch.wav -------------------------------------------------------------------------------- /img/PowerPoint/ric1ing.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/PowerPoint/ric1ing.wav -------------------------------------------------------------------------------- /img/PowerPoint/ric21PersoneWrong.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/PowerPoint/ric21PersoneWrong.wav -------------------------------------------------------------------------------- /img/PowerPoint/ric22Wrong.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/PowerPoint/ric22Wrong.wav -------------------------------------------------------------------------------- /img/PowerPoint/ric23MaschileWrong.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/PowerPoint/ric23MaschileWrong.wav -------------------------------------------------------------------------------- /img/PowerPoint/ric2spa.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/PowerPoint/ric2spa.wav -------------------------------------------------------------------------------- /img/PowerPoint/ric31Toms.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/PowerPoint/ric31Toms.wav -------------------------------------------------------------------------------- /img/PowerPoint/ric32Persone.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/PowerPoint/ric32Persone.wav -------------------------------------------------------------------------------- /img/PowerPoint/ric33Maschile.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/PowerPoint/ric33Maschile.wav -------------------------------------------------------------------------------- /img/PowerPoint/ricostruita_masc.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/PowerPoint/ricostruita_masc.wav -------------------------------------------------------------------------------- /img/PowerPoint/ricostruita_noise.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/PowerPoint/ricostruita_noise.wav -------------------------------------------------------------------------------- /img/PowerPoint/ricostruite1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/PowerPoint/ricostruite1.jpg -------------------------------------------------------------------------------- /img/PowerPoint/ricostruite2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/PowerPoint/ricostruite2.jpg -------------------------------------------------------------------------------- /img/PowerPoint/ricostruite3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/PowerPoint/ricostruite3.jpg -------------------------------------------------------------------------------- /img/PowerPoint/rss_mA.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/PowerPoint/rss_mA.wav -------------------------------------------------------------------------------- /img/PowerPoint/rss_mB.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/PowerPoint/rss_mB.wav -------------------------------------------------------------------------------- /img/PowerPoint/rumore.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/PowerPoint/rumore.wav -------------------------------------------------------------------------------- /img/PowerPoint/schiera.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/PowerPoint/schiera.JPG -------------------------------------------------------------------------------- /img/PowerPoint/voce_maschile.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/PowerPoint/voce_maschile.wav -------------------------------------------------------------------------------- /img/PowerPoint/~$presentazione.pptx: -------------------------------------------------------------------------------- 1 | Charly Charly -------------------------------------------------------------------------------- /img/Progetto/3mic_mmmm_mix1.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/3mic_mmmm_mix1.wav -------------------------------------------------------------------------------- /img/Progetto/3mic_mmmm_mix2.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/3mic_mmmm_mix2.wav -------------------------------------------------------------------------------- /img/Progetto/3mic_mmmm_mix3.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/3mic_mmmm_mix3.wav -------------------------------------------------------------------------------- /img/Progetto/3mic_mmmm_shift2_1.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/3mic_mmmm_shift2_1.wav -------------------------------------------------------------------------------- /img/Progetto/3mic_mmmm_shift2_2.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/3mic_mmmm_shift2_2.wav -------------------------------------------------------------------------------- /img/Progetto/3mic_mmmm_shift2_3.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/3mic_mmmm_shift2_3.wav -------------------------------------------------------------------------------- /img/Progetto/3mic_mmmm_shift2_4.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/3mic_mmmm_shift2_4.wav -------------------------------------------------------------------------------- /img/Progetto/3persone.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/3persone.wav -------------------------------------------------------------------------------- /img/Progetto/3personePCM.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/3personePCM.wav -------------------------------------------------------------------------------- /img/Progetto/A_maschile.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/A_maschile.wav -------------------------------------------------------------------------------- /img/Progetto/Appunti.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/Appunti.pdf -------------------------------------------------------------------------------- /img/Progetto/ArticoloInternet1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/ArticoloInternet1.pdf -------------------------------------------------------------------------------- /img/Progetto/ArticoloSeparazione.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/ArticoloSeparazione.pdf -------------------------------------------------------------------------------- /img/Progetto/Articolo_ortogonal.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/Articolo_ortogonal.pdf -------------------------------------------------------------------------------- /img/Progetto/Bella_Casa.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/Bella_Casa.wav -------------------------------------------------------------------------------- /img/Progetto/Brutta_Casa.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/Brutta_Casa.wav -------------------------------------------------------------------------------- /img/Progetto/Codice_mod/Toms_diner22.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/Codice_mod/Toms_diner22.wav -------------------------------------------------------------------------------- /img/Progetto/Codice_mod/Urlo22.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/Codice_mod/Urlo22.wav -------------------------------------------------------------------------------- /img/Progetto/Codice_mod/nonmisomiglia22.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/Codice_mod/nonmisomiglia22.wav -------------------------------------------------------------------------------- /img/Progetto/Codice_mod/proveaudio.m: -------------------------------------------------------------------------------- 1 | clear all; 2 | close all; 3 | 4 | %creazione finestra 5 | M=512; 6 | win=hamming(M); 7 | 8 | %I segnali importati devono essere tutti campionati alla stessa frequenza 9 | %di campionamento 10 | % [signal1,Fs1]=wavread('Urlo22.wav'); %sono tutti importati come vettori colonna 11 | % [signal2,Fs2]=wavread('Toms_diner22.wav'); 12 | % [signal3,Fs3]=wavread('nonmisomiglia22.wav'); 13 | f1=50; 14 | f2=100; 15 | f3=200; 16 | fc=1e3; %campiono a 1 Khz 17 | t=0:1/fc:4-1/fc; %durata: 4 secondi 18 | signal1=cos(2*pi*f1*t); 19 | signal2=cos(2*pi*f2*t); 20 | signal3=cos(2*pi*f3*t); 21 | 22 | rit1=160; 23 | rit2=560; 24 | rit3=800; 25 | 26 | %definizione segnali al mic2 (ritardati) 27 | signal1r=[zeros(1,rit1) signal1]; 28 | signal2r=[zeros(1,rit2) signal2]; 29 | signal3r=[zeros(1,rit3) signal3]; 30 | 31 | %calcolo la lunghezza massima 32 | maxl=max([length(signal1r) length(signal2r) length(signal3r)]); 33 | minl=min([length(signal1) length(signal2) length(signal3)]); 34 | 35 | signal1=[signal1 zeros(1,(maxl-minl))]; 36 | signal2=[signal2 zeros(1,(maxl-minl))]; 37 | signal3=[signal3 zeros(1,(maxl-minl))]; 38 | signal1r=[signal1r zeros(1,(maxl-length(signal1r)))]; 39 | signal2r=[signal2r zeros(1,(maxl-length(signal2r)))]; 40 | signal3r=[signal3r zeros(1,(maxl-length(signal3r)))]; 41 | 42 | 43 | [F1]=stft(signal1',win,maxl); 44 | [F2]=stft(signal2',win,maxl); 45 | [F3]=stft(signal3',win,maxl); 46 | 47 | %Segnale somma e trasformate al mic1 e al mic2 48 | oss1=signal1+signal2+signal3; 49 | oss2=signal1r+signal2r+signal3r; 50 | [Yos1]=stft(oss1',win,maxl); 51 | [Yos2]=stft(oss2',win,maxl); 52 | 53 | fk=-fc/2:fc/M:fc/2; %asse freq discrete 54 | tk=0:(M/fc):(maxl/fc); 55 | 56 | figure(1); imagesc(tk,fk,abs(Yos1)); 57 | figure(2); imagesc(tk,fk,abs(Yos2)); 58 | 59 | 60 | -------------------------------------------------------------------------------- /img/Progetto/Codice_mod/readme.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/Codice_mod/readme.txt -------------------------------------------------------------------------------- /img/Progetto/Codice_mod/stft.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/Codice_mod/stft.m -------------------------------------------------------------------------------- /img/Progetto/Codice_mod/stft_sintesys.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/Codice_mod/stft_sintesys.m -------------------------------------------------------------------------------- /img/Progetto/E_femminile.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/E_femminile.wav -------------------------------------------------------------------------------- /img/Progetto/FrameWorkGenerale.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/FrameWorkGenerale.pdf -------------------------------------------------------------------------------- /img/Progetto/ISTFT.asv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/ISTFT.asv -------------------------------------------------------------------------------- /img/Progetto/ISTFT.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/ISTFT.m -------------------------------------------------------------------------------- /img/Progetto/Mic1.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/Mic1.wav -------------------------------------------------------------------------------- /img/Progetto/Mic1ric.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/Mic1ric.wav -------------------------------------------------------------------------------- /img/Progetto/Mic2.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/Mic2.wav -------------------------------------------------------------------------------- /img/Progetto/Mic2ric.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/Mic2ric.wav -------------------------------------------------------------------------------- /img/Progetto/Nuova_Rob/features.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/Nuova_Rob/features.m -------------------------------------------------------------------------------- /img/Progetto/Nuova_Rob/featuresB.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/Nuova_Rob/featuresB.m -------------------------------------------------------------------------------- /img/Progetto/Nuova_Rob/geometria.asv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/Nuova_Rob/geometria.asv -------------------------------------------------------------------------------- /img/Progetto/Nuova_Rob/geometria.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/Nuova_Rob/geometria.m -------------------------------------------------------------------------------- /img/Progetto/Nuova_Rob/readme.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/Nuova_Rob/readme.txt -------------------------------------------------------------------------------- /img/Progetto/PowerPoint/Corrispondenza1.fig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/PowerPoint/Corrispondenza1.fig -------------------------------------------------------------------------------- /img/Progetto/PowerPoint/Features.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/PowerPoint/Features.jpg -------------------------------------------------------------------------------- /img/Progetto/PowerPoint/Features_2d.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/PowerPoint/Features_2d.jpg -------------------------------------------------------------------------------- /img/Progetto/PowerPoint/Orig_Ric_STFT.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/PowerPoint/Orig_Ric_STFT.jpg -------------------------------------------------------------------------------- /img/Progetto/PowerPoint/Orig_Ric_time.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/PowerPoint/Orig_Ric_time.jpg -------------------------------------------------------------------------------- /img/Progetto/PowerPoint/Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/PowerPoint/Thumbs.db -------------------------------------------------------------------------------- /img/Progetto/PowerPoint/configurazione.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/PowerPoint/configurazione.jpg -------------------------------------------------------------------------------- /img/Progetto/PowerPoint/presentazione.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/PowerPoint/presentazione.pptx -------------------------------------------------------------------------------- /img/Progetto/PowerPoint/~$presentazione.pptx: -------------------------------------------------------------------------------- 1 | Charly Charly -------------------------------------------------------------------------------- /img/Progetto/Prove_Varie.m: -------------------------------------------------------------------------------- 1 | %PROGETTO DI TATA --> prove varie 19 Marzo 09 2 | 3 | -------------------------------------------------------------------------------- /img/Progetto/Ritardi_2.asv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/Ritardi_2.asv -------------------------------------------------------------------------------- /img/Progetto/Ritardi_2.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/Ritardi_2.m -------------------------------------------------------------------------------- /img/Progetto/Ritardig.asv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/Ritardig.asv -------------------------------------------------------------------------------- /img/Progetto/Ritardig.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/Ritardig.m -------------------------------------------------------------------------------- /img/Progetto/STFT.asv: -------------------------------------------------------------------------------- 1 | %STFT 2 | 3 | % CALCOLO DEL NUMERO DI SPLICE: 4 | % numero_splice=1+((length(signal)-length(win))/(length(win)/2)) 5 | % 6 | % 7 | 8 | 9 | function [trasf]=STFT(signal,win,maxl) 10 | 11 | M=length(win); 12 | R=M/2; %hop size del 50% 13 | part(1:M,1)=signal(1:M,1); 14 | splice(1:M,1)=part(1:M,1)'.*win'; 15 | 16 | cicli=fix((length(signal)-length(win))/(length(win)/2)); 17 | 18 | for i=2:cicli 19 | 20 | start=(i-1)*(R); %avanza del 50% 21 | fin=start+M-1; 22 | part(1:M,i)=signal(start:fin,1); 23 | splice(1:M,i)=part(1:M,i)'.*win'; 24 | 25 | end; 26 | 27 | for i=1:(round(maxl/M)); 28 | 29 | trasf(1:M,i)=fft(splice(1:M,i)); 30 | 31 | end; -------------------------------------------------------------------------------- /img/Progetto/STFT.m: -------------------------------------------------------------------------------- 1 | %STFT 2 | 3 | % CALCOLO DEL NUMERO DI SPLICE: 4 | % numero_splice=1+((length(signal)-length(win))/(length(win)/2)) 5 | % 6 | % 7 | 8 | 9 | function [trasf]=STFT(signal,win) 10 | 11 | M=length(win); 12 | R=M/2; %hop size del 50% (M/2) 13 | part(1:M,1)=signal(1:M,1); 14 | splice(1:M,1)=part(1:M,1)'.*win'; 15 | 16 | cicli=fix((length(signal)-length(win))/(length(win)/2)); %2 o 4 17 | 18 | for i=2:cicli; 19 | 20 | start=1+(i-1)*(R); 21 | fin=start+length(win)-1; 22 | part(1:M,i)=signal(start:fin,1); 23 | splice(1:M,i)=part(1:M,i)'.*win'; 24 | 25 | end; 26 | 27 | for i=1:(size(splice,2)); 28 | 29 | trasf(1:M,i)=fft(splice(1:M,i)); 30 | 31 | end; -------------------------------------------------------------------------------- /img/Progetto/STFT3personeRif.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/STFT3personeRif.jpg -------------------------------------------------------------------------------- /img/Progetto/STFTMicrofoni.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/STFTMicrofoni.jpg -------------------------------------------------------------------------------- /img/Progetto/STFT_FFT.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/STFT_FFT.m -------------------------------------------------------------------------------- /img/Progetto/STFT_Sintesys.asv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/STFT_Sintesys.asv -------------------------------------------------------------------------------- /img/Progetto/STFT_Sintesys.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/STFT_Sintesys.m -------------------------------------------------------------------------------- /img/Progetto/SpazioParametri.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/SpazioParametri.pdf -------------------------------------------------------------------------------- /img/Progetto/TataProj_Spect.asv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/TataProj_Spect.asv -------------------------------------------------------------------------------- /img/Progetto/TataProj_Spect.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/TataProj_Spect.m -------------------------------------------------------------------------------- /img/Progetto/TataProj_sin.asv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/TataProj_sin.asv -------------------------------------------------------------------------------- /img/Progetto/TataProj_sin.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/TataProj_sin.m -------------------------------------------------------------------------------- /img/Progetto/Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/Thumbs.db -------------------------------------------------------------------------------- /img/Progetto/Toms_diner.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/Toms_diner.wav -------------------------------------------------------------------------------- /img/Progetto/features.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/features.m -------------------------------------------------------------------------------- /img/Progetto/finkle.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/finkle.wav -------------------------------------------------------------------------------- /img/Progetto/geometria.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/geometria.m -------------------------------------------------------------------------------- /img/Progetto/gotowork.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/gotowork.wav -------------------------------------------------------------------------------- /img/Progetto/ifusayno.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/ifusayno.wav -------------------------------------------------------------------------------- /img/Progetto/performance.asv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/performance.asv -------------------------------------------------------------------------------- /img/Progetto/performance.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/performance.m -------------------------------------------------------------------------------- /img/Progetto/prestazioni_prove.asv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/prestazioni_prove.asv -------------------------------------------------------------------------------- /img/Progetto/prestazioni_prove.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/prestazioni_prove.m -------------------------------------------------------------------------------- /img/Progetto/progetto.asv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/progetto.asv -------------------------------------------------------------------------------- /img/Progetto/progetto.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/progetto.m -------------------------------------------------------------------------------- /img/Progetto/progetto3f.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/progetto3f.m -------------------------------------------------------------------------------- /img/Progetto/progettoFs.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/progettoFs.m -------------------------------------------------------------------------------- /img/Progetto/progetto_2.asv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/progetto_2.asv -------------------------------------------------------------------------------- /img/Progetto/progetto_2.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/progetto_2.m -------------------------------------------------------------------------------- /img/Progetto/progetto_fraz.asv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/progetto_fraz.asv -------------------------------------------------------------------------------- /img/Progetto/progetto_fraz.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/progetto_fraz.m -------------------------------------------------------------------------------- /img/Progetto/progetto_internet.asv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/progetto_internet.asv -------------------------------------------------------------------------------- /img/Progetto/progetto_internet.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/progetto_internet.m -------------------------------------------------------------------------------- /img/Progetto/progetto_internet1.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/progetto_internet1.m -------------------------------------------------------------------------------- /img/Progetto/progetto_internet2.asv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/progetto_internet2.asv -------------------------------------------------------------------------------- /img/Progetto/progetto_internet2.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/progetto_internet2.m -------------------------------------------------------------------------------- /img/Progetto/progetto_unwrap.asv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/progetto_unwrap.asv -------------------------------------------------------------------------------- /img/Progetto/progetto_unwrap.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/progetto_unwrap.m -------------------------------------------------------------------------------- /img/Progetto/rihanna.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/rihanna.mp3 -------------------------------------------------------------------------------- /img/Progetto/ritardi.m: -------------------------------------------------------------------------------- 1 | %RITARDO FRAZIONALE TRAMITE DFT 2 | 3 | %prima prova (anticipo di 0.5 campioni) 4 | FT1=fft(signal1); 5 | k1=1:size(signal1)/2; 6 | esp1=exp(-i*2*pi*k1/60*0.5); 7 | esp1=esp1'; 8 | FT1(1:size(FT1)/2,1)=FT1(1:size(FT1)/2,1).*esp1; 9 | k2=11959:size(FT1);esp2=exp(-i*2*pi*(k2/60-1)*0.5); 10 | esp2=esp2'; 11 | FT1(size(FT1)/2+1:size(FT1),1)=FT1(size(FT1)/2+1:size(FT1),1).*esp2; 12 | 13 | 14 | 15 | signal1R=ifft(FT1,'symmetric'); 16 | figure; plot(signal1R); 17 | sound(signal1R,8000); 18 | sound(signal1,8000); 19 | prova2=signal1-signal1R; 20 | figure; plot(prova2); 21 | sound(prova2,8000); 22 | sound(signal1,8000); 23 | sound(signal1R,8000); 24 | sound(prova2,8000); 25 | 26 | %seconda prova 27 | FT1=fft(signal1); 28 | k1=1:size(signal1)/2; 29 | esp1=exp(-i*2*pi*k1/60*3.5); 30 | esp1=esp1'; 31 | FT1(1:size(FT1)/2,1)=FT1(1:size(FT1)/2,1).*esp1; 32 | k2=11959:size(FT1);esp2=exp(-i*2*pi*(k2/60-1)*3.5); 33 | esp2=esp2'; 34 | FT1(size(FT1)/2+1:size(FT1),1)=FT1(size(FT1)/2+1:size(FT1),1).*esp2; 35 | signal1R=ifft(FT1,'symmetric'); 36 | sound(signal1R,8000); 37 | prova2=signal1-signal1R; 38 | sound(prova2,8000); -------------------------------------------------------------------------------- /img/Progetto/rss_mA.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/rss_mA.wav -------------------------------------------------------------------------------- /img/Progetto/rss_mB.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/rss_mB.wav -------------------------------------------------------------------------------- /img/Progetto/rssd_A.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/rssd_A.wav -------------------------------------------------------------------------------- /img/Progetto/rssd_B.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/rssd_B.wav -------------------------------------------------------------------------------- /img/Progetto/s1.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/s1.wav -------------------------------------------------------------------------------- /img/Progetto/s2.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/s2.wav -------------------------------------------------------------------------------- /img/Progetto/s3.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/s3.wav -------------------------------------------------------------------------------- /img/Progetto/segnali.asv: -------------------------------------------------------------------------------- 1 | %creazione artificiale di segnali 2 | 3 | 4 | Fs=8000; %frequenza di campionamento 1KHz 5 | Lenght=24100; %lunghezza in campioni del segnale 6 | 7 | %creazione dell'asse temporale 8 | 9 | T=1/Fs; %periodo di campionamento 10 | t=(0:Lenght-1).*T; 11 | 12 | %creazione dei segnali (vettori) 13 | 14 | seno150=sin(2*pi*150*t); 15 | seno1000=sin(2*pi*1000*t); 16 | seno150=sin(2*pi*150*t); 17 | seno150=sin(2*pi*150*t); 18 | seno150=sin(2*pi*150*t); 19 | seno150=sin(2*pi*150*t); -------------------------------------------------------------------------------- /img/Progetto/segnali.m: -------------------------------------------------------------------------------- 1 | %creazione artificiale di segnali 2 | %I segnali vanno creati come vettori colonna!!!! 3 | 4 | 5 | Fs=8000; %frequenza di campionamento 1KHz 6 | Lenght=24100; %lunghezza in campioni del segnale 7 | 8 | %creazione dell'asse temporale 9 | 10 | T=1/Fs; %periodo di campionamento 11 | t=(0:Lenght-1).*T; 12 | 13 | %creazione dei segnali (vettori) 14 | 15 | seno150=sin(2*pi*150*t); 16 | seno1000=sin(2*pi*1000*t); 17 | seno500=sin(2*pi*500*t); 18 | seno300=sin(2*pi*300*t); 19 | seno2000=sin(2*pi*2000*t); 20 | seno50=sin(2*pi*50*t); 21 | 22 | signal1=seno150'+seno1000'; 23 | signal2=seno500'+seno50'; 24 | signal3=seno300'+seno2000'; -------------------------------------------------------------------------------- /img/Progetto/serioustherapy.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/serioustherapy.wav -------------------------------------------------------------------------------- /img/Progetto/sfasamenti.m: -------------------------------------------------------------------------------- 1 | function Y=uladata(theta,P,N,sig2,m,d) 2 | % 3 | % Generates N snapshots of ULA sensor data 4 | % 5 | % Y=uladata(theta,P,N,sig2,m,d); 6 | % 7 | % theta <- arrival angles of the m sources in degrees 8 | % P <- The covariance matrix of the source signals 9 | % N <- number of snapshots to generate 10 | % sig2 <- noise variance 11 | % m <- number of sensors 12 | % d <- sensor spacing in wavelengths 13 | % Y -> m x N data matrix Y = [y(1),...,y(N)] 14 | 15 | % Copyright 1996 by R. Moses 16 | 17 | % generate the A matrix 18 | A=exp(-2*pi*j*d*[0:m-1].'*sin([theta(:).']*pi/180)); 19 | 20 | % generate the source signals 21 | n=max(size(P)); 22 | s=(sqrtm(P)')*randn(n,N); % s(t) 23 | 24 | % generate the noise component 25 | e=sqrt(sig2/2)*(randn(m,N)+j*randn(m,N)); 26 | 27 | % generate the ULA data 28 | Y=A*s+e; 29 | -------------------------------------------------------------------------------- /img/Progetto/trippy.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/trippy.wav -------------------------------------------------------------------------------- /img/Progetto/voce_maschile.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/voce_maschile.wav -------------------------------------------------------------------------------- /img/Progetto/voiced_a.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/voiced_a.wav -------------------------------------------------------------------------------- /img/Progetto/wavexread.m: -------------------------------------------------------------------------------- 1 | function [y,Fs,nbits,speakers] = wavexread(file,ext) 2 | %WAVEXREAD Read Microsoft WAVE-FORMAT-EXTENSIBLE (".wav") sound file. 3 | % Y=WAVEXREAD(FILE) reads a WAVE file specified by the string FILE, 4 | % returning the sampled data in Y. The ".wav" extension is appended 5 | % if no extension is given. Amplitude values are in the range [-1,+1]. 6 | % 7 | % [Y,FS,NBITS]=WAVEXREAD(FILE) returns the sample rate (FS) in Hertz 8 | % and the number of bits per sample (NBITS) used to encode the 9 | % data in the file. 10 | % 11 | % [...]=WAVEXREAD(FILE,N) returns only the first N samples from each 12 | % channel in the file. 13 | % [...]=WAVEXREAD(FILE,[N1 N2]) returns only samples N1 through N2 from 14 | % each channel in the file. 15 | % SIZ=WAVEXREAD(FILE,'size') returns the size of the audio data contained 16 | % in the file in place of the actual audio data, returning the 17 | % vector SIZ=[samples channels]. 18 | % 19 | % [Y,FS,NBITS,OPTS]=WAVEXREAD(...) returns a structure OPTS of additional 20 | % information contained in the WAV file. The content of this 21 | % structure differs from file to file. Typical structure fields 22 | % include '.fmt' (audio format information) and '.info' (text 23 | % which may describe subject title, copy right, etc.) 24 | % 25 | % Supports multi-channel data, with up to 32 bits per sample. 26 | % 27 | % NOTE: This file reader only supports Microsoft PCM data format. 28 | % It does not support wave-list data. 29 | % 30 | % See also WAVEXWRITE, WAVWRITE, AUREAD, AUWRITE. 31 | 32 | % Author: D. Orofino 33 | % Copyright 1984-2002 The MathWorks, Inc. 34 | % $Revision: 5.28 $ $Date: 2002/05/30 20:42:03 $ 35 | % 36 | % Modified 2004/07/27 by Sylvain Choisel 37 | % to handle WAVE-FORMAT-EXTENSIBLE 38 | 39 | % Parse input arguments: 40 | nargchk(1,2,nargin); 41 | if nargin<2, ext=[]; end % Default - read all samples 42 | exts = prod(size(ext)); % length of extent info 43 | if ~strncmpi(ext,'size',exts) & (exts > 2), 44 | error('Index range must be specified as a scalar or 2-element vector.'); 45 | end 46 | if ~ischar(ext) & exts==1, 47 | if ext==0, 48 | ext='size'; % synonym for size 49 | else 50 | ext=[1 ext]; % Prepend start sample index 51 | end 52 | end 53 | 54 | % Open WAV file: 55 | [fid,msg] = open_wav(file); 56 | error(msg); 57 | 58 | % Now the file is open - wrap remaining code in try/catch so we can 59 | % close the file if an error occurs 60 | try 61 | 62 | % Find the first RIFF chunk: 63 | [riffck,msg] = find_cktype(fid,'RIFF'); 64 | %error(msg); 65 | if ~isempty(msg), 66 | error('Not a WAVE file.'); 67 | end 68 | 69 | % Verify that RIFF file is WAVE data type: 70 | msg = check_rifftype(fid,'WAVE'); 71 | error(msg); 72 | 73 | % Find optional chunks, and don't stop till found: 74 | found_data = 0; 75 | end_of_file = 0; 76 | opt_ck = []; 77 | 78 | while(~end_of_file), 79 | [ck,msg] = find_cktype(fid); 80 | error(msg); 81 | 82 | switch lower(ck.ID) 83 | 84 | case 'end of file' 85 | end_of_file = 1; 86 | 87 | case 'fmt' 88 | % found 89 | [opt_ck,msg] = read_wavefmt(fid,ck,opt_ck); 90 | error(msg); 91 | 92 | case 'data' 93 | % found: 94 | found_data = 1; 95 | if ~isfield(opt_ck,'fmt'), 96 | error('Corrupt WAV file: found audio data before format information.'); 97 | end 98 | 99 | if strncmpi(ext,'size',exts) | ... 100 | (~isempty(ext) & all(ext==0)), 101 | % Caller doesn't want data - just data size: 102 | [samples,msg] = read_wavedat(ck, opt_ck.fmt, -1); 103 | error(msg); 104 | y = [samples opt_ck.fmt.nChannels]; 105 | 106 | else 107 | % Read : 108 | [datack,msg] = read_wavedat(ck, opt_ck.fmt, ext); 109 | error(msg); 110 | y = datack.Data; 111 | 112 | end 113 | 114 | case 'fact' 115 | % Optional found: 116 | [opt_ck,msg] = read_factck(fid, ck, opt_ck); 117 | error(msg); 118 | 119 | case 'disp' 120 | % Optional found: 121 | [opt_ck,msg] = read_dispck(fid, ck, opt_ck); 122 | error(msg); 123 | 124 | case 'list' 125 | % Optional found: 126 | [opt_ck, msg] = read_listck(fid, ck, opt_ck); 127 | error(msg); 128 | 129 | otherwise 130 | % Skip over data in unprocessed chunks: 131 | if rem(ck.Size,2), ck.Size=ck.Size+1; end 132 | if(fseek(fid,ck.Size,0)==-1), 133 | error('Incorrect chunk size information in WAV file.'); 134 | end 135 | end 136 | end 137 | 138 | catch 139 | fclose(fid); 140 | error(lasterr); 141 | end 142 | 143 | fclose(fid); 144 | 145 | % Parse structure info for return to user: 146 | Fs = opt_ck.fmt.nSamplesPerSec; 147 | if opt_ck.fmt.wFormatTag == 1 | opt_ck.fmt.wFormatTag == 3, 148 | % Type 3 floating point has no nBitsPerSample field, so use 149 | % nBlockAlign to figure out number of bits 150 | nbits = (opt_ck.fmt.nBlockAlign / opt_ck.fmt.nChannels) * 8; 151 | else 152 | nbits = []; % Unknown 153 | end 154 | 155 | speakers=find((fliplr(dec2bin(opt_ck.fmt.dwChanelMask)-48))~=0); 156 | 157 | % end of wavread() 158 | 159 | 160 | % ------------------------------------------------------------------------ 161 | % Local functions: 162 | % ------------------------------------------------------------------------ 163 | 164 | % --------------------------------------------- 165 | % OPEN_WAV: Open a WAV file for reading 166 | % --------------------------------------------- 167 | function [fid,msg] = open_wav(file) 168 | % Append .wav extension if it's missing: 169 | [pat,nam,ext] = fileparts(file); 170 | if isempty(ext), 171 | file = [file '.wav']; 172 | end 173 | [fid,msg] = fopen(file,'rb','l'); % Little-endian 174 | if fid == -1, 175 | msg = 'Cannot open file.'; 176 | end 177 | return 178 | 179 | % --------------------------------------------- 180 | % READ_CKINFO: Reads next RIFF chunk, but not the chunk data. 181 | % If optional sflg is set to nonzero, reads SUBchunk info instead. 182 | % Expects an open FID pointing to first byte of chunk header. 183 | % Returns a new chunk structure. 184 | % --------------------------------------------- 185 | function [ck,msg] = read_ckinfo(fid) 186 | 187 | msg = ''; 188 | ck.fid = fid; 189 | ck.Data = []; 190 | err_msg = 'Truncated chunk header found - possibly not a WAV file.'; 191 | 192 | [s,cnt] = fread(fid,4,'char'); 193 | 194 | % Do not error-out if a few (<4) trailing chars are in file 195 | % Just return quickly: 196 | if (cnt~=4), 197 | if feof(fid), 198 | % End of the file (not an error) 199 | ck.ID = 'end of file'; % unambiguous chunk ID (>4 chars) 200 | ck.Size = 0; 201 | else 202 | msg = err_msg; 203 | end 204 | return 205 | end 206 | 207 | ck.ID = deblank(setstr(s')); 208 | 209 | % Read chunk size (skip if subchunk): 210 | [sz,cnt] = fread(fid,1,'ulong'); 211 | if cnt~=1, 212 | msg = err_msg; 213 | return 214 | end 215 | ck.Size = sz; 216 | return 217 | 218 | % --------------------------------------------- 219 | % FIND_CKTYPE: Finds a chunk with appropriate type. 220 | % Searches from current file position specified by fid. 221 | % Leaves file positions to data of desired chunk. 222 | % If optional sflg is set to nonzero, finds a SUBchunk instead. 223 | % --------------------------------------------- 224 | function [ck,msg] = find_cktype(fid,ftype) 225 | 226 | msg = ''; 227 | if nargin<2, ftype = ''; end 228 | 229 | [ck,msg] = read_ckinfo(fid); 230 | if ~isempty(msg), return; end 231 | 232 | % Was a required chunk type specified? 233 | if ~isempty(ftype) & ~strcmpi(ck.ID,ftype), 234 | msg = ['<' ftype '-ck> did not appear as expected']; 235 | end 236 | return 237 | 238 | 239 | % --------------------------------------------- 240 | % CHECK_RIFFTYPE: Finds the RIFF data type. 241 | % Searches from current file position specified by fid. 242 | % Leaves file positions to data of desired chunk. 243 | % --------------------------------------------- 244 | function msg = check_rifftype(fid,ftype) 245 | msg = ''; 246 | [rifftype,cnt] = fread(fid,4,'char'); 247 | rifftype = setstr(rifftype)'; 248 | 249 | if cnt~=4, 250 | msg = 'Not a WAVE file.'; 251 | elseif ~strcmpi(rifftype,ftype), 252 | msg = ['File does not contain required ''' ftype ''' data chunk.']; 253 | end 254 | 255 | return 256 | 257 | 258 | % --------------------------------------------- 259 | % READ_LISTCK: Read the FLIST chunk: 260 | % --------------------------------------------- 261 | function [opt_ck,msg] = read_listck(fid,ck, orig_opt_ck) 262 | 263 | opt_ck = orig_opt_ck; 264 | 265 | orig_pos = ftell(fid); 266 | total_bytes = ck.Size; % # bytes in subchunk 267 | nbytes = 4; % # of required bytes in header 268 | msg = ''; 269 | err_msg = 'Error reading chunk.'; 270 | 271 | if total_bytes < nbytes, 272 | msg = err_msg; 273 | return 274 | end 275 | 276 | % Read standard data: 277 | listdata = setstr(fread(fid,total_bytes,'uchar')'); 278 | 279 | listtype = lower(listdata(1:4)); % Get LIST type 280 | listdata = listdata(5:end); % Move past INFO 281 | 282 | if strcmp(listtype,'info'), 283 | % Information: 284 | while(~isempty(listdata)), 285 | id = listdata(1:4); 286 | switch lower(id) 287 | case 'iart' 288 | name = 'Artist'; 289 | case 'icmt' 290 | name = 'Comments'; 291 | case 'icrd' 292 | name = 'Creation date'; 293 | case 'icop' 294 | name = ['Copy' 'right']; 295 | case 'ieng' 296 | name = 'Engineer'; 297 | case 'inam' 298 | name = 'Name'; 299 | case 'iprd' 300 | name = 'Product'; 301 | case 'isbj' 302 | name = 'Subject'; 303 | case 'isft' 304 | name = 'Software'; 305 | case 'isrc' 306 | name = 'Source'; 307 | otherwise 308 | name = id; 309 | end 310 | 311 | if ~isfield(opt_ck,'info'), 312 | opt_ck.info = []; 313 | end 314 | len = listdata(5:8) * 2.^[0 8 16 24]'; 315 | txt = listdata(9:9+len-1); 316 | 317 | % Fix up text: deblank, and replace CR/LR with LF 318 | txt = deblank(txt); 319 | idx=findstr(txt,setstr([13 10])); 320 | txt(idx) = ''; 321 | 322 | % Store - don't include the "name" info 323 | opt_ck.info.(lower(id)) = txt; 324 | 325 | if rem(len,2), len=len+1; end 326 | listdata = listdata(9+len:end); 327 | end 328 | 329 | else 330 | if ~isfield(opt_ck,'list'), 331 | opt_ck.list = []; 332 | end 333 | opt_ck.list.(listtype) = listdata; 334 | end 335 | 336 | % Skip over any unprocessed data: 337 | if rem(total_bytes,2), total_bytes=total_bytes+1; end 338 | rbytes = total_bytes - (ftell(fid) - orig_pos); 339 | if rbytes~=0, 340 | if (fseek(fid,rbytes,'cof')==-1), 341 | msg = err_msg; 342 | end 343 | end 344 | return 345 | 346 | 347 | % --------------------------------------------- 348 | % READ_DISPCK: Read the DISP chunk: 349 | % --------------------------------------------- 350 | function [opt_ck, msg] = read_dispck(fid,ck,orig_opt_ck) 351 | 352 | opt_ck = orig_opt_ck; 353 | 354 | orig_pos = ftell(fid); 355 | total_bytes = ck.Size; % # bytes in subchunk 356 | nbytes = 4; % # of required bytes in header 357 | msg = ''; 358 | err_msg = 'Error reading chunk.'; 359 | 360 | if total_bytes < nbytes, 361 | msg = err_msg; 362 | return 363 | end 364 | 365 | % Read standard data: 366 | data = fread(fid,total_bytes,'uchar'); 367 | 368 | % Process data: 369 | 370 | % First few entries are size info: 371 | icon_data = data; 372 | siz_info = reshape(icon_data(1:2*4),4,2)'; 373 | siz_info = siz_info*(2.^[0 8 16 24]'); 374 | is_icon = isequal(siz_info,[8;40]); 375 | 376 | if ~is_icon, 377 | % Not the icon: 378 | opt_ck.disp.name = 'DisplayName'; 379 | txt = deblank(setstr(data(5:end)')); 380 | opt_ck.disp.text = txt; 381 | end 382 | 383 | % Skip over any unprocessed data: 384 | if rem(total_bytes,2), total_bytes=total_bytes+1; end 385 | rbytes = total_bytes - (ftell(fid) - orig_pos); 386 | if rbytes~=0, 387 | if(fseek(fid,rbytes,'cof')==-1), 388 | msg = err_msg; 389 | end 390 | end 391 | return 392 | 393 | 394 | % --------------------------------------------- 395 | % READ_FACTCK: Read the FACT chunk: 396 | % --------------------------------------------- 397 | function [opt_ck,msg] = read_factck(fid,ck,orig_opt_ck) 398 | 399 | opt_ck = orig_opt_ck; 400 | orig_pos = ftell(fid); 401 | total_bytes = ck.Size; % # bytes in subchunk 402 | nbytes = 4; % # of required bytes in header 403 | msg = ''; 404 | err_msg = 'Error reading chunk.'; 405 | 406 | if total_bytes < nbytes, 407 | msg = err_msg; 408 | return 409 | end 410 | 411 | % Read standard data: 412 | opt_ck.fact = setstr(fread(fid,total_bytes,'uchar')'); 413 | 414 | % Skip over any unprocessed data: 415 | if rem(total_bytes,2), total_bytes=total_bytes+1; end 416 | rbytes = total_bytes - (ftell(fid) - orig_pos); 417 | if rbytes~=0, 418 | if(fseek(fid,rbytes,'cof')==-1), 419 | msg = err_msg; 420 | end 421 | end 422 | return 423 | 424 | 425 | % --------------------------------------------- 426 | % READ_WAVEFMT: Read WAVE format chunk. 427 | % Assumes fid points to the subchunk. 428 | % Requires chunk structure to be passed, indicating 429 | % the length of the chunk in case we don't recognize 430 | % the format tag. 431 | % --------------------------------------------- 432 | function [opt_ck,msg] = read_wavefmt(fid,ck,orig_opt_ck) 433 | 434 | opt_ck = orig_opt_ck; 435 | 436 | orig_pos = ftell(fid); 437 | total_bytes = ck.Size; % # bytes in subchunk 438 | nbytes = 40; % # of required bytes in header 439 | msg = ''; 440 | err_msg = 'Error reading chunk.'; 441 | 442 | if total_bytes < nbytes, 443 | msg = err_msg; 444 | return 445 | end 446 | 447 | % Read standard data: 448 | opt_ck.fmt.wFormatTag = fread(fid,1,'ushort'); % Data encoding format 449 | opt_ck.fmt.nChannels = fread(fid,1,'ushort'); % Number of channels 450 | opt_ck.fmt.nSamplesPerSec = fread(fid,1,'ulong'); % Samples per second 451 | opt_ck.fmt.nAvgBytesPerSec = fread(fid,1,'ulong'); % Avg transfer rate 452 | opt_ck.fmt.nBlockAlign = fread(fid,1,'ushort'); % Block alignment 453 | %sc 454 | opt_ck.fmt.wBitsPerSample = fread(fid,1,'ushort'); 455 | opt_ck.fmt.cbSize = fread(fid,1,'ushort'); 456 | opt_ck.fmt.wValidBitsPerSample = fread(fid,1,'ushort'); 457 | opt_ck.fmt.dwChanelMask = fread(fid,1,'ulong'); 458 | opt_ck.fmt.subFormat = fread(fid,16,'uchar'); 459 | 460 | % Read format-specific info: 461 | switch opt_ck.fmt.wFormatTag 462 | case 1 463 | % PCM Format: 464 | %[opt_ck.fmt, msg] = read_fmt_pcm(fid, ck, opt_ck.fmt); 465 | exit('Invalid extensible format'); 466 | case hex2dec('FFFE') 467 | % [opt_ck.fmt, msg] = read_fmt_pcm(fid, ck, opt_ck.fmt); 468 | end 469 | 470 | 471 | % Skip over any unprocessed fmt-specific data: 472 | %if rem(total_bytes,2), total_bytes=total_bytes+1; end 473 | %rbytes = total_bytes - (ftell(fid) - orig_pos); 474 | %if rbytes~=0, 475 | % if(fseek(fid,rbytes,'cof')==-1), 476 | % msg = err_msg; 477 | % end 478 | %end 479 | 480 | return 481 | 482 | 483 | % --------------------------------------------- 484 | % READ_FMT_PCM: Read info 485 | % --------------------------------------------- 486 | function [fmt,msg] = read_fmt_pcm(fid, ck, fmt) 487 | 488 | % There had better be a bits/sample field: 489 | total_bytes = ck.Size; % # bytes in subchunk 490 | nbytes = 14; % # of bytes already read in header 491 | msg = ''; 492 | err_msg = 'Error reading PCM chunk.'; 493 | 494 | %if (total_bytes < nbytes+2), 495 | % msg = err_msg; 496 | % return 497 | %end 498 | 499 | %[bits,cnt] = fread(fid,1,'ushort'); 500 | %nbytes=nbytes+2; 501 | %if (cnt~=1), 502 | % msg = err_msg; 503 | % return 504 | %end 505 | %fmt.nBitsPerSample=bits; 506 | 507 | % Are there any additional fields present? 508 | if (total_bytes > nbytes), 509 | % See if the "cbSize" field is present. If so, grab the data: 510 | if (total_bytes >= nbytes+2), 511 | % we have the cbSize ushort in the file: 512 | [cbSize,cnt]=fread(fid,1,'ushort'); 513 | nbytes=nbytes+2; 514 | if (cnt~=1), 515 | msg = err_msg; 516 | return 517 | end 518 | fmt.cbSize = cbSize; 519 | end 520 | 521 | % Simply skip any remaining stuff - we don't know what it is: 522 | if rem(total_bytes,2), total_bytes=total_bytes+1; end 523 | rbytes = total_bytes - nbytes; 524 | if rbytes~=0, 525 | if (fseek(fid,rbytes,'cof') == -1); 526 | msg = err_msg; 527 | end 528 | end 529 | end 530 | return 531 | 532 | 533 | % --------------------------------------------- 534 | % READ_WAVEDAT: Read WAVE data chunk 535 | % Assumes fid points to the wave-data chunk 536 | % Requires and structures to be passed. 537 | % Requires extraction range to be specified. 538 | % Setting ext=[] forces ALL samples to be read. Otherwise, 539 | % ext should be a 2-element vector specifying the first 540 | % and last samples (per channel) to be extracted. 541 | % Setting ext=-1 returns the number of samples per channel, 542 | % skipping over the sample data. 543 | % --------------------------------------------- 544 | function [dat,msg] = read_wavedat(datack,wavefmt,ext) 545 | 546 | % In case of unsupported data compression format: 547 | dat = []; 548 | fmt_msg = ''; 549 | 550 | switch wavefmt.wFormatTag 551 | case 1 552 | % PCM Format: 553 | [dat,msg] = read_dat_pcm(datack,wavefmt,ext); 554 | case 2 555 | fmt_msg = 'Microsoft ADPCM'; 556 | case 3 557 | % normalized floating-point 558 | [dat,msg] = read_dat_pcm(datack,wavefmt,ext); 559 | case 6 560 | fmt_msg = 'CCITT a-law'; 561 | case 7 562 | fmt_msg = 'CCITT mu-law'; 563 | case 17 564 | fmt_msg = 'IMA ADPCM'; 565 | case 34 566 | fmt_msg = 'DSP Group TrueSpeech TM'; 567 | case 49 568 | fmt_msg = 'GSM 6.10'; 569 | case 50 570 | fmt_msg = 'MSN Audio'; 571 | case 257 572 | fmt_msg = 'IBM Mu-law'; 573 | case 258 574 | fmt_msg = 'IBM A-law'; 575 | case 259 576 | fmt_msg = 'IBM AVC Adaptive Differential'; 577 | case hex2dec('FFFE') %sc 578 | % WAVE-FORMAT-EXTENSIBLE 579 | [dat,msg] = read_dat_pcm(datack,wavefmt,ext); 580 | otherwise 581 | fmt_msg = ['Format #' num2str(wavefmt.wFormatTag)]; 582 | end 583 | if ~isempty(fmt_msg), 584 | msg = ['Data compression format (' fmt_msg ') is not supported.']; 585 | end 586 | return 587 | 588 | 589 | % --------------------------------------------- 590 | % READ_DAT_PCM: Read PCM format data from chunk. 591 | % Assumes fid points to the wave-data chunk 592 | % Requires and structures to be passed. 593 | % Requires extraction range to be specified. 594 | % Setting ext=[] forces ALL samples to be read. Otherwise, 595 | % ext should be a 2-element vector specifying the first 596 | % and last samples (per channel) to be extracted. 597 | % Setting ext=-1 returns the number of samples per channel, 598 | % skipping over the sample data. 599 | % --------------------------------------------- 600 | function [dat,msg] = read_dat_pcm(datack,wavefmt,ext) 601 | 602 | dat = []; 603 | msg = ''; 604 | 605 | % Determine # bytes/sample - format requires rounding 606 | % to next integer number of bytes: 607 | BytesPerSample = ceil(wavefmt.nBlockAlign / wavefmt.nChannels); 608 | if (BytesPerSample == 1), 609 | dtype='uchar'; % unsigned 8-bit 610 | elseif (BytesPerSample == 2), 611 | dtype='short'; % signed 16-bit 612 | elseif (BytesPerSample == 3) 613 | dtype='bit24'; % signed 24-bit 614 | elseif (BytesPerSample == 4), 615 | % 32-bit 16.8 float (type 1 - 32-bit) 616 | % 32-bit normalized floating point 617 | dtype = 'float'; 618 | % 32-bit 24.0 float (type 1 - 24-bit) 619 | if wavefmt.wFormatTag ~= 3 & wavefmt.nBitsPerSample == 24, 620 | BytesPerSample = 3; 621 | end 622 | else 623 | msg = 'Cannot read PCM file formats with more than 32 bits per sample.'; 624 | return 625 | end 626 | 627 | total_bytes = datack.Size; % # bytes in this chunk 628 | total_samples = total_bytes / BytesPerSample; 629 | SamplesPerChannel = total_samples / wavefmt.nChannels; 630 | if ~isempty(ext) & ext==-1, 631 | % Just return the samples per channel, and fseek past data: 632 | dat = SamplesPerChannel; 633 | 634 | % Add in a pad-byte, if required: 635 | total_bytes = total_bytes + rem(datack.Size,2); 636 | 637 | if(fseek(datack.fid,total_bytes,'cof')==-1), 638 | msg = 'Error reading PCM file format.'; 639 | end 640 | 641 | return 642 | end 643 | 644 | % Determine sample range to read: 645 | if isempty(ext), 646 | ext = [1 SamplesPerChannel]; % Return all samples 647 | else 648 | if prod(size(ext))~=2, 649 | msg = 'Sample limit vector must have 2 elements.'; 650 | return 651 | end 652 | if ext(1)<1 | ext(2)>SamplesPerChannel, 653 | msg = 'Sample limits out of range.'; 654 | return 655 | end 656 | if ext(1)>ext(2), 657 | msg = 'Sample limits must be given in ascending order.'; 658 | return 659 | end 660 | end 661 | 662 | bytes_remaining = total_bytes; % Preset byte counter 663 | 664 | % Skip over leading samples: 665 | if ext(1)>1, 666 | % Skip over leading samples, if specified: 667 | skipcnt = BytesPerSample * (ext(1)-1) * wavefmt.nChannels; 668 | if(fseek(datack.fid, skipcnt,'cof') == -1), 669 | msg = 'Error reading PCM file format.'; 670 | return 671 | end 672 | % 673 | % Update count of bytes remaining: 674 | bytes_remaining = bytes_remaining - skipcnt; 675 | end 676 | 677 | % Read desired data: 678 | nSPCext = ext(2)-ext(1)+1; % # samples per channel in extraction range 679 | dat = datack; % Copy input structure to output 680 | extSamples = wavefmt.nChannels*nSPCext; 681 | dat.Data = fread(datack.fid, [wavefmt.nChannels nSPCext], dtype); 682 | % 683 | % Update count of bytes remaining: 684 | skipcnt = BytesPerSample*nSPCext*wavefmt.nChannels; 685 | bytes_remaining = bytes_remaining - skipcnt; 686 | 687 | % if cnt~=extSamples, dat='Error reading file.'; return; end 688 | % Skip over trailing samples: 689 | if(fseek(datack.fid, BytesPerSample * ... 690 | (SamplesPerChannel-ext(2))*wavefmt.nChannels, 'cof')==-1), 691 | msg = 'Error reading PCM file format.'; 692 | return 693 | end 694 | % Update count of bytes remaining: 695 | skipcnt = BytesPerSample*(SamplesPerChannel-ext(2))*wavefmt.nChannels; 696 | bytes_remaining = bytes_remaining - skipcnt; 697 | 698 | % Determine if a pad-byte is appended to data chunk, 699 | % skipping over it if present: 700 | if rem(datack.Size,2), 701 | fseek(datack.fid, 1, 'cof'); 702 | end 703 | % Rearrange data into a matrix with one channel per column: 704 | dat.Data = dat.Data'; 705 | % Normalize data range: min will hit -1, max will not quite hit +1. 706 | if BytesPerSample==1, 707 | dat.Data = (dat.Data-128)/128; % [-1,1) 708 | elseif BytesPerSample==2, 709 | dat.Data = dat.Data/32768; % [-1,1) 710 | elseif BytesPerSample==3, 711 | dat.Data = dat.Data/(2^23); % [-1,1) 712 | elseif BytesPerSample==4, 713 | if wavefmt.wFormatTag ~= 3, % Type 3 32-bit is already normalized 714 | dat.Data = dat.Data/32768; % [-1,1) 715 | end 716 | end 717 | 718 | return 719 | 720 | % end of wavread.m -------------------------------------------------------------------------------- /img/Progetto/wavexwrite.m: -------------------------------------------------------------------------------- 1 | function wavexwrite(y,Fs,nbits,wavefile,speakers) 2 | %WAVEXWRITE Write WAVE_FORMAT_EXTENSIBLE sound file. 3 | % WAVEXWRITE(Y,FS,NBITS,WAVEFILE, SPEAKERS) writes data Y to a WAVEX 4 | % file specified by the file name WAVEFILE, with a sample rate 5 | % of FS Hz and with NBITS number of bits. NBITS must be 8, 16, 6 | % 24, or 32. Stereo data should be specified as a matrix with two 7 | % columns. For NBITS < 32, amplitude values outside the range 8 | % [-1,+1] are clipped. 9 | % 10 | % SPEAKERS is a vector of speaker numbers 11 | % e.g. [1,2] for stereo 12 | % [1:5] for 5.1 13 | % [3] for center channel 14 | % 15 | % WAVEXWRITE(Y,FS,WAVEFILE) assumes NBITS=16 bits. 16 | % WAVEXWRITE(Y,WAVEFILE) assumes NBITS=16 bits and FS=44100 Hz. 17 | % 18 | % 8-, 16-, and 24-bit files are type 1 integer PCM. 32-bit files 19 | % are written as type 3 normalized floating point. 20 | % 21 | % Modified 2004/07/27 by Sylvain Choisel 22 | % to handle WAVE-FORMAT-EXTENSIBLE 23 | % email: sc@acoustics.aau.dk 24 | 25 | % Parse inputs: 26 | error(nargchk(2,5,nargin)); 27 | if nargin < 3, 28 | wavefile = Fs; 29 | Fs = 44100; 30 | nbits = 16; 31 | elseif nargin < 4, 32 | wavefile = nbits; 33 | nbits = 16; 34 | end 35 | 36 | % If input is a vector, force it to be a column: 37 | if ndims(y) > 2, 38 | error('Data array cannot be an N-D array.'); 39 | end 40 | if size(y,1)==1, 41 | y = y(:); 42 | end 43 | [samples, channels] = size(y); 44 | if nargin < 5, 45 | speakerMask=2^channels-1; 46 | else 47 | if (length(speakers)~=channels) 48 | error ('Speaker mask length must be equal to the number of channels'); 49 | end 50 | speakerMask=sum(2.^(speakers-1)); 51 | end 52 | 53 | % Determine number of bytes in chunks 54 | % (not including pad bytes, if needed): 55 | % ---------------------------------- 56 | % 'RIFF' 4 bytes 57 | % size 4 bytes (ulong) 58 | % 'WAVE' 4 bytes 59 | % 'fmt ' 4 bytes 60 | % size 4 bytes (ulong) 61 | % 14 bytes 62 | % 2 bytes (PCM) 63 | % 'data' 4 bytes 64 | % size 4 bytes (ulong) 65 | % N bytes 66 | % ---------------------------------- 67 | bytes_per_sample = ceil(nbits/8); 68 | total_samples = samples * channels; 69 | total_bytes = total_samples * bytes_per_sample; 70 | 71 | riff_cksize = 4+48+total_bytes; % Don't include 'RIFF' or its size field 72 | fmt_cksize = 40; % Don't include 'fmt ' or its size field 73 | data_cksize = total_bytes; % Don't include 'data' or its size field 74 | 75 | % Determine pad bytes: 76 | data_pad = rem(data_cksize,2); 77 | riff_cksize = riff_cksize + data_pad; % + fmt_pad, always 0 78 | 79 | % Open file for output: 80 | [fid,err] = OpenWaveWrite(wavefile); 81 | error(err); 82 | 83 | % Prepare basic chunk structure fields: 84 | ck=[]; ck.fid=fid; ck.filename = wavefile; 85 | 86 | % Write RIFF chunk: 87 | ck.ID = 'RIFF'; 88 | ck.Size = riff_cksize; 89 | error(write_ckinfo(ck)); 90 | 91 | % Write WAVE subchunk: 92 | ck.ID = 'WAVE'; 93 | ck.Size = []; % Indicate a subchunk (no chunk size) 94 | error(write_ckinfo(ck)); 95 | 96 | % Write : 97 | ck.ID = 'fmt '; 98 | ck.Size = fmt_cksize; 99 | error(write_ckinfo(ck)); 100 | 101 | % Write : 102 | fmt.filename = wavefile; 103 | fmt.wFormatTag = hex2dec('FFFE'); 104 | fmt.nChannels = channels; % Number of channels 105 | fmt.nSamplesPerSec = Fs; % Samples per second 106 | fmt.nAvgBytesPerSec = channels*bytes_per_sample*Fs; % Avg transfer rate 107 | fmt.nBlockAlign = channels*bytes_per_sample; % Block alignment 108 | fmt.nBitsPerSample = 8*bytes_per_sample; 109 | fmt.cbSize = 22; 110 | fmt.wValidBitsPerSample = nbits; 111 | fmt.dwSpkMask = speakerMask; 112 | fmt.subFormat = [1 0 0 0 0 0 16 0 8*16 0 0 hex2dec('AA') 0 hex2dec('38') hex2dec('9B') hex2dec('71')]; 113 | error(write_wavefmt(fid,fmt)); 114 | 115 | % Write : 116 | ck.ID = 'data'; 117 | ck.Size = data_cksize; 118 | error(write_ckinfo(ck)); 119 | 120 | % Write , and its pad byte if needed: 121 | error(write_wavedat(fid,fmt,y)); 122 | 123 | % Close file: 124 | fclose(fid); 125 | 126 | % end of wavwrite() 127 | 128 | 129 | % ------------------------------------------------------------------------ 130 | % Private functions: 131 | % ------------------------------------------------------------------------ 132 | 133 | 134 | % ------------------------------------------------------------------------ 135 | function [fid,err] = OpenWaveWrite(wavefile) 136 | % OpenWaveWrite 137 | % Open WAV file for writing. 138 | % If filename does not contain an extension, add ".wav" 139 | 140 | fid = []; 141 | err = ''; 142 | if ~isstr(wavefile), 143 | err='Wave file name must be a string.'; return; 144 | end 145 | 146 | % modified 27/07/2004 sc 147 | %if isempty(findstr(wavefile,'.')), 148 | % wavefile=[wavefile '.wav']; 149 | %end 150 | [pathstr,name,ext,versn]=fileparts(wavefile); 151 | if (~strcmp(lower(ext),'.wav')) 152 | wavefile=[wavefile '.wav']; 153 | end 154 | 155 | % Open file, little-endian: 156 | [fid,err] = fopen(wavefile,'wb','l'); 157 | 158 | return 159 | 160 | 161 | % ------------------------------------------------------------------------ 162 | function err = write_ckinfo(ck) 163 | % WRITE_CKINFO: Writes next RIFF chunk, but not the chunk data. 164 | % Assumes the following fields in ck: 165 | % .fid File ID to an open file 166 | % .ID 4-character string chunk identifier 167 | % .Size Size of chunk (empty if subchunk) 168 | % 169 | % 170 | % Expects an open FID pointing to first byte of chunk header, 171 | % and a chunk structure. 172 | % ck.fid, ck.ID, ck.Size, ck.Data 173 | 174 | errmsg = ['Failed to write ' ck.ID ' chunk to WAVE file: ' ck.filename]; 175 | err = ''; 176 | 177 | if (fwrite(ck.fid, ck.ID, 'char') ~= 4), 178 | err=errmsg; return; 179 | end 180 | 181 | if ~isempty(ck.Size), 182 | % Write chunk size: 183 | if (fwrite(ck.fid, ck.Size, 'ulong') ~= 1), 184 | err=errmsg; return; 185 | end 186 | end 187 | 188 | return 189 | 190 | % ------------------------------------------------------------------------ 191 | function err = write_wavefmt(fid, fmt) 192 | % WRITE_WAVEFMT: Write WAVE format chunk. 193 | % Assumes fid points to the wave-format subchunk. 194 | % Requires chunk structure to be passed, indicating 195 | % the length of the chunk. 196 | 197 | errmsg = ['Failed to write WAVE format chunk to file' fmt.filename]; 198 | err = ''; 199 | 200 | % Create data: 201 | if (fwrite(fid, fmt.wFormatTag, 'ushort') ~= 1) | ... 202 | (fwrite(fid, fmt.nChannels, 'ushort') ~= 1) | ... 203 | (fwrite(fid, fmt.nSamplesPerSec, 'ulong' ) ~= 1) | ... 204 | (fwrite(fid, fmt.nAvgBytesPerSec, 'ulong' ) ~= 1) | ... 205 | (fwrite(fid, fmt.nBlockAlign, 'ushort') ~= 1) | ... 206 | (fwrite(fid, fmt.nBitsPerSample, 'ushort') ~= 1) | ... 207 | (fwrite(fid, fmt.cbSize, 'ushort') ~= 1) | ... 208 | (fwrite(fid, fmt.wValidBitsPerSample, 'ushort') ~= 1) | ... 209 | (fwrite(fid, fmt.dwSpkMask, 'ulong' ) ~= 1) | ... 210 | (fwrite(fid, fmt.subFormat, 'uchar' ) ~= 16) 211 | err=errmsg; 212 | end 213 | 214 | return 215 | 216 | 217 | % ----------------------------------------------------------------------- 218 | function y = PCM_Quantize(x, fmt) 219 | % PCM_Quantize: 220 | % Scale and quantize input data, from [-1, +1] range to 221 | % either an 8-, 16-, or 24-bit data range. 222 | 223 | % Clip data to normalized range [-1,+1]: 224 | ClipMsg = ['Data clipped during write to file:' fmt.filename]; 225 | ClipWarn = 0; 226 | 227 | % Determine slope (m) and bias (b) for data scaling: 228 | nbits = fmt.nBitsPerSample; 229 | m = 2.^(nbits-1); 230 | 231 | switch nbits 232 | case 8, 233 | b=128; 234 | case {16,24}, 235 | b=0; 236 | otherwise, 237 | error('Invalid number of bits specified.'); 238 | end 239 | 240 | y = round(m .* x + b); 241 | 242 | % Determine quantized data limits, based on the 243 | % presumed input data limits of [-1, +1]: 244 | ylim = [-1 +1]; 245 | qlim = m * ylim + b; 246 | qlim(2) = qlim(2)-1; 247 | 248 | % Clip data to quantizer limits: 249 | i = find(y < qlim(1)); 250 | if ~isempty(i), 251 | warning(ClipMsg); ClipWarn=1; 252 | y(i) = qlim(1); 253 | end 254 | 255 | i = find(y > qlim(2)); 256 | if ~isempty(i), 257 | if ~ClipWarn, warning(ClipMsg); end 258 | y(i) = qlim(2); 259 | end 260 | 261 | return 262 | 263 | 264 | % ----------------------------------------------------------------------- 265 | function err = write_wavedat(fid,fmt,data) 266 | % WRITE_WAVEDAT: Write WAVE data chunk 267 | % Assumes fid points to the wave-data chunk 268 | % Requires structure to be passed. 269 | 270 | err = ''; 271 | 272 | if fmt.wFormatTag==1 | fmt.wFormatTag==3 | fmt.wFormatTag==hex2dec('FFFE'), 273 | % PCM Format 274 | 275 | % 32-bit Type 3 is normalized, so no scaling needed. 276 | if fmt.nBitsPerSample ~= 32, 277 | data = PCM_Quantize(data, fmt); 278 | end 279 | 280 | switch fmt.nBitsPerSample 281 | case 8, 282 | dtype='uchar'; % unsigned 8-bit 283 | case 16, 284 | dtype='short'; % signed 16-bit 285 | case 24, 286 | dtype='bit24'; % signed 24-bit 287 | case 32, 288 | dtype='float'; % normalized 32-bit floating point 289 | otherwise, 290 | err = 'Invalid number of bits specified.'; return; 291 | end 292 | 293 | % Write data, one row at a time (one sample from each channel): 294 | [samples,channels] = size(data); 295 | total_samples = samples*channels; 296 | 297 | if (fwrite(fid, reshape(data',total_samples,1), dtype) ~= total_samples), 298 | err = 'Failed to write PCM data samples.'; return; 299 | end 300 | 301 | % Determine # bytes/sample - format requires rounding 302 | % to next integer number of bytes: 303 | BytesPerSample = ceil(fmt.nBitsPerSample/8); 304 | 305 | % Determine if a pad-byte must be appended to data chunk: 306 | if rem(total_samples*BytesPerSample, 2) ~= 0, 307 | fwrite(fid,0,'uchar'); 308 | end 309 | 310 | else 311 | % Unknown wave-format for data. 312 | err = 'Unsupported data format.'; 313 | end 314 | 315 | return 316 | 317 | % end of wavwrite.m -------------------------------------------------------------------------------- /img/Progetto/x3_1.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/x3_1.wav -------------------------------------------------------------------------------- /img/Progetto/x3_2.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/Progetto/x3_2.wav -------------------------------------------------------------------------------- /img/ProgettoBSS.odp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/ProgettoBSS.odp -------------------------------------------------------------------------------- /img/ProgettoBSS.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/ProgettoBSS.ppt -------------------------------------------------------------------------------- /img/STFTs.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/STFTs.jpg -------------------------------------------------------------------------------- /img/diffefase.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/diffefase.jpg -------------------------------------------------------------------------------- /img/maschere.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/maschere.jpg -------------------------------------------------------------------------------- /img/readme.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/readme.txt -------------------------------------------------------------------------------- /img/segnali.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/segnali.jpg -------------------------------------------------------------------------------- /img/spettro_mic1_orig.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/spettro_mic1_orig.jpg -------------------------------------------------------------------------------- /img/spettro_s1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/spettro_s1.jpg -------------------------------------------------------------------------------- /img/spettro_s2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/spettro_s2.jpg -------------------------------------------------------------------------------- /img/spettro_s3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/spettro_s3.jpg -------------------------------------------------------------------------------- /img/trasfe.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/img/trasfe.jpg -------------------------------------------------------------------------------- /istft.asv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/istft.asv -------------------------------------------------------------------------------- /istft2.asv: -------------------------------------------------------------------------------- 1 | function [signal]=istft2(tra,win,av) 2 | 3 | w=length(win); 4 | t=length(tra(1,:)); 5 | part=zeros(w,t) 6 | 7 | for i=1:t 8 | part(:,i)=(ifft(ifftshift(tra(:,i)),'symmetric').*(1/win)'); 9 | end 10 | 11 | lun=(size(tra,2)+1)*(w*av); 12 | signal=zeros(lun,1); 13 | 14 | signal(:,1)=part(:,1); 15 | for i=2:t 16 | start=1+(i-1)*(w*av); 17 | fin=start+w-1; 18 | signal(start:fin,1)=signal(start:fin,1)+part(:,i); 19 | end 20 | 21 | -------------------------------------------------------------------------------- /istft2.m: -------------------------------------------------------------------------------- 1 | function [signal]=istft2(tra,win,av) 2 | 3 | w=length(win); 4 | t=length(tra(1,:)); 5 | part=zeros(w,t) 6 | 7 | for i=1:t 8 | part(:,i)=ifftshift(ifft(tra(:,i),'symmetric')).*(1/win)'; 9 | end 10 | 11 | lun=(size(tra,2)+1)*(w*av); 12 | signal=zeros(lun,1); 13 | 14 | signal(1:256,1)=part(:,1); 15 | for i=2:t 16 | start=1+(i-1)*(w*av); 17 | fin=start+w-1; 18 | signal(start:fin,1)=signal(start:fin,1)+part(:,i); 19 | end 20 | 21 | -------------------------------------------------------------------------------- /istftnew.m: -------------------------------------------------------------------------------- 1 | function [sign]=istftnew(trasf,win,maxl) 2 | 3 | M=length(win); 4 | R=M/4; 5 | for i=1:size(trasf,2) 6 | trasf(1:M,i)=ifftshift(trasf(1:M,i)); 7 | splicesig(1:M,i)=ifft(trasf(1:M,i)); 8 | end 9 | 10 | sign(:,1)=[splicesig(1:M,1); zeros((M*(size(trasf,2)-1)),1)]; 11 | 12 | for i=2:(size(trasf,2)) 13 | 14 | start=(i-1)*(R); %avanza del 25% 15 | fin=start+M-1; 16 | sign(start:fin,1)=sign(start:fin,1)+splicesig(1:M,i); 17 | end; 18 | 19 | 20 | -------------------------------------------------------------------------------- /magica_new.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/magica_new.wav -------------------------------------------------------------------------------- /newstft.asv: -------------------------------------------------------------------------------- 1 | %FILE DEL PROGETTO DI TATA 2 | %prova stft e risintesi di un segnale audio 3 | % 4 | % CALCOLO DEL NUMERO DI SPLICE: 5 | % numero_splice=1+((length(signal)-length(win))/(length(win)/2)) 6 | % 7 | % 8 | 9 | 10 | clear all; 11 | close all; 12 | 13 | %creazione finestra 14 | win=hamming(512); 15 | 16 | %definita anche la frequenza di campionamnto per come viene importato il file audio 17 | 18 | [signal1,Fs1]=wavread('Urlo22.wav'); 19 | [signal2,Fs2]=wavread('Toms_diner22.wav'); 20 | [signal3,Fs3]=wavread('nonmisomiglia22.wav'); 21 | 22 | 23 | 24 | %% 25 | %MICROFONO2 26 | 27 | %Ritardo dei segnali (in numero di campioni) 28 | rit1=160; 29 | rit2=560; 30 | rit3=800; 31 | 32 | %definizione segnali 33 | signal1r=[zeros(rit1,1); signal1]; 34 | signal2r=[zeros(rit2,1); signal2]; 35 | signal3r=[zeros(rit3,1); signal3]; 36 | 37 | %calcolo la lunghezza massima 38 | lunghezzar=max(length(signal1r),length(signal2r)); 39 | lunghezzar=max(lunghezzar,length(signal3r)); 40 | 41 | 42 | %% 43 | %PADDING 44 | signal1=[signal1; zeros((lunghezzar-length(signal1)),1)]; 45 | signal2=[signal2; zeros((lunghezzar-length(signal2)),1)]; 46 | signal3=[signal3; zeros((lunghezzar-length(signal3)),1)]; 47 | signal1r=[signal1r; zeros((lunghezzar-length(signal1r)),1)]; 48 | signal2r=[signal2r; zeros((lunghezzar-length(signal2r)),1)]; 49 | signal3r=[signal3r; zeros((lunghezzar-length(signal3r)),1)]; 50 | 51 | %Spettri 52 | [f1,f2,f3]=OLAfft(signal1,signal2,signal3,win); 53 | 54 | 55 | %Rappresentazione 56 | fk1=22000/512*(0:256); 57 | tk1=linspace(0,4.965,425); 58 | 59 | figure(1), imagesc(tk1,fk1,abs(f1([1:256],:))); 60 | figure(2), imagesc(tk1,fk1,abs(f2([1:256],1))); 61 | figure(3), imagesc(tk1,fk1,abs(f3([1:256],1))); 62 | 63 | %Segnali somma ai 2 mic (Assenza riverberazioni e dunque risposta impulsiva nel tempo del canale, banda piatta,unici ritardi quelli di propagaz) 64 | som1=signal1+signal2+signal3; 65 | som2=signal1r+signal2r+signal3r; 66 | 67 | %Spettri 68 | 69 | [fsum1,fsum2,fsum3]=OLAfft(som1,som2,0,win); 70 | clear fsum3; 71 | 72 | % %Rappresentazione 73 | % figure(4); imagesc(abs(fsum1)); 74 | % figure(5); imagesc(abs(fsum2)); 75 | 76 | %Creazione spazio delle features 77 | [feat1,feat2]=spfeat(fsum1,fsum2); -------------------------------------------------------------------------------- /newstft.m: -------------------------------------------------------------------------------- 1 | %FILE DEL PROGETTO DI TATA 2 | %prova stft e risintesi di un segnale audio 3 | % 4 | % CALCOLO DEL NUMERO DI SPLICE: 5 | % numero_splice=1+((length(signal)-length(win))/(length(win)/2)) 6 | % 7 | % 8 | 9 | 10 | clear all; 11 | close all; 12 | 13 | %creazione finestra 14 | win=hamming(512); 15 | 16 | %definita anche la frequenza di campionamnto per come viene importato il file audio 17 | 18 | [signal1,Fs1]=wavread('Urlo22.wav'); 19 | [signal2,Fs2]=wavread('Toms_diner22.wav'); 20 | [signal3,Fs3]=wavread('nonmisomiglia22.wav'); 21 | 22 | 23 | 24 | %% 25 | %MICROFONO2 26 | 27 | %Ritardo dei segnali (in numero di campioni) 28 | rit1=160; 29 | rit2=560; 30 | rit3=800; 31 | 32 | %definizione segnali 33 | signal1r=[zeros(rit1,1); signal1]; 34 | signal2r=[zeros(rit2,1); signal2]; 35 | signal3r=[zeros(rit3,1); signal3]; 36 | 37 | %calcolo la lunghezza massima 38 | lunghezzar=max(length(signal1r),length(signal2r)); 39 | lunghezzar=max(lunghezzar,length(signal3r)); 40 | 41 | 42 | %% 43 | %PADDING 44 | signal1=[signal1; zeros((lunghezzar-length(signal1)),1)]; 45 | signal2=[signal2; zeros((lunghezzar-length(signal2)),1)]; 46 | signal3=[signal3; zeros((lunghezzar-length(signal3)),1)]; 47 | signal1r=[signal1r; zeros((lunghezzar-length(signal1r)),1)]; 48 | signal2r=[signal2r; zeros((lunghezzar-length(signal2r)),1)]; 49 | signal3r=[signal3r; zeros((lunghezzar-length(signal3r)),1)]; 50 | 51 | %Spettri 52 | [f1,f2,f3]=OLAfft(signal1,signal2,signal3,win); 53 | 54 | %Rappresentazione 55 | figure(1), imagesc(abs(f1)); 56 | figure(2), imagesc(abs(f2)); 57 | figure(3), imagesc(abs(f3)); 58 | 59 | %Segnali somma ai 2 mic (Assenza riverberazioni e dunque risposta impulsiva nel tempo del canale, banda piatta,unici ritardi quelli di propagaz) 60 | som1=signal1+signal2+signal3; 61 | som2=signal1r+signal2r+signal3r; 62 | 63 | %Spettri 64 | 65 | [fsum1,fsum2,fsum3]=OLAfft(som1,som2,0,win); 66 | clear fsum3; 67 | 68 | %Rappresentazione 69 | figure(4); imagesc(abs(fsum1)); 70 | figure(5); imagesc(abs(fsum2)); -------------------------------------------------------------------------------- /presentazione.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/presentazione.pdf -------------------------------------------------------------------------------- /progetto.asv: -------------------------------------------------------------------------------- 1 | % Blind Source Separation Problem resolved via Binary Mask Approach 2 | % 3 | % Roberto Calandrini Carlo Fortini 4 | % 5 | % 6 | 7 | 8 | clear all; 9 | close all; 10 | 11 | time=cputime; 12 | 13 | %creazione finestra 14 | win=hamming(512); 15 | 16 | %Acquisizione delle 3 sorgenti audio 17 | 18 | [s1,Fs1]=wavexread('3personePCM.wav'); 19 | [s2,Fs2]=wavexread('Toms_diner.wav'); 20 | [s3,Fs3]=wavexread('Voce_maschile.wav'); 21 | 22 | %Ritardo dei segnali (in numero di campioni) 23 | ang=[-40 10 80]; 24 | [diffe,com,T]=geometria(Fs1,ang,[1 1 1],0.02); 25 | 26 | %calcolo la lunghezza massima 27 | lun=max([length(s1) length(s2) length(s3)]); 28 | if rem(lun,2)~=0 29 | lun=lun+1; %Avere la lunghezza del segnale pari semplifica le cose 30 | end 31 | 32 | %% 33 | %PADDING 34 | s1=[s1; zeros((lun-length(s1)),1)]; 35 | s2=[s2; zeros((lun-length(s2)),1)]; 36 | s3=[s3; zeros((lun-length(s3)),1)]; 37 | 38 | %Implementazione dei ritardi frazionali ai segnali 39 | s1r=ritfraz(s1,diffe(1)); 40 | s2r=ritfraz(s2,diffe(2)); 41 | s3r=ritfraz(s3,diffe(3)); 42 | 43 | %Segnali somma ai 2 mic (Assenza riverberazioni e dunque risposta impulsiva nel tempo del canale, banda piatta,unici ritardi quelli di propagaz) 44 | %Si aggiustano da soli in base agli angoli di arrivo 45 | % 46 | if ang(1)<0 47 | mic1=s1; 48 | mic2=s1r; 49 | else 50 | mic1=s1r; 51 | mic2=s1; 52 | end; 53 | if ang(2)<0 54 | mic1=mic1+s2; 55 | mic2=mic2+s2r; 56 | else 57 | mic1=mic1+s2r; 58 | mic2=mic2+s2; 59 | end; 60 | if ang(3)<0 61 | mic1=mic1+s3; 62 | mic2=mic2+s3r; 63 | else 64 | mic1=mic1+s3r; 65 | mic2=mic2+s3; 66 | end; 67 | 68 | 69 | %Calcolo spettrogramma al mic1 e al mic2 70 | fmic1=STFT(mic1,win,0.25); 71 | fmic2=STFT(mic2,win,0.25); 72 | 73 | 74 | %Rappresentazione spettrogrammi del segnale ai 2 mic 75 | pas=length(win); 76 | fk=-Fs1/2+Fs1/pas:Fs1/pas:Fs1/2; %asse delle frequenze discrete 77 | wk=1:1:size(fmic1,2); %asse con numeri d'indice delle finestre temporali 78 | figure,imagesc(wk,fk,abs(fmic1)); 79 | figure,imagesc(wk,fk,abs(fmic2)); 80 | 81 | %Estraggo features (rapporto delle ampiezze, e fasi normalizzate) 82 | Theta=featuresB(fmic1,fmic2,Fs1,fk); 83 | 84 | %Classifico con kmeans (uso norma L1) 85 | [IDX Cen]=kmeans(Theta,3,'dist','city'); 86 | 87 | %Conto quanti campioni classifica come appartenenti ad ogni sorgente 88 | sorg1=0;sorg2=0;sorg3=0; 89 | 90 | for i=1:length(IDX); 91 | if IDX(i,1)==1; 92 | sorg1=sorg1+1; 93 | else 94 | if IDX(i,1)==2; 95 | sorg2=sorg2+1; 96 | else 97 | if IDX(i,1)==3; 98 | sorg3=sorg3+1; 99 | end; 100 | end; 101 | end; 102 | end; 103 | 104 | sorg1 105 | sorg2 106 | sorg3 107 | 108 | %Coordinate dei centroidi a display 109 | disp('coordinate dei centroidi'); 110 | Cen 111 | 112 | 113 | %Creazione maschere binarie 114 | class=reshape(IDX,length(win),size(fmic1,2)); 115 | 116 | masc1=zeros(size(fmic1,1),size(fmic1,2)); 117 | masc2=zeros(size(fmic1,1),size(fmic1,2)); 118 | masc3=zeros(size(fmic1,1),size(fmic1,2)); 119 | 120 | for i=1:size(masc1,1); 121 | for t=1:size(masc1,2); 122 | if (class(i,t)==1); 123 | masc1(i,t)=1; 124 | else 125 | if (class(i,t)==2); 126 | masc2(i,t)=1; 127 | else 128 | masc3(i,t)=1; 129 | end; 130 | end; 131 | end; 132 | end; 133 | 134 | %Applico le maschere binarie alla STFT del segnale somma al primo microfono 135 | s1traric=fmic1.*masc1; 136 | s2traric=fmic1.*masc2; 137 | s3traric=fmic1.*masc3; 138 | 139 | %Ottengo i segnali temporali ricostruiti attraverso ISTFT 140 | sig1ric=ISTFT(s1traric,win,0.25); 141 | sig2ric=ISTFT(s2traric,win,0.25); 142 | sig3ric=ISTFT(s3traric,win,0.25); 143 | 144 | %RICONOSCIMENTO SORGENTI e CALCOLO PRESTAZIONI 145 | 146 | %primo ricostruito 147 | corre11=xcov(sig1ric,s1); 148 | corre12=xcov(sig1ric,s2); 149 | corre13=xcov(sig1ric,s3); 150 | 151 | corre1=[max(corre11);max(corre12);max(corre13)]' 152 | 153 | %secondo ricostruito 154 | corre21=xcov(sig2ric,s1); 155 | corre22=xcov(sig2ric,s2); 156 | corre23=xcov(sig2ric,s3); 157 | 158 | corre2=[max(corre21);max(corre22);max(corre23)]' 159 | 160 | %terzo ricostruito 161 | corre31=xcov(sig3ric,s1); 162 | corre32=xcov(sig3ric,s2); 163 | corre33=xcov(sig3ric,s3); 164 | 165 | corre3=[max(corre31);max(corre32);max(corre33)]' 166 | 167 | %REGOLE DI CORRISPONDENZA 168 | 169 | [mass1,I1] = max(corre1); 170 | [mass2,I2] = max(corre2); 171 | [mass3,I3] = max(corre3); 172 | 173 | 174 | 175 | 176 | 177 | %% 178 | % %CALCOLO DELLE PRESTAZIONI 179 | % 180 | % 181 | %CALCOLO DELLE INTERFERENZE PRIMA DEL PROCESSSING 182 | SIRin1=10*log10(sum(abs(s1).^2)/(sum(abs(s2).^2)+sum(abs(s3).^2))); 183 | SIRin2=10*log10(sum(abs(s2).^2)/(sum(abs(s1).^2)+sum(abs(s3).^2))); 184 | SIRin3=10*log10(sum(abs(s3).^2)/(sum(abs(s1).^2)+sum(abs(s2).^2))); 185 | 186 | %dipende dalla classificazione!!!!!!! 187 | interf12=STFT((s1+s2),win,0.25); 188 | interf23=STFT((s2+s3),win,0.25); 189 | interf13=STFT((s1+s3),win,0.25); 190 | 191 | if I1==1; 192 | interf23=interf23.*masc1; 193 | interf23s=ISTFT(interf23,win,0.25); 194 | SIRout1=10*log10(sum(sig1ric.^2)/(sum(interf23s.^2))); 195 | G1=SIRout1-SIRin1; 196 | end; 197 | 198 | if I1==2; 199 | interf13=interf13.*masc1; 200 | interf13s=ISTFT(interf13,win,0.25); 201 | SIRout1=10*log10(sum(sig1ric.^2)/(sum(interf13s.^2))); 202 | G2=SIRout1-SIRin2; 203 | end; 204 | 205 | if I1==3; 206 | interf12=interf12.*masc1; 207 | interf12s=ISTFT(interf12,win,0.25); 208 | SIRout1=10*log10(sum(sig1ric.^2)/(sum(interf12s.^2))); 209 | G3=SIRout1-SIRin3; 210 | end; 211 | 212 | 213 | if I2==1; 214 | interf23=interf23.*masc2; 215 | interf23s=ISTFT(interf23,win,0.25); 216 | SIRout2=10*log10(sum(sig2ric.^2)/(sum(interf23s.^2))); 217 | G1=SIRout2-SIRin1; 218 | end; 219 | 220 | if I2==2; 221 | interf13=interf13.*masc2; 222 | interf13s=ISTFT(interf13,win,0.25); 223 | SIRout2=10*log10(sum(sig2ric.^2)/(sum(interf13s.^2))); 224 | G2=SIRout2-SIRin2; 225 | end; 226 | 227 | if I2==3; 228 | interf12=interf12.*masc2; 229 | interf12s=ISTFT(interf12,win,0.25); 230 | SIRout2=10*log10(sum(sig2ric.^2)/(sum(interf12s.^2))); 231 | G3=SIRout2-SIRin3; 232 | end; 233 | 234 | if I3==1; 235 | interf23=interf23.*masc3; 236 | interf23s=ISTFT(interf23,win,0.25); 237 | SIRout3=10*log10(sum(sig3ric.^2)/(sum(interf23s.^2))); 238 | G1=SIRout3-SIRin1; 239 | end; 240 | 241 | if I3==2; 242 | interf13=interf13.*masc3; 243 | interf13s=ISTFT(interf13,win,0.25); 244 | SIRout3=10*log10(sum(sig3ric.^2)/(sum(interf13s.^2))); 245 | G2=SIRout3-SIRin2; 246 | end; 247 | 248 | if I3==3; 249 | interf12=interf12.*masc3; 250 | interf12s=ISTFT(interf12,win,0.25); 251 | SIRout3=10*log10(sum(sig3ric.^2)/(sum(interf12s.^2))); 252 | G3=SIRout3-SIRin3; 253 | end; 254 | 255 | 256 | 257 | disp('Guadagni in dB'); 258 | G1 259 | G2 260 | G3 261 | -------------------------------------------------------------------------------- /progetto.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/progetto.m -------------------------------------------------------------------------------- /progetto_audio_modfile.aup: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /progetto_audio_modfile_data/b00010.auf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/progetto_audio_modfile_data/b00010.auf -------------------------------------------------------------------------------- /progetto_audio_modfile_data/b00019.au: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/progetto_audio_modfile_data/b00019.au -------------------------------------------------------------------------------- /progetto_audio_modfile_data/b00028.au: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/progetto_audio_modfile_data/b00028.au -------------------------------------------------------------------------------- /progetto_audio_modfile_data/b00029.au: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/progetto_audio_modfile_data/b00029.au -------------------------------------------------------------------------------- /progetto_audio_modfile_data/b00031.au: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/progetto_audio_modfile_data/b00031.au -------------------------------------------------------------------------------- /progetto_audio_modfile_data/b00033.au: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/progetto_audio_modfile_data/b00033.au -------------------------------------------------------------------------------- /readme.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/readme.txt -------------------------------------------------------------------------------- /ritfraz.asv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/ritfraz.asv -------------------------------------------------------------------------------- /ritfraz.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/ritfraz.m -------------------------------------------------------------------------------- /stft.asv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/stft.asv -------------------------------------------------------------------------------- /stft_sintesys.asv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/stft_sintesys.asv -------------------------------------------------------------------------------- /stft_sintesys.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/stft_sintesys.m -------------------------------------------------------------------------------- /tipoB.asv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/tipoB.asv -------------------------------------------------------------------------------- /tipoB.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/tipoB.m -------------------------------------------------------------------------------- /toms_new.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/toms_new.wav -------------------------------------------------------------------------------- /voce_maschile.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robical/BlindSourceSeparation/d9f756c23c5e8124eb4bb0d07453b4d3fa844bc7/voce_maschile.wav -------------------------------------------------------------------------------- /wavexread.m: -------------------------------------------------------------------------------- 1 | function [y,Fs,nbits,speakers] = wavexread(file,ext) 2 | %WAVEXREAD Read Microsoft WAVE-FORMAT-EXTENSIBLE (".wav") sound file. 3 | % Y=WAVEXREAD(FILE) reads a WAVE file specified by the string FILE, 4 | % returning the sampled data in Y. The ".wav" extension is appended 5 | % if no extension is given. Amplitude values are in the range [-1,+1]. 6 | % 7 | % [Y,FS,NBITS]=WAVEXREAD(FILE) returns the sample rate (FS) in Hertz 8 | % and the number of bits per sample (NBITS) used to encode the 9 | % data in the file. 10 | % 11 | % [...]=WAVEXREAD(FILE,N) returns only the first N samples from each 12 | % channel in the file. 13 | % [...]=WAVEXREAD(FILE,[N1 N2]) returns only samples N1 through N2 from 14 | % each channel in the file. 15 | % SIZ=WAVEXREAD(FILE,'size') returns the size of the audio data contained 16 | % in the file in place of the actual audio data, returning the 17 | % vector SIZ=[samples channels]. 18 | % 19 | % [Y,FS,NBITS,OPTS]=WAVEXREAD(...) returns a structure OPTS of additional 20 | % information contained in the WAV file. The content of this 21 | % structure differs from file to file. Typical structure fields 22 | % include '.fmt' (audio format information) and '.info' (text 23 | % which may describe subject title, copy right, etc.) 24 | % 25 | % Supports multi-channel data, with up to 32 bits per sample. 26 | % 27 | % NOTE: This file reader only supports Microsoft PCM data format. 28 | % It does not support wave-list data. 29 | % 30 | % See also WAVEXWRITE, WAVWRITE, AUREAD, AUWRITE. 31 | 32 | % Author: D. Orofino 33 | % Copyright 1984-2002 The MathWorks, Inc. 34 | % $Revision: 5.28 $ $Date: 2002/05/30 20:42:03 $ 35 | % 36 | % Modified 2004/07/27 by Sylvain Choisel 37 | % to handle WAVE-FORMAT-EXTENSIBLE 38 | 39 | % Parse input arguments: 40 | nargchk(1,2,nargin); 41 | if nargin<2, ext=[]; end % Default - read all samples 42 | exts = prod(size(ext)); % length of extent info 43 | if ~strncmpi(ext,'size',exts) & (exts > 2), 44 | error('Index range must be specified as a scalar or 2-element vector.'); 45 | end 46 | if ~ischar(ext) & exts==1, 47 | if ext==0, 48 | ext='size'; % synonym for size 49 | else 50 | ext=[1 ext]; % Prepend start sample index 51 | end 52 | end 53 | 54 | % Open WAV file: 55 | [fid,msg] = open_wav(file); 56 | error(msg); 57 | 58 | % Now the file is open - wrap remaining code in try/catch so we can 59 | % close the file if an error occurs 60 | try 61 | 62 | % Find the first RIFF chunk: 63 | [riffck,msg] = find_cktype(fid,'RIFF'); 64 | %error(msg); 65 | if ~isempty(msg), 66 | error('Not a WAVE file.'); 67 | end 68 | 69 | % Verify that RIFF file is WAVE data type: 70 | msg = check_rifftype(fid,'WAVE'); 71 | error(msg); 72 | 73 | % Find optional chunks, and don't stop till found: 74 | found_data = 0; 75 | end_of_file = 0; 76 | opt_ck = []; 77 | 78 | while(~end_of_file), 79 | [ck,msg] = find_cktype(fid); 80 | error(msg); 81 | 82 | switch lower(ck.ID) 83 | 84 | case 'end of file' 85 | end_of_file = 1; 86 | 87 | case 'fmt' 88 | % found 89 | [opt_ck,msg] = read_wavefmt(fid,ck,opt_ck); 90 | error(msg); 91 | 92 | case 'data' 93 | % found: 94 | found_data = 1; 95 | if ~isfield(opt_ck,'fmt'), 96 | error('Corrupt WAV file: found audio data before format information.'); 97 | end 98 | 99 | if strncmpi(ext,'size',exts) | ... 100 | (~isempty(ext) & all(ext==0)), 101 | % Caller doesn't want data - just data size: 102 | [samples,msg] = read_wavedat(ck, opt_ck.fmt, -1); 103 | error(msg); 104 | y = [samples opt_ck.fmt.nChannels]; 105 | 106 | else 107 | % Read : 108 | [datack,msg] = read_wavedat(ck, opt_ck.fmt, ext); 109 | error(msg); 110 | y = datack.Data; 111 | 112 | end 113 | 114 | case 'fact' 115 | % Optional found: 116 | [opt_ck,msg] = read_factck(fid, ck, opt_ck); 117 | error(msg); 118 | 119 | case 'disp' 120 | % Optional found: 121 | [opt_ck,msg] = read_dispck(fid, ck, opt_ck); 122 | error(msg); 123 | 124 | case 'list' 125 | % Optional found: 126 | [opt_ck, msg] = read_listck(fid, ck, opt_ck); 127 | error(msg); 128 | 129 | otherwise 130 | % Skip over data in unprocessed chunks: 131 | if rem(ck.Size,2), ck.Size=ck.Size+1; end 132 | if(fseek(fid,ck.Size,0)==-1), 133 | error('Incorrect chunk size information in WAV file.'); 134 | end 135 | end 136 | end 137 | 138 | catch 139 | fclose(fid); 140 | error(lasterr); 141 | end 142 | 143 | fclose(fid); 144 | 145 | % Parse structure info for return to user: 146 | Fs = opt_ck.fmt.nSamplesPerSec; 147 | if opt_ck.fmt.wFormatTag == 1 | opt_ck.fmt.wFormatTag == 3, 148 | % Type 3 floating point has no nBitsPerSample field, so use 149 | % nBlockAlign to figure out number of bits 150 | nbits = (opt_ck.fmt.nBlockAlign / opt_ck.fmt.nChannels) * 8; 151 | else 152 | nbits = []; % Unknown 153 | end 154 | 155 | speakers=find((fliplr(dec2bin(opt_ck.fmt.dwChanelMask)-48))~=0); 156 | 157 | % end of wavread() 158 | 159 | 160 | % ------------------------------------------------------------------------ 161 | % Local functions: 162 | % ------------------------------------------------------------------------ 163 | 164 | % --------------------------------------------- 165 | % OPEN_WAV: Open a WAV file for reading 166 | % --------------------------------------------- 167 | function [fid,msg] = open_wav(file) 168 | % Append .wav extension if it's missing: 169 | [pat,nam,ext] = fileparts(file); 170 | if isempty(ext), 171 | file = [file '.wav']; 172 | end 173 | [fid,msg] = fopen(file,'rb','l'); % Little-endian 174 | if fid == -1, 175 | msg = 'Cannot open file.'; 176 | end 177 | return 178 | 179 | % --------------------------------------------- 180 | % READ_CKINFO: Reads next RIFF chunk, but not the chunk data. 181 | % If optional sflg is set to nonzero, reads SUBchunk info instead. 182 | % Expects an open FID pointing to first byte of chunk header. 183 | % Returns a new chunk structure. 184 | % --------------------------------------------- 185 | function [ck,msg] = read_ckinfo(fid) 186 | 187 | msg = ''; 188 | ck.fid = fid; 189 | ck.Data = []; 190 | err_msg = 'Truncated chunk header found - possibly not a WAV file.'; 191 | 192 | [s,cnt] = fread(fid,4,'char'); 193 | 194 | % Do not error-out if a few (<4) trailing chars are in file 195 | % Just return quickly: 196 | if (cnt~=4), 197 | if feof(fid), 198 | % End of the file (not an error) 199 | ck.ID = 'end of file'; % unambiguous chunk ID (>4 chars) 200 | ck.Size = 0; 201 | else 202 | msg = err_msg; 203 | end 204 | return 205 | end 206 | 207 | ck.ID = deblank(setstr(s')); 208 | 209 | % Read chunk size (skip if subchunk): 210 | [sz,cnt] = fread(fid,1,'ulong'); 211 | if cnt~=1, 212 | msg = err_msg; 213 | return 214 | end 215 | ck.Size = sz; 216 | return 217 | 218 | % --------------------------------------------- 219 | % FIND_CKTYPE: Finds a chunk with appropriate type. 220 | % Searches from current file position specified by fid. 221 | % Leaves file positions to data of desired chunk. 222 | % If optional sflg is set to nonzero, finds a SUBchunk instead. 223 | % --------------------------------------------- 224 | function [ck,msg] = find_cktype(fid,ftype) 225 | 226 | msg = ''; 227 | if nargin<2, ftype = ''; end 228 | 229 | [ck,msg] = read_ckinfo(fid); 230 | if ~isempty(msg), return; end 231 | 232 | % Was a required chunk type specified? 233 | if ~isempty(ftype) & ~strcmpi(ck.ID,ftype), 234 | msg = ['<' ftype '-ck> did not appear as expected']; 235 | end 236 | return 237 | 238 | 239 | % --------------------------------------------- 240 | % CHECK_RIFFTYPE: Finds the RIFF data type. 241 | % Searches from current file position specified by fid. 242 | % Leaves file positions to data of desired chunk. 243 | % --------------------------------------------- 244 | function msg = check_rifftype(fid,ftype) 245 | msg = ''; 246 | [rifftype,cnt] = fread(fid,4,'char'); 247 | rifftype = setstr(rifftype)'; 248 | 249 | if cnt~=4, 250 | msg = 'Not a WAVE file.'; 251 | elseif ~strcmpi(rifftype,ftype), 252 | msg = ['File does not contain required ''' ftype ''' data chunk.']; 253 | end 254 | 255 | return 256 | 257 | 258 | % --------------------------------------------- 259 | % READ_LISTCK: Read the FLIST chunk: 260 | % --------------------------------------------- 261 | function [opt_ck,msg] = read_listck(fid,ck, orig_opt_ck) 262 | 263 | opt_ck = orig_opt_ck; 264 | 265 | orig_pos = ftell(fid); 266 | total_bytes = ck.Size; % # bytes in subchunk 267 | nbytes = 4; % # of required bytes in header 268 | msg = ''; 269 | err_msg = 'Error reading chunk.'; 270 | 271 | if total_bytes < nbytes, 272 | msg = err_msg; 273 | return 274 | end 275 | 276 | % Read standard data: 277 | listdata = setstr(fread(fid,total_bytes,'uchar')'); 278 | 279 | listtype = lower(listdata(1:4)); % Get LIST type 280 | listdata = listdata(5:end); % Move past INFO 281 | 282 | if strcmp(listtype,'info'), 283 | % Information: 284 | while(~isempty(listdata)), 285 | id = listdata(1:4); 286 | switch lower(id) 287 | case 'iart' 288 | name = 'Artist'; 289 | case 'icmt' 290 | name = 'Comments'; 291 | case 'icrd' 292 | name = 'Creation date'; 293 | case 'icop' 294 | name = ['Copy' 'right']; 295 | case 'ieng' 296 | name = 'Engineer'; 297 | case 'inam' 298 | name = 'Name'; 299 | case 'iprd' 300 | name = 'Product'; 301 | case 'isbj' 302 | name = 'Subject'; 303 | case 'isft' 304 | name = 'Software'; 305 | case 'isrc' 306 | name = 'Source'; 307 | otherwise 308 | name = id; 309 | end 310 | 311 | if ~isfield(opt_ck,'info'), 312 | opt_ck.info = []; 313 | end 314 | len = listdata(5:8) * 2.^[0 8 16 24]'; 315 | txt = listdata(9:9+len-1); 316 | 317 | % Fix up text: deblank, and replace CR/LR with LF 318 | txt = deblank(txt); 319 | idx=findstr(txt,setstr([13 10])); 320 | txt(idx) = ''; 321 | 322 | % Store - don't include the "name" info 323 | opt_ck.info.(lower(id)) = txt; 324 | 325 | if rem(len,2), len=len+1; end 326 | listdata = listdata(9+len:end); 327 | end 328 | 329 | else 330 | if ~isfield(opt_ck,'list'), 331 | opt_ck.list = []; 332 | end 333 | opt_ck.list.(listtype) = listdata; 334 | end 335 | 336 | % Skip over any unprocessed data: 337 | if rem(total_bytes,2), total_bytes=total_bytes+1; end 338 | rbytes = total_bytes - (ftell(fid) - orig_pos); 339 | if rbytes~=0, 340 | if (fseek(fid,rbytes,'cof')==-1), 341 | msg = err_msg; 342 | end 343 | end 344 | return 345 | 346 | 347 | % --------------------------------------------- 348 | % READ_DISPCK: Read the DISP chunk: 349 | % --------------------------------------------- 350 | function [opt_ck, msg] = read_dispck(fid,ck,orig_opt_ck) 351 | 352 | opt_ck = orig_opt_ck; 353 | 354 | orig_pos = ftell(fid); 355 | total_bytes = ck.Size; % # bytes in subchunk 356 | nbytes = 4; % # of required bytes in header 357 | msg = ''; 358 | err_msg = 'Error reading chunk.'; 359 | 360 | if total_bytes < nbytes, 361 | msg = err_msg; 362 | return 363 | end 364 | 365 | % Read standard data: 366 | data = fread(fid,total_bytes,'uchar'); 367 | 368 | % Process data: 369 | 370 | % First few entries are size info: 371 | icon_data = data; 372 | siz_info = reshape(icon_data(1:2*4),4,2)'; 373 | siz_info = siz_info*(2.^[0 8 16 24]'); 374 | is_icon = isequal(siz_info,[8;40]); 375 | 376 | if ~is_icon, 377 | % Not the icon: 378 | opt_ck.disp.name = 'DisplayName'; 379 | txt = deblank(setstr(data(5:end)')); 380 | opt_ck.disp.text = txt; 381 | end 382 | 383 | % Skip over any unprocessed data: 384 | if rem(total_bytes,2), total_bytes=total_bytes+1; end 385 | rbytes = total_bytes - (ftell(fid) - orig_pos); 386 | if rbytes~=0, 387 | if(fseek(fid,rbytes,'cof')==-1), 388 | msg = err_msg; 389 | end 390 | end 391 | return 392 | 393 | 394 | % --------------------------------------------- 395 | % READ_FACTCK: Read the FACT chunk: 396 | % --------------------------------------------- 397 | function [opt_ck,msg] = read_factck(fid,ck,orig_opt_ck) 398 | 399 | opt_ck = orig_opt_ck; 400 | orig_pos = ftell(fid); 401 | total_bytes = ck.Size; % # bytes in subchunk 402 | nbytes = 4; % # of required bytes in header 403 | msg = ''; 404 | err_msg = 'Error reading chunk.'; 405 | 406 | if total_bytes < nbytes, 407 | msg = err_msg; 408 | return 409 | end 410 | 411 | % Read standard data: 412 | opt_ck.fact = setstr(fread(fid,total_bytes,'uchar')'); 413 | 414 | % Skip over any unprocessed data: 415 | if rem(total_bytes,2), total_bytes=total_bytes+1; end 416 | rbytes = total_bytes - (ftell(fid) - orig_pos); 417 | if rbytes~=0, 418 | if(fseek(fid,rbytes,'cof')==-1), 419 | msg = err_msg; 420 | end 421 | end 422 | return 423 | 424 | 425 | % --------------------------------------------- 426 | % READ_WAVEFMT: Read WAVE format chunk. 427 | % Assumes fid points to the subchunk. 428 | % Requires chunk structure to be passed, indicating 429 | % the length of the chunk in case we don't recognize 430 | % the format tag. 431 | % --------------------------------------------- 432 | function [opt_ck,msg] = read_wavefmt(fid,ck,orig_opt_ck) 433 | 434 | opt_ck = orig_opt_ck; 435 | 436 | orig_pos = ftell(fid); 437 | total_bytes = ck.Size; % # bytes in subchunk 438 | nbytes = 40; % # of required bytes in header 439 | msg = ''; 440 | err_msg = 'Error reading chunk.'; 441 | 442 | if total_bytes < nbytes, 443 | msg = err_msg; 444 | return 445 | end 446 | 447 | % Read standard data: 448 | opt_ck.fmt.wFormatTag = fread(fid,1,'ushort'); % Data encoding format 449 | opt_ck.fmt.nChannels = fread(fid,1,'ushort'); % Number of channels 450 | opt_ck.fmt.nSamplesPerSec = fread(fid,1,'ulong'); % Samples per second 451 | opt_ck.fmt.nAvgBytesPerSec = fread(fid,1,'ulong'); % Avg transfer rate 452 | opt_ck.fmt.nBlockAlign = fread(fid,1,'ushort'); % Block alignment 453 | %sc 454 | opt_ck.fmt.wBitsPerSample = fread(fid,1,'ushort'); 455 | opt_ck.fmt.cbSize = fread(fid,1,'ushort'); 456 | opt_ck.fmt.wValidBitsPerSample = fread(fid,1,'ushort'); 457 | opt_ck.fmt.dwChanelMask = fread(fid,1,'ulong'); 458 | opt_ck.fmt.subFormat = fread(fid,16,'uchar'); 459 | 460 | % Read format-specific info: 461 | switch opt_ck.fmt.wFormatTag 462 | case 1 463 | % PCM Format: 464 | %[opt_ck.fmt, msg] = read_fmt_pcm(fid, ck, opt_ck.fmt); 465 | exit('Invalid extensible format'); 466 | case hex2dec('FFFE') 467 | % [opt_ck.fmt, msg] = read_fmt_pcm(fid, ck, opt_ck.fmt); 468 | end 469 | 470 | 471 | % Skip over any unprocessed fmt-specific data: 472 | %if rem(total_bytes,2), total_bytes=total_bytes+1; end 473 | %rbytes = total_bytes - (ftell(fid) - orig_pos); 474 | %if rbytes~=0, 475 | % if(fseek(fid,rbytes,'cof')==-1), 476 | % msg = err_msg; 477 | % end 478 | %end 479 | 480 | return 481 | 482 | 483 | % --------------------------------------------- 484 | % READ_FMT_PCM: Read info 485 | % --------------------------------------------- 486 | function [fmt,msg] = read_fmt_pcm(fid, ck, fmt) 487 | 488 | % There had better be a bits/sample field: 489 | total_bytes = ck.Size; % # bytes in subchunk 490 | nbytes = 14; % # of bytes already read in header 491 | msg = ''; 492 | err_msg = 'Error reading PCM chunk.'; 493 | 494 | %if (total_bytes < nbytes+2), 495 | % msg = err_msg; 496 | % return 497 | %end 498 | 499 | %[bits,cnt] = fread(fid,1,'ushort'); 500 | %nbytes=nbytes+2; 501 | %if (cnt~=1), 502 | % msg = err_msg; 503 | % return 504 | %end 505 | %fmt.nBitsPerSample=bits; 506 | 507 | % Are there any additional fields present? 508 | if (total_bytes > nbytes), 509 | % See if the "cbSize" field is present. If so, grab the data: 510 | if (total_bytes >= nbytes+2), 511 | % we have the cbSize ushort in the file: 512 | [cbSize,cnt]=fread(fid,1,'ushort'); 513 | nbytes=nbytes+2; 514 | if (cnt~=1), 515 | msg = err_msg; 516 | return 517 | end 518 | fmt.cbSize = cbSize; 519 | end 520 | 521 | % Simply skip any remaining stuff - we don't know what it is: 522 | if rem(total_bytes,2), total_bytes=total_bytes+1; end 523 | rbytes = total_bytes - nbytes; 524 | if rbytes~=0, 525 | if (fseek(fid,rbytes,'cof') == -1); 526 | msg = err_msg; 527 | end 528 | end 529 | end 530 | return 531 | 532 | 533 | % --------------------------------------------- 534 | % READ_WAVEDAT: Read WAVE data chunk 535 | % Assumes fid points to the wave-data chunk 536 | % Requires and structures to be passed. 537 | % Requires extraction range to be specified. 538 | % Setting ext=[] forces ALL samples to be read. Otherwise, 539 | % ext should be a 2-element vector specifying the first 540 | % and last samples (per channel) to be extracted. 541 | % Setting ext=-1 returns the number of samples per channel, 542 | % skipping over the sample data. 543 | % --------------------------------------------- 544 | function [dat,msg] = read_wavedat(datack,wavefmt,ext) 545 | 546 | % In case of unsupported data compression format: 547 | dat = []; 548 | fmt_msg = ''; 549 | 550 | switch wavefmt.wFormatTag 551 | case 1 552 | % PCM Format: 553 | [dat,msg] = read_dat_pcm(datack,wavefmt,ext); 554 | case 2 555 | fmt_msg = 'Microsoft ADPCM'; 556 | case 3 557 | % normalized floating-point 558 | [dat,msg] = read_dat_pcm(datack,wavefmt,ext); 559 | case 6 560 | fmt_msg = 'CCITT a-law'; 561 | case 7 562 | fmt_msg = 'CCITT mu-law'; 563 | case 17 564 | fmt_msg = 'IMA ADPCM'; 565 | case 34 566 | fmt_msg = 'DSP Group TrueSpeech TM'; 567 | case 49 568 | fmt_msg = 'GSM 6.10'; 569 | case 50 570 | fmt_msg = 'MSN Audio'; 571 | case 257 572 | fmt_msg = 'IBM Mu-law'; 573 | case 258 574 | fmt_msg = 'IBM A-law'; 575 | case 259 576 | fmt_msg = 'IBM AVC Adaptive Differential'; 577 | case hex2dec('FFFE') %sc 578 | % WAVE-FORMAT-EXTENSIBLE 579 | [dat,msg] = read_dat_pcm(datack,wavefmt,ext); 580 | otherwise 581 | fmt_msg = ['Format #' num2str(wavefmt.wFormatTag)]; 582 | end 583 | if ~isempty(fmt_msg), 584 | msg = ['Data compression format (' fmt_msg ') is not supported.']; 585 | end 586 | return 587 | 588 | 589 | % --------------------------------------------- 590 | % READ_DAT_PCM: Read PCM format data from chunk. 591 | % Assumes fid points to the wave-data chunk 592 | % Requires and structures to be passed. 593 | % Requires extraction range to be specified. 594 | % Setting ext=[] forces ALL samples to be read. Otherwise, 595 | % ext should be a 2-element vector specifying the first 596 | % and last samples (per channel) to be extracted. 597 | % Setting ext=-1 returns the number of samples per channel, 598 | % skipping over the sample data. 599 | % --------------------------------------------- 600 | function [dat,msg] = read_dat_pcm(datack,wavefmt,ext) 601 | 602 | dat = []; 603 | msg = ''; 604 | 605 | % Determine # bytes/sample - format requires rounding 606 | % to next integer number of bytes: 607 | BytesPerSample = ceil(wavefmt.nBlockAlign / wavefmt.nChannels); 608 | if (BytesPerSample == 1), 609 | dtype='uchar'; % unsigned 8-bit 610 | elseif (BytesPerSample == 2), 611 | dtype='short'; % signed 16-bit 612 | elseif (BytesPerSample == 3) 613 | dtype='bit24'; % signed 24-bit 614 | elseif (BytesPerSample == 4), 615 | % 32-bit 16.8 float (type 1 - 32-bit) 616 | % 32-bit normalized floating point 617 | dtype = 'float'; 618 | % 32-bit 24.0 float (type 1 - 24-bit) 619 | if wavefmt.wFormatTag ~= 3 & wavefmt.nBitsPerSample == 24, 620 | BytesPerSample = 3; 621 | end 622 | else 623 | msg = 'Cannot read PCM file formats with more than 32 bits per sample.'; 624 | return 625 | end 626 | 627 | total_bytes = datack.Size; % # bytes in this chunk 628 | total_samples = total_bytes / BytesPerSample; 629 | SamplesPerChannel = total_samples / wavefmt.nChannels; 630 | if ~isempty(ext) & ext==-1, 631 | % Just return the samples per channel, and fseek past data: 632 | dat = SamplesPerChannel; 633 | 634 | % Add in a pad-byte, if required: 635 | total_bytes = total_bytes + rem(datack.Size,2); 636 | 637 | if(fseek(datack.fid,total_bytes,'cof')==-1), 638 | msg = 'Error reading PCM file format.'; 639 | end 640 | 641 | return 642 | end 643 | 644 | % Determine sample range to read: 645 | if isempty(ext), 646 | ext = [1 SamplesPerChannel]; % Return all samples 647 | else 648 | if prod(size(ext))~=2, 649 | msg = 'Sample limit vector must have 2 elements.'; 650 | return 651 | end 652 | if ext(1)<1 | ext(2)>SamplesPerChannel, 653 | msg = 'Sample limits out of range.'; 654 | return 655 | end 656 | if ext(1)>ext(2), 657 | msg = 'Sample limits must be given in ascending order.'; 658 | return 659 | end 660 | end 661 | 662 | bytes_remaining = total_bytes; % Preset byte counter 663 | 664 | % Skip over leading samples: 665 | if ext(1)>1, 666 | % Skip over leading samples, if specified: 667 | skipcnt = BytesPerSample * (ext(1)-1) * wavefmt.nChannels; 668 | if(fseek(datack.fid, skipcnt,'cof') == -1), 669 | msg = 'Error reading PCM file format.'; 670 | return 671 | end 672 | % 673 | % Update count of bytes remaining: 674 | bytes_remaining = bytes_remaining - skipcnt; 675 | end 676 | 677 | % Read desired data: 678 | nSPCext = ext(2)-ext(1)+1; % # samples per channel in extraction range 679 | dat = datack; % Copy input structure to output 680 | extSamples = wavefmt.nChannels*nSPCext; 681 | dat.Data = fread(datack.fid, [wavefmt.nChannels nSPCext], dtype); 682 | % 683 | % Update count of bytes remaining: 684 | skipcnt = BytesPerSample*nSPCext*wavefmt.nChannels; 685 | bytes_remaining = bytes_remaining - skipcnt; 686 | 687 | % if cnt~=extSamples, dat='Error reading file.'; return; end 688 | % Skip over trailing samples: 689 | if(fseek(datack.fid, BytesPerSample * ... 690 | (SamplesPerChannel-ext(2))*wavefmt.nChannels, 'cof')==-1), 691 | msg = 'Error reading PCM file format.'; 692 | return 693 | end 694 | % Update count of bytes remaining: 695 | skipcnt = BytesPerSample*(SamplesPerChannel-ext(2))*wavefmt.nChannels; 696 | bytes_remaining = bytes_remaining - skipcnt; 697 | 698 | % Determine if a pad-byte is appended to data chunk, 699 | % skipping over it if present: 700 | if rem(datack.Size,2), 701 | fseek(datack.fid, 1, 'cof'); 702 | end 703 | % Rearrange data into a matrix with one channel per column: 704 | dat.Data = dat.Data'; 705 | % Normalize data range: min will hit -1, max will not quite hit +1. 706 | if BytesPerSample==1, 707 | dat.Data = (dat.Data-128)/128; % [-1,1) 708 | elseif BytesPerSample==2, 709 | dat.Data = dat.Data/32768; % [-1,1) 710 | elseif BytesPerSample==3, 711 | dat.Data = dat.Data/(2^23); % [-1,1) 712 | elseif BytesPerSample==4, 713 | if wavefmt.wFormatTag ~= 3, % Type 3 32-bit is already normalized 714 | dat.Data = dat.Data/32768; % [-1,1) 715 | end 716 | end 717 | 718 | return 719 | 720 | % end of wavread.m -------------------------------------------------------------------------------- /wavexwrite.m: -------------------------------------------------------------------------------- 1 | function wavexwrite(y,Fs,nbits,wavefile,speakers) 2 | %WAVEXWRITE Write WAVE_FORMAT_EXTENSIBLE sound file. 3 | % WAVEXWRITE(Y,FS,NBITS,WAVEFILE, SPEAKERS) writes data Y to a WAVEX 4 | % file specified by the file name WAVEFILE, with a sample rate 5 | % of FS Hz and with NBITS number of bits. NBITS must be 8, 16, 6 | % 24, or 32. Stereo data should be specified as a matrix with two 7 | % columns. For NBITS < 32, amplitude values outside the range 8 | % [-1,+1] are clipped. 9 | % 10 | % SPEAKERS is a vector of speaker numbers 11 | % e.g. [1,2] for stereo 12 | % [1:5] for 5.1 13 | % [3] for center channel 14 | % 15 | % WAVEXWRITE(Y,FS,WAVEFILE) assumes NBITS=16 bits. 16 | % WAVEXWRITE(Y,WAVEFILE) assumes NBITS=16 bits and FS=44100 Hz. 17 | % 18 | % 8-, 16-, and 24-bit files are type 1 integer PCM. 32-bit files 19 | % are written as type 3 normalized floating point. 20 | % 21 | % Modified 2004/07/27 by Sylvain Choisel 22 | % to handle WAVE-FORMAT-EXTENSIBLE 23 | % email: sc@acoustics.aau.dk 24 | 25 | % Parse inputs: 26 | error(nargchk(2,5,nargin)); 27 | if nargin < 3, 28 | wavefile = Fs; 29 | Fs = 44100; 30 | nbits = 16; 31 | elseif nargin < 4, 32 | wavefile = nbits; 33 | nbits = 16; 34 | end 35 | 36 | % If input is a vector, force it to be a column: 37 | if ndims(y) > 2, 38 | error('Data array cannot be an N-D array.'); 39 | end 40 | if size(y,1)==1, 41 | y = y(:); 42 | end 43 | [samples, channels] = size(y); 44 | if nargin < 5, 45 | speakerMask=2^channels-1; 46 | else 47 | if (length(speakers)~=channels) 48 | error ('Speaker mask length must be equal to the number of channels'); 49 | end 50 | speakerMask=sum(2.^(speakers-1)); 51 | end 52 | 53 | % Determine number of bytes in chunks 54 | % (not including pad bytes, if needed): 55 | % ---------------------------------- 56 | % 'RIFF' 4 bytes 57 | % size 4 bytes (ulong) 58 | % 'WAVE' 4 bytes 59 | % 'fmt ' 4 bytes 60 | % size 4 bytes (ulong) 61 | % 14 bytes 62 | % 2 bytes (PCM) 63 | % 'data' 4 bytes 64 | % size 4 bytes (ulong) 65 | % N bytes 66 | % ---------------------------------- 67 | bytes_per_sample = ceil(nbits/8); 68 | total_samples = samples * channels; 69 | total_bytes = total_samples * bytes_per_sample; 70 | 71 | riff_cksize = 4+48+total_bytes; % Don't include 'RIFF' or its size field 72 | fmt_cksize = 40; % Don't include 'fmt ' or its size field 73 | data_cksize = total_bytes; % Don't include 'data' or its size field 74 | 75 | % Determine pad bytes: 76 | data_pad = rem(data_cksize,2); 77 | riff_cksize = riff_cksize + data_pad; % + fmt_pad, always 0 78 | 79 | % Open file for output: 80 | [fid,err] = OpenWaveWrite(wavefile); 81 | error(err); 82 | 83 | % Prepare basic chunk structure fields: 84 | ck=[]; ck.fid=fid; ck.filename = wavefile; 85 | 86 | % Write RIFF chunk: 87 | ck.ID = 'RIFF'; 88 | ck.Size = riff_cksize; 89 | error(write_ckinfo(ck)); 90 | 91 | % Write WAVE subchunk: 92 | ck.ID = 'WAVE'; 93 | ck.Size = []; % Indicate a subchunk (no chunk size) 94 | error(write_ckinfo(ck)); 95 | 96 | % Write : 97 | ck.ID = 'fmt '; 98 | ck.Size = fmt_cksize; 99 | error(write_ckinfo(ck)); 100 | 101 | % Write : 102 | fmt.filename = wavefile; 103 | fmt.wFormatTag = hex2dec('FFFE'); 104 | fmt.nChannels = channels; % Number of channels 105 | fmt.nSamplesPerSec = Fs; % Samples per second 106 | fmt.nAvgBytesPerSec = channels*bytes_per_sample*Fs; % Avg transfer rate 107 | fmt.nBlockAlign = channels*bytes_per_sample; % Block alignment 108 | fmt.nBitsPerSample = 8*bytes_per_sample; 109 | fmt.cbSize = 22; 110 | fmt.wValidBitsPerSample = nbits; 111 | fmt.dwSpkMask = speakerMask; 112 | fmt.subFormat = [1 0 0 0 0 0 16 0 8*16 0 0 hex2dec('AA') 0 hex2dec('38') hex2dec('9B') hex2dec('71')]; 113 | error(write_wavefmt(fid,fmt)); 114 | 115 | % Write : 116 | ck.ID = 'data'; 117 | ck.Size = data_cksize; 118 | error(write_ckinfo(ck)); 119 | 120 | % Write , and its pad byte if needed: 121 | error(write_wavedat(fid,fmt,y)); 122 | 123 | % Close file: 124 | fclose(fid); 125 | 126 | % end of wavwrite() 127 | 128 | 129 | % ------------------------------------------------------------------------ 130 | % Private functions: 131 | % ------------------------------------------------------------------------ 132 | 133 | 134 | % ------------------------------------------------------------------------ 135 | function [fid,err] = OpenWaveWrite(wavefile) 136 | % OpenWaveWrite 137 | % Open WAV file for writing. 138 | % If filename does not contain an extension, add ".wav" 139 | 140 | fid = []; 141 | err = ''; 142 | if ~isstr(wavefile), 143 | err='Wave file name must be a string.'; return; 144 | end 145 | 146 | % modified 27/07/2004 sc 147 | %if isempty(findstr(wavefile,'.')), 148 | % wavefile=[wavefile '.wav']; 149 | %end 150 | [pathstr,name,ext,versn]=fileparts(wavefile); 151 | if (~strcmp(lower(ext),'.wav')) 152 | wavefile=[wavefile '.wav']; 153 | end 154 | 155 | % Open file, little-endian: 156 | [fid,err] = fopen(wavefile,'wb','l'); 157 | 158 | return 159 | 160 | 161 | % ------------------------------------------------------------------------ 162 | function err = write_ckinfo(ck) 163 | % WRITE_CKINFO: Writes next RIFF chunk, but not the chunk data. 164 | % Assumes the following fields in ck: 165 | % .fid File ID to an open file 166 | % .ID 4-character string chunk identifier 167 | % .Size Size of chunk (empty if subchunk) 168 | % 169 | % 170 | % Expects an open FID pointing to first byte of chunk header, 171 | % and a chunk structure. 172 | % ck.fid, ck.ID, ck.Size, ck.Data 173 | 174 | errmsg = ['Failed to write ' ck.ID ' chunk to WAVE file: ' ck.filename]; 175 | err = ''; 176 | 177 | if (fwrite(ck.fid, ck.ID, 'char') ~= 4), 178 | err=errmsg; return; 179 | end 180 | 181 | if ~isempty(ck.Size), 182 | % Write chunk size: 183 | if (fwrite(ck.fid, ck.Size, 'ulong') ~= 1), 184 | err=errmsg; return; 185 | end 186 | end 187 | 188 | return 189 | 190 | % ------------------------------------------------------------------------ 191 | function err = write_wavefmt(fid, fmt) 192 | % WRITE_WAVEFMT: Write WAVE format chunk. 193 | % Assumes fid points to the wave-format subchunk. 194 | % Requires chunk structure to be passed, indicating 195 | % the length of the chunk. 196 | 197 | errmsg = ['Failed to write WAVE format chunk to file' fmt.filename]; 198 | err = ''; 199 | 200 | % Create data: 201 | if (fwrite(fid, fmt.wFormatTag, 'ushort') ~= 1) | ... 202 | (fwrite(fid, fmt.nChannels, 'ushort') ~= 1) | ... 203 | (fwrite(fid, fmt.nSamplesPerSec, 'ulong' ) ~= 1) | ... 204 | (fwrite(fid, fmt.nAvgBytesPerSec, 'ulong' ) ~= 1) | ... 205 | (fwrite(fid, fmt.nBlockAlign, 'ushort') ~= 1) | ... 206 | (fwrite(fid, fmt.nBitsPerSample, 'ushort') ~= 1) | ... 207 | (fwrite(fid, fmt.cbSize, 'ushort') ~= 1) | ... 208 | (fwrite(fid, fmt.wValidBitsPerSample, 'ushort') ~= 1) | ... 209 | (fwrite(fid, fmt.dwSpkMask, 'ulong' ) ~= 1) | ... 210 | (fwrite(fid, fmt.subFormat, 'uchar' ) ~= 16) 211 | err=errmsg; 212 | end 213 | 214 | return 215 | 216 | 217 | % ----------------------------------------------------------------------- 218 | function y = PCM_Quantize(x, fmt) 219 | % PCM_Quantize: 220 | % Scale and quantize input data, from [-1, +1] range to 221 | % either an 8-, 16-, or 24-bit data range. 222 | 223 | % Clip data to normalized range [-1,+1]: 224 | ClipMsg = ['Data clipped during write to file:' fmt.filename]; 225 | ClipWarn = 0; 226 | 227 | % Determine slope (m) and bias (b) for data scaling: 228 | nbits = fmt.nBitsPerSample; 229 | m = 2.^(nbits-1); 230 | 231 | switch nbits 232 | case 8, 233 | b=128; 234 | case {16,24}, 235 | b=0; 236 | otherwise, 237 | error('Invalid number of bits specified.'); 238 | end 239 | 240 | y = round(m .* x + b); 241 | 242 | % Determine quantized data limits, based on the 243 | % presumed input data limits of [-1, +1]: 244 | ylim = [-1 +1]; 245 | qlim = m * ylim + b; 246 | qlim(2) = qlim(2)-1; 247 | 248 | % Clip data to quantizer limits: 249 | i = find(y < qlim(1)); 250 | if ~isempty(i), 251 | warning(ClipMsg); ClipWarn=1; 252 | y(i) = qlim(1); 253 | end 254 | 255 | i = find(y > qlim(2)); 256 | if ~isempty(i), 257 | if ~ClipWarn, warning(ClipMsg); end 258 | y(i) = qlim(2); 259 | end 260 | 261 | return 262 | 263 | 264 | % ----------------------------------------------------------------------- 265 | function err = write_wavedat(fid,fmt,data) 266 | % WRITE_WAVEDAT: Write WAVE data chunk 267 | % Assumes fid points to the wave-data chunk 268 | % Requires structure to be passed. 269 | 270 | err = ''; 271 | 272 | if fmt.wFormatTag==1 | fmt.wFormatTag==3 | fmt.wFormatTag==hex2dec('FFFE'), 273 | % PCM Format 274 | 275 | % 32-bit Type 3 is normalized, so no scaling needed. 276 | if fmt.nBitsPerSample ~= 32, 277 | data = PCM_Quantize(data, fmt); 278 | end 279 | 280 | switch fmt.nBitsPerSample 281 | case 8, 282 | dtype='uchar'; % unsigned 8-bit 283 | case 16, 284 | dtype='short'; % signed 16-bit 285 | case 24, 286 | dtype='bit24'; % signed 24-bit 287 | case 32, 288 | dtype='float'; % normalized 32-bit floating point 289 | otherwise, 290 | err = 'Invalid number of bits specified.'; return; 291 | end 292 | 293 | % Write data, one row at a time (one sample from each channel): 294 | [samples,channels] = size(data); 295 | total_samples = samples*channels; 296 | 297 | if (fwrite(fid, reshape(data',total_samples,1), dtype) ~= total_samples), 298 | err = 'Failed to write PCM data samples.'; return; 299 | end 300 | 301 | % Determine # bytes/sample - format requires rounding 302 | % to next integer number of bytes: 303 | BytesPerSample = ceil(fmt.nBitsPerSample/8); 304 | 305 | % Determine if a pad-byte must be appended to data chunk: 306 | if rem(total_samples*BytesPerSample, 2) ~= 0, 307 | fwrite(fid,0,'uchar'); 308 | end 309 | 310 | else 311 | % Unknown wave-format for data. 312 | err = 'Unsupported data format.'; 313 | end 314 | 315 | return 316 | 317 | % end of wavwrite.m --------------------------------------------------------------------------------