The Designer's Guide Community
Forum
Welcome, Guest. Please Login or Register. Please follow the Forum guidelines.
Jul 17th, 2024, 3:31pm
Pages: 1
Send Topic Print
Sample rate conversion (Read 5102 times)
SARAM
Junior Member
**
Offline



Posts: 12

Sample rate conversion
Sep 07th, 2011, 11:51pm
 
Hi all,

I want to write code for simulating interpolator.
I have two clock domain  CLK_low , CLK_high.
I want to increase sample rate by this ratio CLk_h/CLK_l.

I write code below and feed it with ramp but in some place it did not work correctly.

please help Cry

Clk_h=150 MHz;
CLK_l=61.44 MHz;

this program use linear interpolation y=(1-n)*Xn-1+n*Xn
that n is 0<n<1;

module SRC (in,out,CLK_l,CLK_h);
     
parameter integer OSR_1 = floor((1/(150/61.44))*pow(2,9));

     parameter integer scale = pow(2,9);
     

     input  in,CLK_l,CLK_h;
     output out;
     wreal  in,out;
           
     integer   fraq_cnt = 0;
     real   xn,xn_1,y_lin,frq,frq1;
     
     always @(posedge CLK_h )      begin
                 
                 fraq_cnt = fraq_cnt + OSR_1;
                 frq1     = (fraq_cnt % scale);
                 frq      = frq1/scale;
                 y_lin    =  (1-(frq)) * xn_1 + (frq) * xn;
                 
     end            
                 
     always @(posedge CLK_l ) begin
                             
                 xn_1   = xn;
                 xn     = in;
     end

                                   
     
assign      out = y_lin;

endmodule

Back to top
 
 
View Profile   IP Logged
boe
Community Fellow
*****
Offline



Posts: 615

Re: Sample rate conversion
Reply #1 - Sep 9th, 2011, 4:23am
 
SARAM,
Quote:
... but in some place it did not work correctly.

Please be more specific. Without more information we can only guess.

B O E
Back to top
 
 
View Profile   IP Logged
SARAM
Junior Member
**
Offline



Posts: 12

Re: Sample rate conversion
Reply #2 - Sep 14th, 2011, 3:43am
 
Hi,

The previous code was written for linear interpolation.
This one was written for Zero order hold. and the same clock frequency as above.

input  in,CLK_l,CLK_h;
    output out;
    wreal  in,out;

    real   xn,xn_1,y_zoh;
   
    always @(posedge CLK_h )      begin
               y_zoh = xn_1;
               
    end            
               
    always @(posedge CLK_l ) begin
                           
                xn_1   = xn;
                xn     = in;
    end


How can I make sure that in every rising edge of higher clk system take data and do the ZOH operation?
I dont see that there are some point at rising edge of Clk_h. and also the input is a linear ramp but the output is not.

Would you please help me

Amir
Back to top
 

Screenshot-1_007.png
View Profile   IP Logged
boe
Community Fellow
*****
Offline



Posts: 615

Re: Sample rate conversion
Reply #3 - Sep 14th, 2011, 12:40pm
 
SARAM,
please show input and output trace with sample&hold, not interpolated. Discrete values of output would also be interesting.

I suspect an display issue.

B O E.
Back to top
 
 
View Profile   IP Logged
SARAM
Junior Member
**
Offline



Posts: 12

Re: Sample rate conversion
Reply #4 - Sep 14th, 2011, 11:41pm
 
Thanks B O E

Attached, you can see what you asked.
I just increase the CLK_h by factor of 2 in this figure.

if this is display problem how can i make sure the number of samples at the output were increased? I can not see the symbol in between of two low rate clk that sampled with high rate.


Regards
Back to top
 

Screenshot-2_003.png
View Profile   IP Logged
boe
Community Fellow
*****
Offline



Posts: 615

Re: Sample rate conversion
Reply #5 - Sep 15th, 2011, 3:54am
 
SARAM,
This plot seems OK to me. Note that this is digital simulation; you don't get time points unless the value changes.

B O E
Back to top
 
 
View Profile   IP Logged
SARAM
Junior Member
**
Offline



Posts: 12

Re: Sample rate conversion
Reply #6 - Sep 15th, 2011, 4:44am
 
Hi BOE,

You mean that by this way I increased data samples at the output in ZOH manner.

another question is that how can i solve the problem with linear interpolation. (first code i have written at my first post). what can i do when two clock are async.

how can i implement linear interpolation? is there another way to implement with two async clock?

Regards,
Back to top
 
 
View Profile   IP Logged
boe
Community Fellow
*****
Offline



Posts: 615

Re: Sample rate conversion
Reply #7 - Sep 15th, 2011, 8:30am
 
Hi SARAM,
I suggest you store time ($realtime) of last slow edge and check that frq/frq1 are correct. Look for two things:
  • correct period (e.g. due to rounding error on OSR_1), and
  • no offset between frq/frq1 and relative position to clocks ("offset").
B O E
Back to top
 
 
View Profile   IP Logged
Pages: 1
Send Topic Print
Copyright 2002-2024 Designer’s Guide Consulting, Inc. Designer’s Guide® is a registered trademark of Designer’s Guide Consulting, Inc. All rights reserved. Send comments or questions to editor@designers-guide.org. Consider submitting a paper or model.