Sample rate conversion doubt
CASTalk.com Forum Index CASTalk.com
Discussion of DSP, FPGA, storage and embedded system.
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web castalk.com
Sample rate conversion doubt

 
Post new topic   Reply to topic    CASTalk.com Forum Index -> DSP
Author Message
jaac
Guest





Posted: Mon Jan 03, 2005 12:33 am    Post subject: Sample rate conversion doubt Reply with quote

Hello guys,

I've been struggling with algorithms for sample rate conversion, namely
decimation by a factor of 40, to convert from 8kHz sample rate to 200
Hz.

I've started with the block diagrams from P.P. Vaidyanathan's book
"Multirate Systems and Filter Banks" implementing them in Simulink, and
then writting my own C code. From the Simulink model everything was OK.
But my C code (running on a SHARC, BTW) gave me some sort of modulation
on the decimated signal.

I asked for support, people here guided me to the code available at
DSPGuru. I understood it, implemented it, and gave me exactly the same
results as my original C code.

Moreover, I did the decimation by brute force, which means a long
lowpass filter, then discarding 39 out of 40 samples, and again the
same results.

I've been wondering why does it work perfectly in Cimulink, and not in
my code. In my test, the signal to be downsampled is a carrier at 60Hz,
with the "information" modulating this carrier, AM. The strange thing
is that even if I use a pure 60Hz tone as input, I get a modulated
output with my code, not with Simulink.

Someone suggested slightly changing the carrier frequency to say 60.37
Hz, and voilà: even in Simulink it appears that the decimated signal
seems to be modulated.

The conclusion is: I can't do the sample rate conversion for my
application, because MY information is on the envelope of the carrier,
because it's AM modulation.

But my BIG question is: is it TRUE that sampling rate conversion CAN
change the envelope of the output signal? Isn't there a way to do
sample rate conversion which preservers the signal shape, regardless of
the relations between original sample rate, final sample rate and
upsampling/downsampling factors?

Thank you very much,

JaaC
Back to top
Tim Wescott
Guest





Posted: Mon Jan 03, 2005 1:33 am    Post subject: Re: Sample rate conversion doubt Reply with quote

jaac wrote:

Quote:
Hello guys,

I've been struggling with algorithms for sample rate conversion, namely
decimation by a factor of 40, to convert from 8kHz sample rate to 200
Hz.

I've started with the block diagrams from P.P. Vaidyanathan's book
"Multirate Systems and Filter Banks" implementing them in Simulink, and
then writting my own C code. From the Simulink model everything was OK.
But my C code (running on a SHARC, BTW) gave me some sort of modulation
on the decimated signal.

I asked for support, people here guided me to the code available at
DSPGuru. I understood it, implemented it, and gave me exactly the same
results as my original C code.

Moreover, I did the decimation by brute force, which means a long
lowpass filter, then discarding 39 out of 40 samples, and again the
same results.

I've been wondering why does it work perfectly in Cimulink, and not in
my code. In my test, the signal to be downsampled is a carrier at 60Hz,
with the "information" modulating this carrier, AM. The strange thing
is that even if I use a pure 60Hz tone as input, I get a modulated
output with my code, not with Simulink.

Someone suggested slightly changing the carrier frequency to say 60.37
Hz, and voilà: even in Simulink it appears that the decimated signal
seems to be modulated.

The conclusion is: I can't do the sample rate conversion for my
application, because MY information is on the envelope of the carrier,
because it's AM modulation.

But my BIG question is: is it TRUE that sampling rate conversion CAN
change the envelope of the output signal? Isn't there a way to do
sample rate conversion which preservers the signal shape, regardless of
the relations between original sample rate, final sample rate and
upsampling/downsampling factors?

Thank you very much,

JaaC

Yes it is true. Using envelopes for demodulation is a very iffy

business with sampled data.

In fact, are you sure that your envelope is "perfect" with the 200Hz
sampling? I'm seeing a variation with a period of 10 samples -- perhaps
that is just short enough that you didn't notice?

You can't really preserve the signal shape in this case, without up
sampling again before demodulating. If it were me I'd either do exactly
that, or I'd do synchronous AM demodulation, which should retrieve your
original data just fine -- assuming that it's band limited enough.

--

Tim Wescott
Wescott Design Services
http://www.wescottdesign.com
Back to top
Jerry Avins
Guest





Posted: Mon Jan 03, 2005 2:18 am    Post subject: Re: Sample rate conversion doubt Reply with quote

jaac wrote:

Quote:
Hello guys,

