DSPRelated.com
Forums

IIR oscillator or cos(Wn)

Started by Masood September 21, 2006
Masood wrote:
>> Masood wrote: >>>> Masood wrote: >>>>> Jerry >>>>> Thanks for the reply, reply to your questions follows: >>>>> >>>>> 1. i am using pentium machine for DSP software implementation. >>>>> 2. in cos( 2*pi*(Fc/Fs)n) Fc is signal frequency, Fs is sampling >>>>> frequency and their ratio Fc/Fs is digital frequency. >>>>> 3. if both IIR and cos(wn) are method of generating oscillator then >>>>> i would prefer using cos equation for simplicity as i am doing it >>> for >>>>> first time. >>>> Well then, there's not much to figure out. Just decide how much the >>>> phase is to advance every sample, and compute a new cosine. >>>> >>>> Suppose that you want a frequency that is Fs/n. Then the phase will >>>> advance 2*pi radians after n periods, or 2*pi/n radians per period. >>>> >>>> Define phase_increment "2*pi/n"; >>>> >>>> Set theta = 0; >>>> >>>> Define a function 'new_cos()': >>>> >>>> Theta += phase_increment; >>>> return cos(theta); >>>> end; >>>> >>>> If that's fast enough, go for it. Other methods can be about 20 times > >>>> faster. >>>> >>>> Jerry >>>> -- >>>> of a thread, making it hard to follow. >>>> is that it interrupts the natural flow >>>> The thing I dislike about top posting >>>> &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295; >>>> >>> If desired frequency is not exactly obtainable from Fs/n >>> then what should be the solution. >> 'n' was a bad choice of variable name. It need not be an integer. >> >>> suppose Fs=48khz and i am downsampling 25 khz >>> to 12 khz then i need 13 Khz (Local Oscillator)signal so(pseudo code) >>> upto my understanding would be >>> >>> loop for n=0 to 1024 <-(sample count) >>> (25 Khz signal)* cos(2*pi*(13kz/48khz)*n) <-cos(Wn) where, > W=2*pi*Fc/Fs >>> end >>> where 13 Khz is (local oscillator)signal to get 25-13=12 Khz and > 25+13=38 >>> Khz >> You described heterodyning, not downsampling. >> >>> 1. would it give same result as the algoithm you have mentioned >>> in case desired frequency is exactly obtainable from Fs/n ? >>> 2. if above is true then does it mean that it can be used for > obtaining >>> any (LO) frequency signal for downsampling and upconversion? >> Jerry >> -- >> "The rights of the best of men are secured only as the >> rights of the vilest and most abhorrent are protected." >> - Chief Justice Charles Evans Hughes, 1927 >> &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295; >> > > > Jerry you were right, it would be down conversion from 25 Khz to 12 Khz. > can you comment on my questions below: > > suppose Fs=48khz and i am down converting it to 25 khz > then i need 13 Khz (Local Oscillator)signal so(pseudo code) > upto my understanding would be
You need to understand the distinction between sample-rate conversion and and frequency shifting. The method of frequency shifting that you describe is called heterodyning, and is not suitable for the shift you need. I can't describe what you have to do until I understand better what you want to accomplish. Be specific. You began by asking how to make an sine wave. It turns out (if I guess correctly) that you want to change the sample rate. An oscillator has nothing to do with that.
> loop for n=0 to 1024 <-(sample count) > (25 Khz signal)* cos(2*pi*(13kz/48khz)*n) <-cos(Wn) where, W=2*pi*Fc/Fs > end > where 13 Khz is (local oscillator)signal to get 25-13=12 Khz and > 25+13=38 Khz > > 1. would it give same result as the algoithm you have mentioned ? > > 2. if above is true then does it mean that it can be used for > obtaining > any (LO) frequency signal for down conversion and up conversion of > received signal ?
Jerry -- "The rights of the best of men are secured only as the rights of the vilest and most abhorrent are protected." - Chief Justice Charles Evans Hughes, 1927 &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;
>Masood wrote: >>> Masood wrote: >>>>> Masood wrote: >>>>>> Jerry >>>>>> Thanks for the reply, reply to your questions follows: >>>>>> >>>>>> 1. i am using pentium machine for DSP software implementation. >>>>>> 2. in cos( 2*pi*(Fc/Fs)n) Fc is signal frequency, Fs is sampling >>>>>> frequency and their ratio Fc/Fs is digital frequency. >>>>>> 3. if both IIR and cos(wn) are method of generating oscillator
then
>>>>>> i would prefer using cos equation for simplicity as i am doing
it
>>>> for >>>>>> first time. >>>>> Well then, there's not much to figure out. Just decide how much the
>>>>> phase is to advance every sample, and compute a new cosine. >>>>> >>>>> Suppose that you want a frequency that is Fs/n. Then the phase will
>>>>> advance 2*pi radians after n periods, or 2*pi/n radians per period. >>>>> >>>>> Define phase_increment "2*pi/n"; >>>>> >>>>> Set theta = 0; >>>>> >>>>> Define a function 'new_cos()': >>>>> >>>>> Theta += phase_increment; >>>>> return cos(theta); >>>>> end; >>>>> >>>>> If that's fast enough, go for it. Other methods can be about 20
times
>> >>>>> faster. >>>>> >>>>> Jerry >>>>> -- >>>>> of a thread, making it hard to follow. >>>>> is that it interrupts the natural flow >>>>> The thing I dislike about top posting >>>>>
&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;
>>>>> >>>> If desired frequency is not exactly obtainable from Fs/n >>>> then what should be the solution. >>> 'n' was a bad choice of variable name. It need not be an integer. >>> >>>> suppose Fs=48khz and i am downsampling 25 khz >>>> to 12 khz then i need 13 Khz (Local Oscillator)signal so(pseudo
code)
>>>> upto my understanding would be >>>> >>>> loop for n=0 to 1024 <-(sample count) >>>> (25 Khz signal)* cos(2*pi*(13kz/48khz)*n) <-cos(Wn) where, >> W=2*pi*Fc/Fs >>>> end >>>> where 13 Khz is (local oscillator)signal to get 25-13=12 Khz and >> 25+13=38 >>>> Khz >>> You described heterodyning, not downsampling. >>> >>>> 1. would it give same result as the algoithm you have mentioned >>>> in case desired frequency is exactly obtainable from Fs/n ? >>>> 2. if above is true then does it mean that it can be used for >> obtaining >>>> any (LO) frequency signal for downsampling and upconversion? >>> Jerry >>> -- >>> "The rights of the best of men are secured only as the >>> rights of the vilest and most abhorrent are protected." >>> - Chief Justice Charles Evans Hughes, 1927 >>> &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295; >>> >> >> >> Jerry you were right, it would be down conversion from 25 Khz to 12
Khz.
>> can you comment on my questions below: >> >> suppose Fs=48khz and i am down converting it to 25 khz >> then i need 13 Khz (Local Oscillator)signal so(pseudo code) >> upto my understanding would be > >You need to understand the distinction between sample-rate conversion >and and frequency shifting. The method of frequency shifting that you >describe is called heterodyning, and is not suitable for the shift you >need. I can't describe what you have to do until I understand better >what you want to accomplish. Be specific. You began by asking how to >make an sine wave. It turns out (if I guess correctly) that you want to >change the sample rate. An oscillator has nothing to do with that. > >> loop for n=0 to 1024 <-(sample count) >> (25 Khz signal)* cos(2*pi*(13kz/48khz)*n) <-cos(Wn) where,
W=2*pi*Fc/Fs
>> end >> where 13 Khz is (local oscillator)signal to get 25-13=12 Khz and >> 25+13=38 Khz >> >> 1. would it give same result as the algoithm you have mentioned ? >> >> 2. if above is true then does it mean that it can be used for >> obtaining >> any (LO) frequency signal for down conversion and up conversion of >> received signal ? > >Jerry >-- > "The rights of the best of men are secured only as the > rights of the vilest and most abhorrent are protected." > - Chief Justice Charles Evans Hughes, 1927 >&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295; >
Hi Jerry i want to demodulate the AM signals in real time by software runing in PC(sampling rate=48khz), i plan to shit the frequency of received AM signal from RF front-end to the value suitable for sound card, i will be using 14 Khz for sound card input, now when the signal is in PC i want to shift frequency of this signal to 12 Khz then what i have to do, Is the pseuode code described ealier by me is suffecient or not? can you tell guide me by explaining the pseudocode i need to implement reply soon Regards Masood