i wrote the code for this but it is for known frequency interference cancellation.
%% step 1 proj adsp
clear;
clc
close all;
N=2000;
Fs=1000;
Length=Fs*10;
f_signal=20/Fs;
x=sin(2*pi*20/Fs*(1:N));
%plot (x)
f1=50;%freq of noise signal in Hz
i=1:length(x);
Noise_signal = sin(2*pi*f1*i/Fs); % Power Line Interference
n=Noise_signal;
% Range of the Noise Signal embedded in the signal x
Mixed = x+ Noise_signal; % received Signal with periodic Noise
%%%%%%%%%%%%%%%% POWER LINE INTERFERENCE %%%%%%%%%%%%%%%
%% LMS algo for adaptive filtering
m=Mixed;
d=x+n+m;
n1=rand()*Noise_signal;% harmonic noise with some unknown amplitude
FilterTap=16;
w=ones(FilterTap,1);% no of taps of estiamted filter
mu=0.05; % Lest Mean Square (LMS) step size.
for i=1:length(x)
if i<FilterTap
u=[n1(i:-1:1) ,zeros(1,FilterTap-i)]';
else
u=[n1(i:-1:i-(FilterTap-1))]';
end
y(i)=w'*u;
e(i)=d(i)-y(i);
w=w+mu*u*e(i);
if (sum(w)<=10^-9)
break
end
end
d_ref=conv(w,x);
plot(e)
figure(2)
plot(x)
figure(3)
plot(m)
Output_without_Noise_signal=e;
M=100;
fc=0.25;
for i=1:M
h(i)=sin(2*pi*fc*(i-M/2))*(0.42- 0.5*cos(2*pi*i/M) + 0.08*cos(4*pi/M) )/(i-M/2);
end
h(ceil(M/2))=2*pi*fc;
h=h/sum(h);
Final_filter_Output=filter(h,1,Output_without_Noise_signal);
figure(4),plot(Final_filter_Output)
plot(abs(fft (Final_filter_Output)))
figure(5)
plot(abs(fft(m)))
chech this all of you. here final_filter_output has just changed amplitude. mean amplitude detection is somewhat false. all idea are welcomed.