I've been struggling with algorithms for sample rate conversion, namely
decimation by a factor of 40, to convert from 8kHz sample rate to 200
Hz.

I've started with the block diagrams from P.P. Vaidyanathan's book
"Multirate Systems and Filter Banks" implementing them in Simulink, and
then writting my own C code. From the Simulink model everything was OK.
But my C code (running on a SHARC, BTW) gave me some sort of modulation
on the decimated signal.

I asked for support, people here guided me to the code available at
DSPGuru. I understood it, implemented it, and gave me exactly the same
results as my original C code.

Moreover, I did the decimation by brute force, which means a long
lowpass filter, then discarding 39 out of 40 samples, and again the
same results.

I've been wondering why does it work perfectly in Cimulink, and not in
my code. In my test, the signal to be downsampled is a carrier at 60Hz,
with the "information" modulating this carrier, AM. The strange thing
is that even if I use a pure 60Hz tone as input, I get a modulated
output with my code, not with Simulink.

Someone suggested slightly changing the carrier frequency to say 60.37
Hz, and voilà: even in Simulink it appears that the decimated signal
seems to be modulated.

The conclusion is: I can't do the sample rate conversion for my
application, because MY information is on the envelope of the carrier,
because it's AM modulation.

But my BIG question is: is it TRUE that sampling rate conversion CAN
change the envelope of the output signal? Isn't there a way to do
sample rate conversion which preservers the signal shape, regardless of
the relations between original sample rate, final sample rate and
upsampling/downsampling factors?

Thank you very much,

JaaC

Envelope demodulation works with continuous signals because the peak of
the carrier is present in each carrier cycle. It can be faked if the
sample rate is high enough because a sample falls near enough to the
carrier peak in most carrier samples. (Using absolute value essentially
doubles the sample rate.) Even for continuous signals, envelope
detection works well only for modulating frequencies much lower than the
carrier frequency.

Jerry
--
Engineering is the art of making what you want from things you can get.
ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
Back to top
jaac
Guest





Posted: Mon Jan 03, 2005 5:20 am    Post subject: Re: Sample rate conversion doubt Reply with quote

Hi Tim,

Thanks for prompt reply.

To be precise, my project is related to the measurement of the
phenomena named "flicker", which consists of amplitude variations on
the AC line, 50/60 Hz, 220 / 110 Vrms. That's why my information is
precisely in the envelope of the carrier, which here is 60 Hz (possibly
with fluctuations, of course).

As stated on the IEC standard, the demodulation is done by squaring,
then some filtering is performed, to eliminate DC component and
components higher than Fs/2. And then further filtering and analysis of
the data, and storage.

Your idea of upsampling before demodulation, excuse me, is not a good
one. For my case, it would be better to do all of the downsampling
after the demodulation. I know that it is the almost the same as you
suggested, it is just locating the sample rate conversion to the place
where it is more benefical. I bet that's what you had in your mind.

The idea of synchronous AM demodulation seems interesting. Could you
please elaborate on the subject, or point me to information about it?
Kindest regards,

JaaC
Back to top
jaac
Guest





Posted: Mon Jan 03, 2005 5:20 am    Post subject: Re: Sample rate conversion doubt Reply with quote

Hi Tim,

Thanks for prompt reply.

To be precise, my project is related to the measurement of the
phenomena named "flicker", which consists of amplitude variations on
the AC line, 50/60 Hz, 220 / 110 Vrms. That's why my information is
precisely in the envelope of the carrier, which here is 60 Hz (possibly
with fluctuations, of course).

As stated on the IEC standard, the demodulation is done by squaring,
then some filtering is performed, to eliminate DC component and
components higher than Fs/2. And then further filtering and analysis of
the data, and storage.

Your idea of upsampling before demodulation, excuse me, is not a good
one. For my case, it would be better to do all of the downsampling
after the demodulation. I know that it is the almost the same as you
suggested, it is just locating the sample rate conversion to the place
where it is more benefical. I bet that's what you had in your mind.

The idea of synchronous AM demodulation seems interesting. Could you
please elaborate on the subject, or point me to information about it?
Kindest regards,

JaaC
Back to top
jaac
Guest





Posted: Mon Jan 03, 2005 5:21 am    Post subject: Re: Sample rate conversion doubt Reply with quote

Hi Tim,

Thanks for prompt reply.

To be precise, my project is related to the measurement of the
phenomena named "flicker", which consists of amplitude variations on
the AC line, 50/60 Hz, 220 / 110 Vrms. That's why my information is
precisely in the envelope of the carrier, which here is 60 Hz (possibly
with fluctuations, of course).

