├── Code ├── 1 ├── Fxlms_v1.m ├── Mul_Fxlms.m ├── Test_Fxlms_Bd.m ├── ANC_Nb.m └── pinknoise.m ├── PNGS └── WINWORD_BUO8dqD7fx.png ├── README.md └── LICENSE /Code/1: -------------------------------------------------------------------------------- 1 | # THIS IS NEW FILE 2 | -------------------------------------------------------------------------------- /Code/Fxlms_v1.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/875441459/Basic-demonstraion-of-Fxlms-Algo/HEAD/Code/Fxlms_v1.m -------------------------------------------------------------------------------- /Code/Mul_Fxlms.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/875441459/Basic-demonstraion-of-Fxlms-Algo/HEAD/Code/Mul_Fxlms.m -------------------------------------------------------------------------------- /Code/Test_Fxlms_Bd.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/875441459/Basic-demonstraion-of-Fxlms-Algo/HEAD/Code/Test_Fxlms_Bd.m -------------------------------------------------------------------------------- /PNGS/WINWORD_BUO8dqD7fx.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/875441459/Basic-demonstraion-of-Fxlms-Algo/HEAD/PNGS/WINWORD_BUO8dqD7fx.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Basic-Demonstraion-of-Fxlms-Algo 2 | Containing the basic Fxlms Algo for Broadband and narrowband active noise control(ANC) 3 | 4 | # System Diagram 5 | ![System Diagram](https://github.com/875441459/Basic-demonstraion-of-Fxlms-Algo/blob/master/PNGS/WINWORD_BUO8dqD7fx.png) 6 | 7 | # Broadband ANC 8 | + **Single-channel Fxlms Algo**(Basic Fxlms, 1 reference microphone, 1 secondary source and 1 error microphone) 9 | + [test_demo](https://github.com/875441459/Basic-demonstraion-of-Fxlms-Algo/blob/master/Code/Test_Fxlms_Bd.m) 10 | + **Multi-channel Fxlms Algo**(I reference microphone(I=1 here),J secondary source(actuator/loudspeaker) and K error microphone) 11 | + [test_demo](https://github.com/875441459/Basic-demonstraion-of-Fxlms-Algo/blob/master/Code/Mul_Fxlms.m) 12 | 13 | # Narrowband ANC 14 | + **Single pure tone noise control** 15 | + [test_demo](https://github.com/875441459/Basic-demonstraion-of-Fxlms-Algo/blob/master/Code/ANC_Nb.m) 16 | 17 | # Thanks 18 | 1. Hristo Zhivomirov [Pinknoise generator](https://www.mathworks.com/matlabcentral/fileexchange/42919-pink-red-blue-and-violet-noise-generation-with-matlab) 19 | 20 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Jeff WANG 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Code/ANC_Nb.m: -------------------------------------------------------------------------------- 1 | %% narrowband noise cancellation 2 | clear;close all;clc 3 | dotnumber=3e3; 4 | fs=8e3;%%sampling rate 5 | f_u=400;%%reference signal's frequency 6 | f_d=410;%%desired signal's frequency 7 | w_u=2*pi*f_u/fs;%%reference signal's digital omega 8 | w_d=2*pi*f_d/fs;%%reference signal's digital omega 9 | u=exp(1j*w_u*(0:dotnumber)); 10 | % u1=cos(w_u*(0:dotnumber)); 11 | % d=cos(w_d*(0:dotnumber)); 12 | d=sin(w_d*(0:dotnumber)); 13 | e=zeros(dotnumber,1); 14 | W=zeros(dotnumber,1); 15 | miu=1e-2; 16 | len_S=3;%%delay time =len_S-1 17 | S=zeros(len_S,1); 18 | S(len_S)=1; 19 | num_fft=1000; 20 | delta_w=2*pi/num_fft; 21 | idx_w0=floor(w_u/delta_w+1); 22 | SW=freqz(S,1,num_fft); 23 | freqz(S,1,num_fft) 24 | S_w0=SW(idx_w0); 25 | y=zeros(len_S,1); 26 | for n=1:dotnumber 27 | y1=real(W(n)*u(n)); 28 | % y1=(W(n)*u(n)); 29 | % y1=W(n)*u1(n); 30 | y=[y1;y(1:end-1)]; 31 | e(n)=d(n)+S'*y; 32 | W(n+1)=W(n)-miu*e(n)*conj(S_w0)*exp(-1j*n*2*pi*f_u/fs); 33 | end 34 | figure 35 | subplot 211 36 | plot(abs(e).^2) 37 | Grid_set 38 | ylabel('MSE','Interpreter','latex','FontSize',12); 39 | axis tight 40 | subplot 212 41 | plot(abs(W)) 42 | Grid_set 43 | xlabel('iteration','Interpreter','latex','FontSize',12); 44 | ylabel('$\|W\|$','Interpreter','latex','FontSize',12); 45 | axis tight -------------------------------------------------------------------------------- /Code/pinknoise.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % Pink Noise Generation with MATLAB Implementation % 3 | % % 4 | % Author: M.Sc. Eng. Hristo Zhivomirov 07/30/13 % 5 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 6 | 7 | function y = pinknoise(m, n) 8 | 9 | % function: y = pinknoise(m, n) 10 | % m - number of matrix rows 11 | % n - number of matrix columns 12 | % y - matrix with pink (flicker) noise samples 13 | % with mu = 0 and sigma = 1 (columnwise) 14 | 15 | % The function generates a matrix of pink (flicker) noise samples 16 | % (columnwise). In terms of power at a constant bandwidth, pink 17 | % noise falls off at 3 dB/oct, i.e. 10 dB/dec. 18 | 19 | % difine the length of the noise vector and ensure 20 | % that M is even, this will simplify the processing 21 | m = round(m); n = round(n); N = m*n; 22 | if rem(N, 2) 23 | M = N+1; 24 | else 25 | M = N; 26 | end 27 | 28 | % generate white noise sequence 29 | x = randn(1, M); 30 | 31 | % FFT 32 | X = fft(x); 33 | 34 | % prepare a vector with frequency indexes 35 | NumUniquePts = M/2 + 1; % number of the unique fft points 36 | k = 1:NumUniquePts; % vector with frequency indexes 37 | 38 | % manipulate the left half of the spectrum so the PSD 39 | % is proportional to the frequency by a factor of 1/f, 40 | % i.e. the amplitudes are proportional to 1/sqrt(f) 41 | X = X(1:NumUniquePts); 42 | X = X./sqrt(k); 43 | 44 | % prepare the right half of the spectrum - a conjugate copy of the left 45 | % one except the DC component and the Nyquist component - they are unique, 46 | % and reconstruct the whole spectrum 47 | X = [X conj(X(end-1:-1:2))]; 48 | 49 | % IFFT 50 | y = real(ifft(X)); 51 | 52 | % ensure that the length of y is N 53 | y = y(1, 1:N); 54 | 55 | % form the noise matrix and ensure unity standard 56 | % deviation and zero mean value (columnwise) 57 | y = reshape(y, [m, n]); 58 | y = bsxfun(@minus, y, mean(y)); 59 | y = bsxfun(@rdivide, y, std(y)); 60 | 61 | end --------------------------------------------------------------------------------