% M01-intro-demo.diary % Matlab examples from lecture 1 % 2007-09-04 % Inverse filtering demo % Read in the stereo recording [d,sr] = wavread('recording.wav'); % first channel is what was sent to speakers X = d(:,1); % second channel is as recorded from microphone Y = d(:,2); % Compare the sound soundsc(X,sr) soundsc(Y,sr) % Look at waveforms plot([1:length(X)]/sr,X,[1:length(Y)]/sr,Y) % Can see delay, distortion % Calculate whitened cross-correlation, approximates cross-coupling [Xw,Hw] = whiten(X,40); L = 4000; Hxy = xcorr(Xw,filter(Hw,1,Y), L); % Have a look plot([-L:L]/sr, Hxy) % Can see discrete echoes (?) % Try to design inverse filter [HxyW, IHxy] = whiten(Hxy, 40); % Recovered version of X Xr = filter(IHxy, 1, Y); % It's based on Y, but it sounds more like X... soundsc(Xr,sr) % Time dilation example [d,sr] = wavread('mpgr1_sx419.wav'); soundsc(d,sr) % Slow down sampling rate soundsc(d,sr*.7) % Slow down with SOLAFS dd = solafs(d',0.7,300,100); soundsc(dd,sr) % Speed up du = solafs(d',1.5,300,100); soundsc(du,sr) % Look at the waveforms plot(d) % Zoom in on the first part plot(d(1:5000)) plot(d(2000+[1:5000])) % Compare with time-dilated version subplot(211) plot(d(2000+[1:5000])) subplot(212) plot(dd(2000+[1:5000])) % Compare spectrograms subplot(211) specgram(d,256,sr); subplot(212) specgram(dd,256,sr); % spectrograms with same duration - extend shorter d(length(dd)) = 0; subplot(211) specgram(d,256,sr); % fix autoscaling of color axis (to low dB floor) caxis([-70 10]); % -70 dB to 10 dB % match in second specgram subplot(212) caxis([-70 10]); % Visualizing complex sequences x = 10*exp((-1/12 + j*pi/6)*[0:39]); x subplot(211) plot(real(x)) stem(real(x)) subplot(212) stem(imag(x)) % Plot as 3-D subplot(111) stemz(x) axis equal % Add projections for real and imag stemz([0:39],x,1) axis equal % Aperiodic sinusoidal sequence stem([0:40],sin([0:40]*2*pi/(22/3))) % superimpose `smooth' sinusoid for comparison hold on; plot([0:.1:40],sin([0:.1:40]*2*pi/(22/3)),'r'); hold off grid % Aliased sinusoids - cross at sampling instants xx = 0:0.01:10; plot(xx,sin(2*pi*xx*1.2),'r',xx,sin(2*pi*xx*0.2),'g'); % superimpose the discrete samples (same for both freqs) hold on; stem(0:10,sin([0:10]*2*pi*0.2)); hold off