DSPRelated.com
Forums

Need help

Started by Medris March 8, 2006
I want to know what is the mistake in my code below which I used to get
Mother Wavelet in CCs,and by the same code I can get Mother Wavelet using
Matlab.


code in CCS:

int i = 0;                  	    			
float morlet[1024];
int sgm = 64;
float t;				
float f = 1000;
double ts = 1/128;
 

interrupt void c_int11()            		//interrupt service routine
{
  t = -512*ts;
 	for(i=0;i<1024;i++)	// Compute Mother Wavelet (Morlet).
  	{
   		morlet[i] =
((cos(6.283185*t*f)+sin(6.283185*t*f))*exp(-1.0*t*f*t*f/(2.0*sgm*sgm)))/(sgm*2.5066);
   	t = t + ts;
   	}
    
  return;	//return from interrupt										
}
  
void main()
{
  comm_intr(); 
         				//init DSK, codec, McBSP
  while(1);                      	//infinite loop
}
 


Code in MatLab:

f = 1000;
sigma = 64;
dt=1/128;

%max = 0.0001;

    t = -512*dt;
    
    for i=1:1:1024
       
morlet(i)=(cos(6.283185*t*f)+sin(6.283185*t*f))*exp(-1.0*t*f*t*f/(2.0*sigma*sigma))/(sigma*2.5066);
        t=t+dt;
        figure(1)
        plot(morlet)
    end
      
  Please help thank you.  



Medris wrote:
> I want to know what is the mistake in my code below which I used to get > Mother Wavelet in CCs,and by the same code I can get Mother Wavelet using > Matlab. > > > code in CCS: > > int i = 0; > float morlet[1024]; > int sgm = 64; > float t; > float f = 1000; > double ts = 1/128; > > > interrupt void c_int11() //interrupt service routine > { > t = -512*ts; > for(i=0;i<1024;i++) // Compute Mother Wavelet (Morlet). > { > morlet[i] = > ((cos(6.283185*t*f)+sin(6.283185*t*f))*exp(-1.0*t*f*t*f/(2.0*sgm*sgm)))/(sgm*2.5066); > t = t + ts; > } > > return; //return from interrupt > } > > void main() > { > comm_intr(); > //init DSK, codec, McBSP > while(1); //infinite loop > } > > > > Code in MatLab: > > f = 1000; > sigma = 64; > dt=1/128; > > %max = 0.0001; > > t = -512*dt; > > for i=1:1:1024 > > morlet(i)=(cos(6.283185*t*f)+sin(6.283185*t*f))*exp(-1.0*t*f*t*f/(2.0*sigma*sigma))/(sigma*2.5066); > t=t+dt; > figure(1) > plot(morlet) > end > > Please help thank you.
First of all, you didn't tell us what was wrong with it. Please clarify. Second, why are you using interrupts for this? Try getting the code working in main() without the headaches of interrupt processing, then move it into your real code. Third, I notice that you are using floats but that you call double functions. Could the problem be precision related? Which processor are you using? Finally, your subject line is not very descriptive. A more accurate subject line might get you more responses. Cheers! --M
>Medris wrote: >> I want to know what is the mistake in my code below which I used to
get
>> Mother Wavelet in CCs,and by the same code I can get Mother Wavelet
using
>> Matlab. >> >> >> code in CCS: >> >> int i = 0; >> float morlet[1024]; >> int sgm = 64; >> float t; >> float f = 1000; >> double ts = 1/128; >> >> >> interrupt void c_int11() //interrupt service routine >> { >> t = -512*ts; >> for(i=0;i<1024;i++) // Compute Mother Wavelet (Morlet). >> { >> morlet[i] = >>
((cos(6.283185*t*f)+sin(6.283185*t*f))*exp(-1.0*t*f*t*f/(2.0*sgm*sgm)))/(sgm*2.5066);
>> t = t + ts; >> } >> >> return; //return from interrupt >> } >> >> void main() >> { >> comm_intr(); >> //init DSK, codec, McBSP >> while(1); //infinite loop >> } >> >> >> >> Code in MatLab: >> >> f = 1000; >> sigma = 64; >> dt=1/128; >> >> %max = 0.0001; >> >> t = -512*dt; >> >> for i=1:1:1024 >> >>
morlet(i)=(cos(6.283185*t*f)+sin(6.283185*t*f))*exp(-1.0*t*f*t*f/(2.0*sigma*sigma))/(sigma*2.5066);
>> t=t+dt; >> figure(1) >> plot(morlet) >> end >> >> Please help thank you. > >First of all, you didn't tell us what was wrong with it. Please >clarify. Second, why are you using interrupts for this? Try getting the >code working in main() without the headaches of interrupt processing, >then move it into your real code. Third, I notice that you are using >floats but that you call double functions. Could the problem be >precision related? Which processor are you using? Finally, your subject >line is not very descriptive. A more accurate subject line might get >you more responses. > >Cheers! --M > >
Thanks for your reply, actually there is no error in the code but I couldn't get the mother wavelet signal in the same time I can get the signal using same code in MatLab. I am using DSK 6711 in my work About the interrupt , in fact this code is apart of my main code so just I want to get the wavelet signal. Regards. Mohamed.
Medris wrote:
> mlimber wrote: > >First of all, you didn't tell us what was wrong with it. Please > >clarify. Second, why are you using interrupts for this? Try getting the > >code working in main() without the headaches of interrupt processing, > >then move it into your real code. Third, I notice that you are using > >floats but that you call double functions. Could the problem be > >precision related? Which processor are you using? Finally, your subject > >line is not very descriptive. A more accurate subject line might get > >you more responses. > > > >Cheers! --M > > > > Thanks for your reply, actually there is no error in the code but I > couldn't get the mother wavelet signal in the same time I can get the > signal using same code in MatLab. I am using DSK 6711 in my work
What do you mean "in the same time"? The computation on the DSP is slower? The time scale is off? Please elaborate more. If it's not related to efficiency of computation, please show us some numbers of the broking and working versions.
> About the > interrupt , in fact this code is apart of my main code so just I want to > get the wavelet signal.
Right, but my point was that you should try to get the wavelet generation working (at an acceptable speed) apart from your real code and then integrate it. This is just the tried-and-true divide and conquer approach. Cheers! --M