0
$\begingroup$

I am using the standard MATLAB filter function to design pre-emphasis filter. However, I am getting the wrong results back! I have the ground truth so I can check it.

For example I wrote this one Matlab code:

 B = ones(1,6);
 B=B*(-0.97);
 B(1)=1;
 z = 1; 
 xd = filter(B,z,data,[], 2);

However, I only getting back correctly only the first two columns.

Ground truth:

-604.981536865234   -98.1470046997071   -105.546778869629   -114.096517944336   -113.826526184082   -112.466567687988
-615.981201171875   -17.4794665527344   -22.4493148803712   -27.5691586303711   -19.8393945312500   -21.8693325805664
-448.986297607422   4.52986175537109    6.06981475830077    1.63994995117184    -0.939971313476576  -7.60976776123050
-10.9996643066406   -18.3294406127930   -18.8694241333008   -16.4094992065430   -16.8594854736328   -15.3095327758789
207.993652343750    -3.75988525390625   5.93981872558595    3.93987976074220    2.87991210937500    2.78991485595705
105.996765136719    11.1796588134766    6.41980407714844    6.50980133056640    10.5996765136719    3.80988372802734

What I recover:

-604.981536865234   -98.1470046997071   481.285311889649    1137.16529541016    1884.31249359131    2720.81696472168
-615.981201171875   -17.4794665527344   575.052450256348    1166.46440124512    1774.60584167480    2381.71731353760
-448.986297607422   4.52986175537109    441.586523437500    855.213900146484    1252.26178283691    1631.64020477295
-10.9996643066406   -18.3294406127930   -8.19974975585937   22.3893167114258    67.5279391479492    129.216056518555
207.993652343750    -3.75988525390625   -195.814024047852   -389.868101806641   -582.982208251953   -773.186403503418
105.996765136719    11.1796588134766    -96.3970581054687   -206.883686218262   -316.280347595215   -439.466588134766

My coeff is supposed to be 0.97, I don't get the partial correct results to be honest.

cheers for any input!

$\endgroup$
  • $\begingroup$ Can you please explain what are the specs of the filter you're designing, and why do you expect it to give a certain result? $\endgroup$ – MBaz Apr 5 '16 at 2:34
  • $\begingroup$ I believe that OP means the most simple pre-emphasis filter: $H(z)=1-\alpha z^{-1}$. $\endgroup$ – jojek Apr 5 '16 at 7:16
3
$\begingroup$

I don't really understand what are you trying to achieve with vector B that has 6 elements. Pre-emphasis filter is defined as:

$$y[n]=x[n]-\alpha x[n-1]$$

Where $\alpha$ is $0.97$ in your case.

You can see that there are only two elements in vector B, right? So the code should be something like that:

B=[1, -0.97];
xd = filter(B, 1, data, [], 2);

You can verify the frequency response:

freqz(B, 1)

enter image description here

$\endgroup$
1
$\begingroup$

Only two columns of your output match the expected results, because the first $N$ columns only depend on the first $N$ filter coefficients and only the first two coefficients are consistent with the desired result.

Working back from your original data (which I recreated back from the provided "recovered" result):

-604.9815368652340   -684.9790954589840   -769.9765014648426   -860.9737243652289   -948.9710388183510  -1032.9684753417814
-615.9812011718750   -614.9812316894531   -618.9811096191402   -627.9808349609343   -628.9808044433603   -631.9807128906195
-448.9862976074220   -430.9868469238282   -411.9874267578127   -397.9878540039070   -386.9881896972709   -382.9883117675836
 -10.9996643066406    -28.9991149902344    -46.9985656738281    -61.9981079101562    -76.9976501464843    -89.9972534179683
 207.9936523437500    197.9939575195312    197.9939575195308    195.9940185546867    192.9941101074209    189.9942016601541
 105.9967651367190    113.9965209960940    116.9964294433599    119.9963378906258    126.9961242675798    126.9961242675811

You can compute what the coefficients should be to get your expected results with:

row = 1; % choose any row, results should be the same within numerical errors
B_expected = zeros(size(B));
for col=1:size(data,2)
  sum = 0;
  for idx=2:col
    if col <= length(B)
      sum = sum + B_expected(col-idx+1)*data(row,idx);
    end
  end
  B_expected(col) = (Ground_Truth(row,col)-sum)./data(row,1);
end
B_expected

Which gives you:

1.0000e+000  -9.7000e-001  1.3859e-015  5.7785e-015  -3.2181e-015  6.0134e-015

Asides from numerical errors, this essentially corresponds to using only two non-zero coefficients of [1 -0.97] and is consistent with the pre-emphasis filter definition as indicated in @jojek's answer:

B=[1, -0.97];
xd = filter(B, 1, data, [], 2);
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.