DSPRelated.com
Forums

Problem in BPSK Modulation

Started by muhammad avais November 18, 2009
Dear Sir,
i want to implement bpsk demodulator in DSK6713. I have
generated modulated signal from Matlab and providing this signal to DSK6713
board. The carrier signal frequency is 8khz and data is at 1KhZ rate. This
means binary one and zero will have 8 cycles of carrier wave. I am taking
the input from onboard codec and want to output demodulated signal on the
same codec.
For bpsk demodulation, i have implemented match filter that
is matched to input signal and expecting binary one and zero on
oscilloscope. The sampling rate of codec is set to 32 KHz and match filter
implemented has 32 coefficient.
The match filter, i am trying to imlement for BPSK
demodulation is shown on page 208 of book " Digital Communication by Bernard
SKLAR second edition"
The output of this filter is not correct. Can you please
guide me problem in this approach. The code is shown below.
#include "dsk6713_aic23.h"

#include "stdio.h"

void init_coeff(int [], int []);

void init_ip(int []);

int x[32]={0};

int y=0,z=0;

int c0[32]={0};// coefficient of matched filter

int c1[32]={0};

int w0[4]={0,-1,0,1};

int w1[4]={0,1,0,-1};

static int temp;

void main()

{

init_ip(x);

init_coeff(c0,w0);

init_coeff(c1,w1);

comm_intr();

while(1);

}

interrupt void c_int11()

{

int i;

x[0]=input_sample();

y=0;

z=0;

for(i=0;i<32;i++)

{

y=y+(c0[i]*x[i]);

z=z+(c1[i]*x[i]);

}

for(i1;i>0;i--)

{

x[i]=x[i-1];

}

if(y>=z)

output_sample(100000000);

else

output_sample(0);

return;

}

void init_coeff(int p1[], int p2[]) // The function to initialize the
coefficient of matched filter that are matched to

{

int i,j;

for(i=0;i<32;i=i+4)

{

for(j=0;j<4;j++)

{

p1[i+j]=p2[j];

}

}

}

void init_ip(int q[])

{

int i;

for(i=0;i<32;i++)

{

q[i]=0;

}

}
Dear Richard Williams,
I am expecting binary one and zero at
rate of 1KHZ, but the output shows some data at rate of 6 to 10KHZ.As
I am only outputting
output_sample(100000000); // output 1
and
output_sample(0); // output 0
So, if data is not demodulated correctly, output must be in form of
square waves, after being reconstructed from DAC but output shows
pulses like sine wave at rate of about 6 to 10 KHz.

1) I used function "init_ip(int [])"; to initialize the input array
because during debugging i found they were not initially zero despite
of statement
"int x[32]={0};".
2) the variable static int Temp was only used for debugging.
I think if i output data word for each input sample, even then output
after being passed through DAC will result into square wave

The matlab code given below produces BPSK modulated signal at carrier
frequency 8KHz. Data is alternative ones and zeros at rate of 1KHZ
a=[1];
b=[-1];
z=repmat(a,1,48);
y=repmat(b,1,48);
q=[z y z y z y z y z y];
s=repmat(q,1,1000);
length(s);
t=[0:1/48000:(10-1/48000)];
y=cos(2*pi*8000*t);
u=y.*s;
while(1)
wavplay(u,48000);
end

many thanks for your help and guidance

