Forums

Sample rate conversion doubt

Started by jaac January 2, 2005
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=E0: 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

jaac wrote:

> 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
jaac wrote:

> 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. �����������������������������������������������������������������������
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

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

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

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

jaac wrote:

> 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
"jaac" <jaime.aranguren@ieee.org> wrote in message 
news:1104711708.340093.186300@f14g2000cwb.googlegroups.com...
> 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
> > 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 >
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