As stated on the IEC standard, the demodulation is done by squaring,
then some filtering is performed, to eliminate DC component and
components higher than Fs/2. And then further filtering and analysis of
the data, and storage.

Your idea of upsampling before demodulation, excuse me, is not a good
one. For my case, it would be better to do all of the downsampling
after the demodulation. I know that it is the almost the same as you
suggested, it is just locating the sample rate conversion to the place
where it is more benefical. I bet that's what you had in your mind.

The idea of synchronous AM demodulation seems interesting. Could you
please elaborate on the subject, or point me to information about it?
Kindest regards,

JaaC
Back to top
jaac
Guest





Posted: Mon Jan 03, 2005 5:21 am    Post subject: Re: Sample rate conversion doubt Reply with quote

Hi Tim,

Thanks for prompt reply.

To be precise, my project is related to the measurement of the
phenomena named "flicker", which consists of amplitude variations on
the AC line, 50/60 Hz, 220 / 110 Vrms. That's why my information is
precisely in the envelope of the carrier, which here is 60 Hz (possibly
with fluctuations, of course).

As stated on the IEC standard, the demodulation is done by squaring,
then some filtering is performed, to eliminate DC component and
components higher than Fs/2. And then further filtering and analysis of
the data, and storage.

Your idea of upsampling before demodulation, excuse me, is not a good
one. For my case, it would be better to do all of the downsampling
after the demodulation. I know that it is the almost the same as you
suggested, it is just locating the sample rate conversion to the place
where it is more benefical. I bet that's what you had in your mind.

The idea of synchronous AM demodulation seems interesting. Could you
please elaborate on the subject, or point me to information about it?
Kindest regards,

JaaC
Back to top
Tim Wescott
Guest





Posted: Mon Jan 03, 2005 5:29 am    Post subject: Re: Sample rate conversion doubt Reply with quote

jaac wrote:

Quote:
Hi Tim,

Thanks for prompt reply.

To be precise, my project is related to the measurement of the
phenomena named "flicker", which consists of amplitude variations on
the AC line, 50/60 Hz, 220 / 110 Vrms. That's why my information is
precisely in the envelope of the carrier, which here is 60 Hz (possibly
with fluctuations, of course).

As stated on the IEC standard, the demodulation is done by squaring,
then some filtering is performed, to eliminate DC component and
components higher than Fs/2. And then further filtering and analysis of
the data, and storage.

Your idea of upsampling before demodulation, excuse me, is not a good
one. For my case, it would be better to do all of the downsampling
after the demodulation. I know that it is the almost the same as you
suggested, it is just locating the sample rate conversion to the place
where it is more benefical. I bet that's what you had in your mind.

The idea of synchronous AM demodulation seems interesting. Could you
please elaborate on the subject, or point me to information about it?
Kindest regards,

JaaC

Sorry, I was assuming that you were forced into downsampling first -- if

you can, doing your demodulation first would be best, of course.

Google on "synchronous AM" to get appropriate information -- it's a
well-known method for high quality AM demodulation.

Given that you're working off of a specification it would probably be
easiest to do just that, unless you're prepared to justify how your
method is exactly equivalent.

--

Tim Wescott
Wescott Design Services
http://www.wescottdesign.com
Back to top
Philip Martel
Guest





Posted: Mon Jan 03, 2005 9:22 pm    Post subject: Re: Sample rate conversion doubt Reply with quote

"jaac" <jaime.aranguren@ieee.org> wrote in message
news:1104711708.340093.186300@f14g2000cwb.googlegroups.com...
Quote:
Hi Tim,

Thanks for prompt reply.

To be precise, my project is related to the measurement of the
phenomena named "flicker", which consists of amplitude variations on
the AC line, 50/60 Hz, 220 / 110 Vrms. That's why my information is
precisely in the envelope of the carrier, which here is 60 Hz (possibly
with fluctuations, of course).

As stated on the IEC standard, the demodulation is done by squaring,
then some filtering is performed, to eliminate DC component and
components higher than Fs/2. And then further filtering and analysis of
the data, and storage.
If I understand this, you are digitizing some data at 8KHz, then squaring

it. The data is a 60Hz signal with some modulation on it.
When you square the signal, you will get:
a DC term (level depends on carrier strength)
a low frequency term due to modulation (I think this is what you are
interested in)
the original 60 Hz signal with it's modulation
a signal at 120 Hz with various modulation signals