Kind Regards
Avais
On 11/18/09, Richard Williams wrote:
> muhammad,
>
> You did not mention the specifics of what was wrong with the output data.
> The information on the error(s) would help in determining the cause of the
> problem.
>
> I suspect the indicated functions are missing some info.
> The reason I suspect this is because:
> 1) the function void init_ip(int []);
> is only invoked once, with the address of the 'x' array as a parameter.
> the init_ip() function only fills the first 32 positions of the passed
> parameter to 0.
> However, in this case, the 'x' array is already set to 0 by "int
> x[32]={0};".
> 2) the variable static int Temp is never used.
>
> I see a data word is output for every input sample. It may be worthwhile
> to only
> output a data word when the value of the output changes.
> This will mean saving the prior calculated output data
> and making a comparison with the new calculated output data
> and only output data when the value changes.
> As it is, a new data word is being output at a 8khz rate.
>
> BTW:
> 1) please do not use tabs in the source code. Not everyone has the tab set
> to the same number of columns
> 2) stdio.h is a system header file, therefore, if your system is setup
> correctly, it should be written as: #include
> 3) it would have been much clearer if the C0 and C1 arrays had been
> initialized with
> the repeating strings via an initializer string rather than: init via {0}
> plus invoking a function to perform the actual initialization.
> This would have enabled the elimination of w0 and w1 and the two invocations
> of the init_coeff function
> 4) commenting the code would have made my job of analysis much easier.
> 5) the function init_ip should not have a hardcoded loop count as this
> removes all flexability in that function.
> Rather a second parameter could be passed in that contains the correct loop
> count.
> in this case, that parameter could be (sizeof(x)/sizeof(int))
> *I* would even have a third parameter that contains the value (in this case
> 0) with which the passed in array is to be initialized.
>
> I see the interrupt handler is performing a lot of math and data movement.
> This leaves me to suspect the interrupt handler maybe running too long.
> This could result in data being lost.
>
> R. Williams
>
> ---------- Original Message -----------
> From: muhammad avais
> To: c...
> Sent: Tue, 17 Nov 2009 12:54:00 +0500
> Subject: [c6x] Problem in BPSK Modulation
>
>> Dear Sir,
>> i want to implement bpsk demodulator in DSK6713. I have
>> generated modulated signal from Matlab and providing this signal to
>> DSK6713 board. The carrier signal frequency is 8khz and data is at 1KhZ
>> rate. This means binary one and zero will have 8 cycles of carrier
>> wave. I am taking the input from onboard codec and want to output
>> demodulated signal on the same codec.
>> For bpsk demodulation, i have implemented match filter that
>> is matched to input signal and expecting binary one and zero on
>> oscilloscope. The sampling rate of codec is set to 32 KHz and match filter
>> implemented has 32 coefficient.
>> The match filter, i am trying to imlement for BPSK
>> demodulation is shown on page 208 of book " Digital Communication by
>> Bernard SKLAR second edition"
>> The output of this filter is not correct. Can you please
>> guide me problem in this approach. The code is shown below.
>> #include "dsk6713_aic23.h"
>>
>> #include "stdio.h"
>> void init_coeff(int [], int []);
>> void init_ip(int []);
>> int x[32]={0};
>> int y=0,z=0;
>> int c0[32]={0};// coefficient of matched filter
>> int c1[32]={0};
>> int w0[4]={0,-1,0,1};
>> int w1[4]={0,1,0,-1};
>> static int temp;
>>
>> void main()
>>
>> {
>> init_ip(x);
>> init_coeff(c0,w0);
>> init_coeff(c1,w1);
>> comm_intr();
>> while(1);
>> }
>>
>> interrupt void c_int11()
>> {
>> int i;
>> x[0]=input_sample(); // get new input sample
>> y=0; // init filter sum
>> z=0; // init filter sum
>>
>> // calc the filter results
>> for(i=0;i<32;i++)
>> {
>> y=y+(c0[i]*x[i]);
>> z=z+(c1[i]*x[i]);
>> }
>>
>> // 'age' the data in prep for next data input
>> for(i1;i>0;i--)
>> {
>> x[i]=x[i-1];
>>
>> }
>>
>> // output the new value
>> if(y>=z)
>> output_sample(100000000);
>> else
>> output_sample(0);
>> return;
>> }
>>
>> void init_coeff(int p1[], int p2[]) // The function to initialize the
>> coefficient of matched filter that are matched to
>> {
>> int i,j;
>> for(i=0;i<32;i=i+4)
>> {
>> for(j=0;j<4;j++)
>> {
>> p1[i+j]=p2[j];
>> }
>> }
>>
>> }
>> void init_ip(int q[])
>> {
>> int i;
>> for(i=0;i<32;i++)
>> {
>> q[i]=0;
>> }
>> }
>

_____________________________________
muhammad,

You did not mention the specifics of what was wrong with the output data.
The information on the error(s) would help in determining the cause of the problem.

