Prev: Compile uitabpanel GUI
Next: Solving eigenvalues
From: Arrate Alonso on 7 Nov 2007 06:35 Dear Mr Teyhan, I'm a student and I'm currently working on something very similar to your code of the post. How did you solve the problem? Thanks "kevin teyhan" <kevinteyhan(a)hotmail.com> wrote in message <f78fsa$33e$1(a)fred.mathworks.com>... > Dear All, > > I have been reading the post of Adaptive Filtering Demos posted by Ricardo Losada in the Signal Processing File exchange section of this site. > Please excuse my ignorance of Matlab language structure, but I was wondering if anyone could show how and where to substitute the randomly generated noise for a .wav file of noise I have. > I would be interested to see how the algorithm performs under varying types of noise files, but unsure which sections of code I can remove and substitute in my .wav file. > Below is the algorithm as posted by Ricardo Losada (although I believe originated by Scott Douglas). > > >>>>>>>>>>>>>>>>>>>>>>>>> > %The Secondary Propagation Path > Fs = 8000; > N = 800; > delayS = 7; > Fd = fdesign.bandpass('N,Fst1,Fst2,Ast',8,0.04,0.5,20); > Hd = design(Fd,'cheby2','FilterStructure','df2tsos'); > H = filter(Hd,[zeros(1,delayS) log(0.99*rand(1,N-delayS) +0.01).* ... > sign(randn(1,N-delayS)).*exp(-0.01*(1:N-delayS))]); > H = H/norm(H); > t = 1/Fs:1/Fs:N/Fs; > plot(t,H,'b'); > xlabel('Time [sec]'); > ylabel('Coefficient value'); > title('True Secondary Path Impulse Response'); > > %% Estimating the Secondary Propagation Path > ntrS = 30000; > s = randn(1,ntrS); > dS = filter(H,1,s) + 0.01*randn(1,ntrS); > > %% Designing the Secondary Propagation Path Estimate > M = 250; > muS = 0.1; offsetS = 0.1; > h = adaptfilt.nlms(M,muS,1,offsetS); > [yS,eS] = filter(h,s,dS); > > n = 1:ntrS; > plot(n,dS,n,yS,n,eS); > > > xlabel('Number of iterations'); > ylabel('Signal value'); > title('Secondary Identification Using the NLMS Adaptive Filter'); > legend('Desired Signal','Output Signal','Error Signal'); > > > %% Accuracy of the Secondary Path Estimate > Hhat = h.Coefficients; > plot(t,H,t(1:M),Hhat,t,[H(1:M)-Hhat(1:M) H(M+1:N)]); > xlabel('Time [sec]'); > ylabel('Coefficient value'); > title('Secondary Path Impulse Response Estimation'); > legend('True','Estimated','Error'); > > > %% The Primary Propagation Path > delayW = 15; > Fd2 = fdesign.bandpass('N,Fst1,Fst2,Ast',10,0.05,0.2,20); > Hd2 = design(Fd2,'cheby2','FilterStructure','df2tsos'); > G = filter(Hd2,[zeros(1,delayW) log(0.99*rand(1,N-delayW) +0.01).*... > sign(randn(1,N-delayW)).*exp(-0.01*(1:N-delayW))]); > G = G/norm(G); > plot(t,G,'b'); > xlabel('Time [sec]'); > ylabel('Coefficient value'); > title('Primary Path Impulse Response'); > > > %% The Noise to be Cancelled > ntrW = 60000; > F0 = 60; > n = 1:ntrW; > A = [0.01 0.01 0.02 0.2 0.3 0.4 0.3 0.2 0.1 0.07 0.02 0.01]; > x = zeros(1,ntrW); > for k=1:length(A); > x = x + A(k)*sin(2*pi*(F0*k/Fs*n+rand(1))); > end > d = filter(G,1,x) + 0.1*randn(1,ntrW); > Hp = spectrum.welch; Hp.SegmentLength = 4444; > Hp.FFTLength='UserDefined'; > Pd = psd(Hp,d(ntrW-20000:ntrW),'NFFT',8192,'Fs',Fs); > plot(Pd) > axis([0 2 -70 0]); > title('Power Spectral Density of the Noise to be Cancelled'); > p8K = audioplayer(d/max(abs(d)),Fs); > playblocking(p8K); > > > %% Active Noise Control using the filtered-X LMS Algorithm > xhat = x + 0.1*randn(1,ntrW); > L = 350; > muW = 0.0001; > h = adaptfilt.filtxlms(L,muW,1,Hhat); > [y,e] = filter(h,xhat,d); > > plot(n,d,'b',n,y,'g',n,e,'r'); > xlabel('Number of iterations'); > ylabel('Signal value'); > tstr = ['Active Noise Control Using', ... > ' the Filtered-X LMS Adaptive Controller']; > title(tstr); > legend('Original Noise','Anti-Noise','Residual Noise'); > p8K = audioplayer(e/max(abs(e)),Fs); > playblocking(p8K); > > %% Residual Error Signal Spectrum > Pe = psd(Hp,e(ntrW-20000:ntrW),'NFFT',8192,'Fs',Fs); > plot(Pd.Frequencies,10*log10(Pd.Data(:,1)),'b',... > Pe.Frequencies,10*log10(Pe.Data(:,1)),'r'); > axis([0 2000 -70 0]); > grid on > xlabel('Frequency (Hz)'); > ylabel('Power/frequency (dB/Hz)'); > tstr = ['Power Spectral Density of the', ... > ' Original and Attenuated Noise']; > title(tstr); > legend('Original','Attenuated'); > > > Any help would be greatly appreciated and please accept my apologies for my lack of understanding! > > Thanks in advance > > Regards, > > Kevin. > > >
|
Pages: 1 Prev: Compile uitabpanel GUI Next: Solving eigenvalues |