If the Fs you mention above is the original 8 KHz, then you will have the 60
Hz and 120 Hz signals. If the Fs you mention is the 200 Hz, then the
signals around 120 Hz will be aliased to around 20Hz and may fall into the
passband of your filter

Best wishes,
--Phil Martel
Quote:

Your idea of upsampling before demodulation, excuse me, is not a good
one. For my case, it would be better to do all of the downsampling
after the demodulation. I know that it is the almost the same as you
suggested, it is just locating the sample rate conversion to the place
where it is more benefical. I bet that's what you had in your mind.

The idea of synchronous AM demodulation seems interesting. Could you
please elaborate on the subject, or point me to information about it?
Kindest regards,

JaaC
Back to top
jaac
Guest





Posted: Mon Jan 03, 2005 10:29 pm    Post subject: Re: Sample rate conversion doubt Reply with quote

Hi Phil,

Thanks for the reply.

You are right. I would get aliasing. Thank you for pointing this out.

To be honest the 200Hz Fs comes from originally having the carrier at
50 Hz in the IEC document, but this won't be my case. If I stay without
the sample rate conversion, and sampling directly at low frequency, I'd
better change it to 240Hz, and I'll have to redesign my filters (I'm
lazy to do that).

More interesting, I'll go for the decimation after squaring at 8kHz.
So, my bandpass filter, from 0.05Hz to 35Hz @ 200Hz will effectively
reject the aliased signals, I won't modify the original signal's shape
(important because my information is there), and more important, I'll
only need one ADC per channel, instead of two (one sampling at 8kHz for
spectral analysis, the other one sampling at 200Hz for waveshape
fluctuation analysis).

Thank you very much!

JaaC
Back to top
Philip Martel
Guest





Posted: Mon Jan 03, 2005 11:03 pm    Post subject: Re: Sample rate conversion doubt Reply with quote

"jaac" <jaime.aranguren@ieee.org> wrote in message
news:1104773346.953976.218710@f14g2000cwb.googlegroups.com...
Quote:
Hi Phil,

Thanks for the reply.

You are right. I would get aliasing. Thank you for pointing this out.

To be honest the 200Hz Fs comes from originally having the carrier at
50 Hz in the IEC document, but this won't be my case. If I stay without
the sample rate conversion, and sampling directly at low frequency, I'd
better change it to 240Hz, and I'll have to redesign my filters (I'm
lazy to do that).

More interesting, I'll go for the decimation after squaring at 8kHz.
So, my bandpass filter, from 0.05Hz to 35Hz @ 200Hz will effectively
reject the aliased signals, I won't modify the original signal's shape
(important because my information is there), and more important, I'll
only need one ADC per channel, instead of two (one sampling at 8kHz for
spectral analysis, the other one sampling at 200Hz for waveshape
fluctuation analysis).

Thank you very much!

JaaC

Glad to have been of help. Won't you have to re-design your filter (0.05Hz

to 35Hz @ 200 Hz) to work at 8KHz? If you just feed the 8KHz samples in, I
suspect it will filter from 0.4Hz to 280Hz

Best wishes,
--Phil
Back to top
jaac
Guest





Posted: Thu Jan 06, 2005 10:32 pm    Post subject: Re: Sample rate conversion doubt Reply with quote

Philip Martel wrote:

Quote:
Glad to have been of help. Won't you have to re-design your filter
(0.05Hz
to 35Hz @ 200 Hz) to work at 8KHz? If you just feed the 8KHz samples
in, I
suspect it will filter from 0.4Hz to 280Hz

Best wishes,
--Phil

Hi Phil,

No. The signal flow would be like this:

Samples @ 8kHz -> Squaring (AM demodulation) @ 8kHz -> Decimation by 40
(New Fs: 200 Hz) -> Bandpass filtering (0.05Hz - 35 Hz) @ 200Hz ->
Other processing @ 200 Hz. What's wrong here?

Regards,

JaaC
Back to top
jaac
Guest





Posted: Thu Jan 06, 2005 10:35 pm    Post subject: Re: Sample rate conversion doubt Reply with quote

Philip Martel wrote:

Quote:
Glad to have been of help. Won't you have to re-design your filter
(0.05Hz
to 35Hz @ 200 Hz) to work at 8KHz?

The idea is to have them working at 200 Hz, not at 8kHz. Specifically,
to ease the design of the filters.

JaaC
Back to top
 
Post new topic   Reply to topic    CASTalk.com Forum Index -> DSP All times are GMT
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




VoIP Electronics Powered by phpBB