I suspect the indicated functions are missing some info.
The reason I suspect this is because:
1) the function void init_ip(int []);
is only invoked once, with the address of the 'x' array as a parameter.
the init_ip() function only fills the first 32 positions of the passed parameter to 0.
However, in this case, the 'x' array is already set to 0 by "int x[32]={0};".
2) the variable static int Temp is never used.

I see a data word is output for every input sample. It may be worthwhile to only
output a data word when the value of the output changes.
This will mean saving the prior calculated output data
and making a comparison with the new calculated output data
and only output data when the value changes.
As it is, a new data word is being output at a 8khz rate.

BTW:
1) please do not use tabs in the source code. Not everyone has the tab set to the same number of columns
2) stdio.h is a system header file, therefore, if your system is setup correctly, it should be written as: #include
3) it would have been much clearer if the C0 and C1 arrays had been initialized with
the repeating strings via an initializer string rather than: init via {0} plus invoking a function to perform the actual initialization.
This would have enabled the elimination of w0 and w1 and the two invocations of the init_coeff function
4) commenting the code would have made my job of analysis much easier.
5) the function init_ip should not have a hardcoded loop count as this removes all flexability in that function.
Rather a second parameter could be passed in that contains the correct loop count.
in this case, that parameter could be (sizeof(x)/sizeof(int))
*I* would even have a third parameter that contains the value (in this case 0) with which the passed in array is to be initialized.

I see the interrupt handler is performing a lot of math and data movement.
This leaves me to suspect the interrupt handler maybe running too long.
This could result in data being lost.

R. Williams

---------- Original Message -----------
From: muhammad avais
To: c...
Sent: Tue, 17 Nov 2009 12:54:00 +0500
Subject: [c6x] Problem in BPSK Modulation

>
>
> Dear Sir,
> iwant to implement bpsk demodulator in DSK6713. I have generated modulated signal from Matlab and providing this signal to DSK6713 board. The carrier signal frequency is 8khz and data is at 1KhZ rate. This means binary one and zerowill have 8 cycles of carrier wave.I am taking the input from onboard codec and want to output demodulated signal on the same codec.
> For bpsk demodulation, i have implemented match filter that is matched to input signal and expecting binary one and zero on oscilloscope.The sampling rate of codec is set to 32 KHz and match filter implementedhas 32 coefficient.
> The match filter, i am trying to imlement for BPSK demodulation is shown on page 208 of book " Digital Communication by Bernard SKLAR second edition"
> The output of this filter is not correct. Can you please guide me problem in this approach. The code is shown below.
> #include "dsk6713_aic23.h"
>
> #include "stdio.h"
> void init_coeff(int [], int []);
> void init_ip(int []);
> int x[32]={0};
> int y=0,z=0;
> int c0[32]={0};// coefficient of matched filter
> int c1[32]={0};
> int w0[4]={0,-1,0,1};
> int w1[4]={0,1,0,-1};
> static int temp;
>
> void main()
>
> {
> init_ip(x);
> init_coeff(c0,w0);
> init_coeff(c1,w1);
> comm_intr();
> while(1);
> }
>
> interrupt void c_int11()
> {
> int i;
> x[0]=input_sample(); // get new input sample
> y=0; // init filter sum
> z=0; // init filter sum
>
> // calc the filter results
> for(i=0;i<32;i++)
> {
> y=y+(c0[i]*x[i]);
> z=z+(c1[i]*x[i]);
> }
>
> // 'age' the data in prep for next data input
> for(i1;i>0;i--)
> {
> x[i]=x[i-1];
>
> }
>
> // output the new value
> if(y>=z)
> output_sample(100000000);
> else
> output_sample(0);
> return;
> }
>
> void init_coeff(int p1[], int p2[]) // The function to initialize the coefficient of matched filter that are matched to
> {
> int i,j;
> for(i=0;i<32;i=i+4)
> {
> for(j=0;j<4;j++)
> {
> p1[i+j]=p2[j];
> }
> }
>
> }
> void init_ip(int q[])
> {
> int i;
> for(i=0;i<32;i++)
> {
> q[i]=0;
> }
> }
muhammad,

