Lowpass doesn't work as expected
2 views (last 30 days)
Show older comments
Hi, I try to filter my signal- in the blue color using lowpass filter and after filtering it I get the orange one which is clearly not what I wanted. Do you have any Idea why?

The code:
Fs = 120e9; % Sampling frequency
T = 1/Fs; % Sampling period
L = 2^20; % Length of signal
t = (0:(L-1))*T; % Time vector
f = Fs*(0:(L/2))/L; % Frequency vector
A = 1; % coeficient of the sin(w*t)
omega=2*pi*1.144409179687500e+09; % ~1GHz frequency
phaseNoise=0.001*ones(1,length(t)); %pure constant phase noise
sine_signal_with_PN=sin(omega*t+phaseNoise); %signal with PN
signal_with_PN=cos(omega*t+phaseNoise); %shifted signal with PN
NF=sin(omega*t+phaseNoise)-A*sin(omega*t); %the notch filter
y=signal_with_PN.*NF; %the signal after processing
%creating the lowpass filter
lpFilt = designfilt('lowpassfir','PassbandFrequency',0.005, ... %2*f/Fs=NormFreq
'StopbandFrequency',0.01,'PassbandRipple',0.5, ...
'StopbandAttenuation',100,'DesignMethod','kaiserwin');
yBeforeLpf=2*y/A;
PN_after_LPF =filter(lpFilt,yBeforeLpf);
filteredPN=filter(lpFilt,phaseNoise);
%% Graph of signal before LPF
figure();
y_ft=db(fft(yBeforeLpf));%db
plot(f,y_ft(1:(L/2+1)));
hold on;
PN_FT=db(fft(PN_after_LPF));%db
plot(f,PN_FT(1:(L/2+1)));
xlabel('f[Hz]');
xlim([0 3e9]);
ylabel('|Y^F|[dB]');
grid minor;
title('FFT Of Signal After Scheme With PN Before LPF');
0 Comments
Answers (1)
Mathieu NOE
on 19 Oct 2020
hi
modofied a bit your code - I did not use designfilt but otherwise your code seems to work
just replaced your FIR filter with a more traditionnal butterworth IIR filter
clc
Fs = 120e9; % Sampling frequency
T = 1/Fs; % Sampling period
L = 2^20; % Length of signal
t = (0:(L-1))*T; % Time vector
f = Fs*(0:(L/2))/L; % Frequency vector
A = 1; % coeficient of the sin(w*t)
omega=2*pi*1.144409179687500e+09; % ~1GHz frequency
phaseNoise=0.001*ones(1,length(t)); %pure constant phase noise
sine_signal_with_PN=sin(omega*t+phaseNoise); %signal with PN
signal_with_PN=cos(omega*t+phaseNoise); %shifted signal with PN
NF=sin(omega*t+phaseNoise)-A*sin(omega*t); %the notch filter
y=signal_with_PN.*NF; %the signal after processing
%creating the lowpass filter
% lpFilt = designfilt('lowpassfir','PassbandFrequency',0.005, ... %2*f/Fs=NormFreq
% 'StopbandFrequency',0.01,'PassbandRipple',0.5, ...
% 'StopbandAttenuation',100,'DesignMethod','kaiserwin');
[BlpFilt,AlpFilt] = BUTTER(2,1e-4);
yBeforeLpf=2*y/A;
% PN_after_LPF =filter(lpFilt,yBeforeLpf);
PN_after_LPF =filter(BlpFilt,AlpFilt,yBeforeLpf);
% filteredPN=filter(lpFilt,phaseNoise);
filteredPN=filter(BlpFilt,AlpFilt,phaseNoise);
% %% Graph of signal before LPF
% figure(1);
% y_ft=20*log10(abs(fft(yBeforeLpf)));%db
% plot(f,y_ft(1:(L/2+1)));
% hold on;
% PN_FT=20*log10(abs(fft(PN_after_LPF)));%db
% plot(f,PN_FT(1:(L/2+1)));
% xlabel('f[Hz]');
% xlim([0 3e9]);
% ylabel('|Y^F|[dB]');
% grid minor;
% title('FFT Of Signal After Scheme With PN Before LPF');
%% Graph of signal before LPF
figure(1);
y_ft=20*log10(abs(fft(yBeforeLpf)));%db
PN_FT=20*log10(abs(fft(PN_after_LPF)));%db
semilogx(f,y_ft(1:(L/2+1)),'b',f,PN_FT(1:(L/2+1)),'r');
xlabel('f[Hz]');
xlim([0 3e9]);
ylabel('|Y^F|[dB]');
grid minor;
title('FFT Of Signal After Scheme With PN Before LPF');
2 Comments
Mathieu NOE
on 19 Oct 2020
OK
II changed quite a bit your code , instead of doing one fft on the entire length of the signal, I have done a periodogram using pwelch function. The results look to me better
you may have to play with NFFT
clc
% Fs = 120e9; % Sampling frequency
Fs = 120e9; % Sampling frequency
T = 1/Fs; % Sampling period
L = 2^20; % Length of signal
t = (0:(L-1))*T; % Time vector
f = Fs*(0:(L/2))/L; % Frequency vector
A = 1; % coeficient of the sin(w*t)
omega=2*pi*1.144409179687500e+09; % ~1GHz frequency
phaseNoise=0.001*ones(1,length(t)); %pure constant phase noise
sine_signal_with_PN=sin(omega*t+phaseNoise); %signal with PN
signal_with_PN=cos(omega*t+phaseNoise); %shifted signal with PN
NF=sin(omega*t+phaseNoise)-A*sin(omega*t); %the notch filter
y=signal_with_PN.*NF; %the signal after processing
%creating the lowpass filter
% lpFilt = designfilt('lowpassfir','PassbandFrequency',0.005, ... %2*f/Fs=NormFreq
% 'StopbandFrequency',0.01,'PassbandRipple',0.5, ...
% 'StopbandAttenuation',100,'DesignMethod','kaiserwin');
[BlpFilt,AlpFilt] = BUTTER(2,1e-4);
yBeforeLpf=2*y/A;
PN_after_LPF =filter(BlpFilt,AlpFilt,yBeforeLpf);
%% Graph of signal before LPF
NFFT = 1024*2; % to have highest frequency resolution
NOVERLAP = round(0.75*NFFT);
[y_ft, freq]=pwelch(yBeforeLpf,hamming(NFFT),NOVERLAP,NFFT,Fs);
[PN_FT, freq]=pwelch(PN_after_LPF,hamming(NFFT),NOVERLAP,NFFT,Fs);
figure(1);
semilogx(freq,20*log10(y_ft),'-+b',freq,20*log10(PN_FT),'-+r');
xlabel('f[Hz]');
xlim([0 3e9]);
ylabel('|Y^F|[dB]');
grid minor;
title('FFT Of Signal After Scheme With PN Before LPF');

See Also
Categories
Find more on Multirate Signal Processing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!