# Using Lowpass filter to filter DC component from BPSK signal

Status
Not open for further replies.

##### Newbie level 6
Hi guys!
I have a code matlab for BPSK demodulation. And I have problem with filtering DC component from BPSK signal. My process is
BPSK_sig*carrier=1/2*(1+cos(2wt)) and I want to use LPF to get DC component which recover to original signal

What should I do? Thanks alot!
And here is my matlab code
Code:
%MATLAB Script for a Binary PSK with two Phases

% Clear all variables and close all figures
clear all;
close all;

bit_stream = [1,0,1,0,1,0,1,0];

% Enter the two Phase shifts - in Radians
% Phase for 0 bit
P1 = 0;

% Phase for 1 bit
P2 = pi;

% Frequency of Modulating Signal
f = 2; %f --> time period

% Sampling rate of sine wave - This will define the resoultion
fs = 100;

% Time for one bit
t = 0: 1/fs : 1;

% This time variable is just for plot
time = [];

PSK_signal = [];
Digital_signal = [];
carrier_signal = [];

for ii = 1: 1: length(bit_stream)

% The Original Digital Signal
if bit_stream(ii)==0
bit0 = zeros(1,length(t));
Digital_signal = [Digital_signal bit0];
end

if bit_stream(ii)==1
bit1 = ones(1,length(t));
Digital_signal = [Digital_signal bit1];
end

% The FSK Signal
if bit_stream(ii)==0
PSK_signal = [PSK_signal cos(2*pi*f*t + P2)];
end
if bit_stream(ii)==1
PSK_signal = [PSK_signal cos(2*pi*f*t + P1)];
end

% Generating carrier wave
carrier_signal = [carrier_signal (cos(2*pi*f*t))];

time = [time t];
t = t + 1;

end

% Plot the Original Digital Signal
subplot(4,1,1);
plot(time,Digital_signal,'r','LineWidth',2);
xlabel('Time (bit period)');
ylabel('Amplitude');
title('Original Digital Signal');
axis([0 time(end) -0.5 1.5]);
grid on;

% Plot the carrier Signal
subplot(4,1,2);
plot(time,carrier_signal,'g','LineWidth',2);
xlabel('Time (bit period)');
ylabel('Amplitude');
title('carrier Signal');
axis([0 time(end) -1.5 1.5]);
grid on;

% Plot the PSK Signal
subplot(4,1,3);
plot(time,PSK_signal,'LineWidth',2);
xlabel('Time (bit period)');
ylabel('Amplitude');
title('PSK Signal with two Phase Shifts');
axis([0 time(end) -1.5 1.5]);
grid on;

% Plot the Demodulation BPSK Signal
de_PSK_signal=PSK_signal.*carrier_signal;
subplot(4,1,4);
plot(time,de_PSK_signal,'LineWidth',2);
xlabel('Time (bit period)');
ylabel('Amplitude');
title('Demodulation BPSK Signal');
axis([0 time(end) -1.5 1.5]);
grid on;

I love the output of your code - it looks really neat If you've got the signal processing toolbox handy, you can use:

Code Python - [expand]1
Hd = design(fdesign.lowpass('N,Fc', 40, f, fs));

...which builds an FIR lowpass filter with 40 taps with a corner frequency f (your signalling rate) at sampling rate fs.
You can view the resultant filter with:

Code Python - [expand]1
fvtool(Hd)

...and apply it to your data (and plot it) via:

Code Python - [expand]1
subplot(4,1,4); plot(time, filtfilt(Hd.Numerator, 1, de_PSK_signal),'LineWidth',2);

Note that I've used filtfilt(..), which is a non-causal zero-phase filter, which makes everything line up and look nice in time domain plots such as yours. Compare the result with a (causal) filter implementation such as:

Code Python - [expand]1
subplot(4,1,4); plot(time, filter(Hd, de_PSK_signal),'LineWidth',2);

Cheers • Points: 2
Thanks you very much! Could you please tell me the meaning of N, FC, 40. Why do you choose 40? I tried some other numbers and still get the result. One more question: How could I recover the original signal from LPF signal because original signal is square wave

The syntax "N, Fc" tells MATLAB you're going to specify the filter by the number of taps and it's corner frequency. (There's a multitude of ways you can specify a filter response, and this is one of the simplest).

N is the number of taps comprising your FIR filter. The greater the number of taps, the more "ideal" the filter response - i.e. the more closely it approaches a low-pass brick wall. Generally, the more the better, although the practical constraints are the corresponding increases in the required computation and delay through the filter. I chose 40, because execution time/causality wasn't important... and the result looked pretty Fc is the corner frequency of the lowpass response - i.e. the frequency corresponding to the -3dB point of the amplitude rolloff. You want this point to be high enough to pass your modulated data, but low enough to reject your carrier frequency component - it's often a tradeoff. (The number of taps of the filter also plays a part here - both decreasing Fc and/or increasing N will reduce the residual carrier ripple, with their own unique performance consequences/penalties).

To recover the input square wave you need to threshold the filtered data, or use some sort of majority voting system etc etc. Optimal data recovery is a whole field in itself, but simple thresholding will work well here - something along the lines of:

if (filteredValue > threshold)
dataOut = 1;
else
dataOut = 0;
end

• Points: 2