as a first guess, the interrupt handler needs to incorporate a low pass filter to remove the carrier signal.
perhaps a 'fir' filter.

There seems to be 4 samples (32khz sample rate) for each cycle of the input carrier wave.

given the sample values range from 0xFFF to 0x000
where 0x800 is the zero crossing point.

so:
when no bit transition the sum of 4 samples would be close to 0x800*4.
when bit transition to 0, the sum of 4 samples would be less than 0x800*4.
when bit transition to 1, the sum of 4 samples would be greater than 0x800*4.
The greater the number of samples taken, the closer to 0x800* the sum would be for no bit transition.

using the two different 'weight' strings (the W0 and W1 strings) would produce a difference that can be used to determine if the current data bit value transitioned to 0 or 1. (or did not change)

As a suggestion, I would start with normalizing the sample values by adjusting the value to account for the 0 crossing offset. I.E. subtract 0x800 from each sample before placing into x[0]. This would move the zero sampling point 0x000 rather than 0x800.

Then I would look carefully at the actual values in 'y' and 'z'.
I would expect those values to be reasonably steady (after the first 32 samples) except for when a bit transition occurs. examination of the actual values during steady state and at 1->0 and 0->1 transitions would indicate when to output nothing and when to output a 0 or 1.
Also, as I previously indicated I would only output a value when the transition first occurs, not during the next 31 sample periods (while the bit transition is still being recognized by the filter).

Hope this helps.

R. Williams

---------- Original Message -----------
From: muhammad avais
To: Richard Williams , c6x
Sent: Wed, 18 Nov 2009 14:41:12 +0500
Subject: Re: [c6x] Problem in BPSK Modulation

