# Matched Filter BER vs SNR curve does not match the theoretical curve [closed]

I am creating a matched filter using filter command. The coefficients are also generated in another file using sigma delta modulator these are ternary coefficients (+1,-1,0). I have generated 1 and 0 with equal probability, mapped the bits with a rectangular pulse then added noise and used filter command to filter the received signal with ternary coefficients. After retrieving of the bits when I try to calculate the bit error, the plot comes out to be flat, it does not resemble the theoretical curve and the error rate gives strange values. I'll really appreciate it if someone helps me, please.

The Pb values does not seem to be right. There is not much difference that is why the plot is flat

## closed as unclear what you're asking by MBaz, Laurent Duval, jojek♦Jan 16 '17 at 13:19

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

• @MBaz I wanted the coefficients to not just be binary but ternary. So to do that I used firpm and got the target coefficients to be made ternary. To oversample I used interpolation. The interpolated output is fed into sigma delta modulator which uses ternary quantizer. This code works fine as output (variable v which uses ternary quantizer) I get is +1, -1, 0. – Abeer Jan 5 '17 at 7:12
• @MBaz My actual problem is in the other code that when I plot Pe vs SNR, it does not show much difference which I have added now at the end of the question, please check it. I'll try to add block diagram as well. – Abeer Jan 5 '17 at 7:25
• We cannot run the code, at least the function TernaryQuantizer is missing. However, looking at your curve: You have 50% Bit error. This amounts to completely random output, which is independent of the input. I suggest you debug your problem first with infinite snr (i.e. noise=0). In this case, your receiver should create the correct output sequence. I suppose, it currently does not. – Maximilian Matthé Jan 5 '17 at 7:48
• @MaximilianMatthé Thank you for your suggestion. and yes sorry I forgot to provide the ternary quantizer function. Should I remove the noise first? – Abeer Jan 5 '17 at 7:55

I dont know, if this is exactly what you wanted to do, but here's a script that creates your theoretic curve. I used your mirrored coefficients as the transmit pulse, and the coefficients as the filter coefficients. This way, the pair becomes a matched filter pair.

N=10^4;        %No: of bits
A=10;          %amplitude of S(t)
T=length(v);          %duration of S(t)
S=fliplr(v)*A;       %the transmit pulse
E=norm(S)^2;         %S(t) Energy
input = rand(1,N)>0.5;   % generating 0,1 with equal probability
bits=(2*input-1);      %mapping the bits with S(t)
x=kron(bits,S);

SNR_db=0:0.25:10;
n_var=(E/2)*10.^(-SNR_db/10);

%Noise that gives SNR=0dB to SNR=7dB

for i = 1:length(n_var)

n=randn(1,length(x))*sqrt(n_var(i));   %noise

%v=ternary coefficients, filtering the received signal and coefficients
filtered=filter(v,1,r);

%sampling at T & using thresholding operation
z=sign(filtered);
z=(z(T:T:end));

%recovering the sent bits

%calculating the bit error

end

%Plotting Pb Vs SNR
figure(1);
SNR=10.^(SNR_db/10);
P_theory=(0.5)*erfc(sqrt(2.*SNR)./sqrt(2));
semilogy(SNR_db,Pb,'o',SNR_db,P_theory,'r-')
title ('SNR Vs Probabolity of Error');
xlabel ('SNR (dB)');
ylabel ('Probability of Error');
legend('practical curve','theoratical curve');
grid on;


• Thank you so much. The curve looks good. I have one question so I can understand the theory, I know the matched filter impulse response must be time reversed as that of input but why do you mirror the coefficients in this case? – Abeer Jan 5 '17 at 20:36
• The mirroring amounts to the time-reversal. – Maximilian Matthé Jan 5 '17 at 21:58
• So in order to do matching the transmitted pulse now contains the mirrored ternary coefficients and then this pulse is matched with the matched filter which has those coefficients? In other words mirrored coefficients are being matched. Is my conclusion correct? – Abeer Jan 6 '17 at 9:58
• the matched-filter criterion is if, g[n] is the TX filter, then g[-n] should be the RX filter (or vice versa). This is what I have implemented. – Maximilian Matthé Jan 6 '17 at 10:18
• ok I get it now. Thank you so much for the guidance, explanation and suggestions – Abeer Jan 7 '17 at 11:49