kamil khoury
Newbie level 3
![Newbie level 3](/styles/images/ranks/alevel3.gif)
Can anyone provide me with these two codes (it's really important to me):
a. a code to generate a square wave (by an unstable filter) using DSP.
b. a code to generate a triangular wave (by an unstable filter) using DSP.
thank you so much for help![Smile :) :)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
the following code generates a sine wave in the same way (I don't know if this code can help) :
#include "Config1cfg.h"
#include "dsk6713_aic23.h"
#include "dsk6713.h"
#include "math.h"
/* Codec configuration settings */
DSK6713_AIC23_Config config = {
0x0017, /* 0 DSK6713_AIC23_LEFTINVOL Left line input channel volume */ \
0x0017, /* 1 DSK6713_AIC23_RIGHTINVOL Right line input channel volume */\
0x00d8, /* 2 DSK6713_AIC23_LEFTHPVOL Left channel headphone volume */ \
0x00d8, /* 3 DSK6713_AIC23_RIGHTHPVOL Right channel headphone volume */ \
0x0011, /* 4 DSK6713_AIC23_ANAPATH Analog audio path control */ \
0x0000, /* 5 DSK6713_AIC23_DIGPATH Digital audio path control */ \
0x0000, /* 6 DSK6713_AIC23_POWERDOWN Power down control */ \
0x0043, /* 7 DSK6713_AIC23_DIGIF Digital audio interface format */ \
0x0081, /* 8 DSK6713_AIC23_SAMPLERATE Sample rate control */ \
0x0001 /* 9 DSK6713_AIC23_DIGACT Digital interface activation */ \
};
void main()
{
DSK6713_AIC23_CodecHandle hCodec;
/* Start the codec */
float u0=1;
int i,n;
float size=10000;
float y[10000];
float fs=16000, ts=(1/fs),f=1300;
float a= 2*cos(360*f*ts), b=-1 , c=sin(360*f*ts);
y[2]=0;
y[1]=2;
y[0]=3;
for(n=2;n<size;n++)
{
y[n]=a*y[n-1]+b*y[n-2]+c*u0;
u0=0;
}
/* Initialize the board support library, must be called first */
DSK6713_init();
hCodec = DSK6713_AIC23_openCodec(0, &config);
for (i = 0; i < size; i++)
{
/* Send a sample to the left channel */
while (!DSK6713_AIC23_write(hCodec,(Int16)y));
/* Send a sample to the right channel */
while (!DSK6713_AIC23_write(hCodec, (Int16)y));
}
DSK6713_AIC23_closeCodec(hCodec);
}
a. a code to generate a square wave (by an unstable filter) using DSP.
b. a code to generate a triangular wave (by an unstable filter) using DSP.
thank you so much for help
the following code generates a sine wave in the same way (I don't know if this code can help) :
#include "Config1cfg.h"
#include "dsk6713_aic23.h"
#include "dsk6713.h"
#include "math.h"
/* Codec configuration settings */
DSK6713_AIC23_Config config = {
0x0017, /* 0 DSK6713_AIC23_LEFTINVOL Left line input channel volume */ \
0x0017, /* 1 DSK6713_AIC23_RIGHTINVOL Right line input channel volume */\
0x00d8, /* 2 DSK6713_AIC23_LEFTHPVOL Left channel headphone volume */ \
0x00d8, /* 3 DSK6713_AIC23_RIGHTHPVOL Right channel headphone volume */ \
0x0011, /* 4 DSK6713_AIC23_ANAPATH Analog audio path control */ \
0x0000, /* 5 DSK6713_AIC23_DIGPATH Digital audio path control */ \
0x0000, /* 6 DSK6713_AIC23_POWERDOWN Power down control */ \
0x0043, /* 7 DSK6713_AIC23_DIGIF Digital audio interface format */ \
0x0081, /* 8 DSK6713_AIC23_SAMPLERATE Sample rate control */ \
0x0001 /* 9 DSK6713_AIC23_DIGACT Digital interface activation */ \
};
void main()
{
DSK6713_AIC23_CodecHandle hCodec;
/* Start the codec */
float u0=1;
int i,n;
float size=10000;
float y[10000];
float fs=16000, ts=(1/fs),f=1300;
float a= 2*cos(360*f*ts), b=-1 , c=sin(360*f*ts);
y[2]=0;
y[1]=2;
y[0]=3;
for(n=2;n<size;n++)
{
y[n]=a*y[n-1]+b*y[n-2]+c*u0;
u0=0;
}
/* Initialize the board support library, must be called first */
DSK6713_init();
hCodec = DSK6713_AIC23_openCodec(0, &config);
for (i = 0; i < size; i++)
{
/* Send a sample to the left channel */
while (!DSK6713_AIC23_write(hCodec,(Int16)y));
/* Send a sample to the right channel */
while (!DSK6713_AIC23_write(hCodec, (Int16)y));
}
DSK6713_AIC23_closeCodec(hCodec);
}