>
>
> Dear Richard Williams,
> I am expecting binary one and zero at
> rate of 1KHZ, but the output shows some data at rate of 6 to 10KHZ.As
> I am only outputting
> output_sample(100000000); // output 1
> and
> output_sample(0); // output 0
> So, if data is not demodulated correctly, output must be in form of
> square waves, after being reconstructed from DAC but output shows
> pulses like sine wave at rate of about 6 to 10 KHz.
>
> 1) I used function "init_ip(int [])"; to initialize the input array
> because during debugging i found they were not initially zero despite
> of statement
> "int x[32]={0};".
> 2) the variable static int Temp was only used for debugging.
> I think if i output data word for each input sample, even then output
> after being passed through DAC will result into square wave
>
> The matlab code given below produces BPSK modulated signal at carrier
> frequency 8KHz. Data is alternative ones and zeros at rate of 1KHZ
> a=[1];
> b=[-1];
> z=repmat(a,1,48);
> y=repmat(b,1,48);
> q=[z y z y z y z y z y];
> s=repmat(q,1,1000);
> length(s);
> t=[0:1/48000:(10-1/48000)];
> y=cos(2*pi*8000*t);
> u=y.*s;
> while(1)
> wavplay(u,48000);
> end
>
> many thanks for your help and guidance
>
> Kind Regards
> Avais
>
> On 11/18/09, Richard Williams wrote:
> > muhammad,
> >
> > You did not mention the specifics of what was wrong with the output data.
> > The information on the error(s) would help in determining the cause of the
> > problem.
> >
> > I suspect the indicated functions are missing some info.
> > The reason I suspect this is because:
> > 1) the function void init_ip(int []);
> > is only invoked once, with the address of the 'x' array as a parameter.
> > the init_ip() function only fills the first 32 positions of the passed
> > parameter to 0.
> > However, in this case, the 'x' array is already set to 0 by "int
> > x[32]={0};".
> > 2) the variable static int Temp is never used.
> >
> > I see a data word is output for every input sample. It may be worthwhile
> > to only
> > output a data word when the value of the output changes.
> > This will mean saving the prior calculated output data
> > and making a comparison with the new calculated output data
> > and only output data when the value changes.
> > As it is, a new data word is being output at a 8khz rate.
> >
> > BTW:
> > 1) please do not use tabs in the source code. Not everyone has the tab set
> > to the same number of columns
> > 2) stdio.h is a system header file, therefore, if your system is setup
> > correctly, it should be written as: #include
> > 3) it would have been much clearer if the C0 and C1 arrays had been
> > initialized with
> > the repeating strings via an initializer string rather than: init via {0}
> > plus invoking a function to perform the actual initialization.
> > This would have enabled the elimination of w0 and w1 and the two invocations
> > of the init_coeff function
> > 4) commenting the code would have made my job of analysis much easier.
> > 5) the function init_ip should not have a hardcoded loop count as this
> > removes all flexability in that function.
> > Rather a second parameter could be passed in that contains the correct loop
> > count.
> > in this case, that parameter could be (sizeof(x)/sizeof(int))
> > *I* would even have a third parameter that contains the value (in this case
> > 0) with which the passed in array is to be initialized.
> >
> > I see the interrupt handler is performing a lot of math and data movement.
> > This leaves me to suspect the interrupt handler maybe running too long.
> > This could result in data being lost.
> >
> > R. Williams
> >
> > ---------- Original Message -----------
> > From: muhammad avais
> > To: c...
> > Sent: Tue, 17 Nov 2009 12:54:00 +0500
> > Subject: [c6x] Problem in BPSK Modulation
> >
> >>
> >>
> >> Dear Sir,
> >> i want to implement bpsk demodulator in DSK6713. I have
> >> generated modulated signal from Matlab and providing this signal to
> >> DSK6713 board. The carrier signal frequency is 8khz and data is at 1KhZ
> >> rate. This means binary one and zero will have 8 cycles of carrier
> >> wave. I am taking the input from onboard codec and want to output
> >> demodulated signal on the same codec.
> >> For bpsk demodulation, i have implemented match filter that
> >> is matched to input signal and expecting binary one and zero on
> >> oscilloscope. The sampling rate of codec is set to 32 KHz and match filter
> >> implemented has 32 coefficient.
> >> The match filter, i am trying to imlement for BPSK
> >> demodulation is shown on page 208 of book " Digital Communication by
> >> Bernard SKLAR second edition"
> >> The output of this filter is not correct. Can you please
> >> guide me problem in this approach. The code is shown below.
> >> #include "dsk6713_aic23.h"
> >>
> >> #include "stdio.h"
> >> void init_coeff(int [], int []);
> >> void init_ip(int []);
> >> int x[32]={0};
> >> int y=0,z=0;
> >> int c0[32]={0};// coefficient of matched filter
> >> int c1[32]={0};
> >> int w0[4]={0,-1,0,1};
> >> int w1[4]={0,1,0,-1};
> >> static int temp;
> >>
> >> void main()
> >>
> >> {
> >> init_ip(x);
> >> init_coeff(c0,w0);
> >> init_coeff(c1,w1);
> >> comm_intr();
> >> while(1);
> >> }
> >>
> >> interrupt void c_int11()
> >> {
> >> int i;
> >> x[0]=input_sample(); // get new input sample
> >> y=0; // init filter sum
> >> z=0; // init filter sum
> >>
> >> // calc the filter results
> >> for(i=0;i<32;i++)
> >> {
> >> y=y+(c0[i]*x[i]);
> >> z=z+(c1[i]*x[i]);
> >> }
> >>
> >> // 'age' the data in prep for next data input
> >> for(i1;i>0;i--)
> >> {
> >> x[i]=x[i-1];
> >>
> >> }
> >>
> >> // output the new value
> >> if(y>=z)
> >> output_sample(100000000);
> >> else
> >> output_sample(0);
> >> return;
> >> }
> >>
> >> void init_coeff(int p1[], int p2[]) // The function to initialize the
> >> coefficient of matched filter that are matched to
> >> {
> >> int i,j;
> >> for(i=0;i<32;i=i+4)
> >> {
> >> for(j=0;j<4;j++)
> >> {
> >> p1[i+j]=p2[j];
> >> }
> >> }
> >>
> >> }
> >> void init_ip(int q[])
> >> {
> >> int i;
> >> for(i=0;i<32;i++)
> >> {
> >> q[i]=0;
> >> }
> >> }
> >
> >
> >
------- End of Original Message -------