Other Parts Discussed in Thread: TMS320C5505
I'm working on a project where i'm going to be implementing some distortion modeling on a TMS320C5505 eZDSP. My first attempt at implementing a simple hard-clipping algorithm produced some unexpected results that i'm stumped by. I know this might be a lengthy read, but if you have the time I could really use the help. I'll layout the process of exactly how i've attempted to do some debugging.
First, i connected my laptop (headphone out) to another laptop (mic
in) and passed a 440 Hz sine wave (generated in Audacity) from the first
laptop to the second and no irregularities or additional harmonics in
the recorded signal's spectrum could be seen, sans a minor dB difference
level. I repeated this process using white noise and the results were
the same (no irregularities).
Next, i repeated the exact same process, but this time i ran the
laptop headphone out into the DSP's analog input and the DSP's headphone
out to the other laptop's input and recorded the same 440 Hz and
whitenoise signals. I used the stock Audio Filter Demo and I modified the timer to just keep the filter off for the entire duration. So, the FIR Filter was bypassed for these tests and the input signal
passed completely through the DSP without any alterations. The results
were the same as in the first procedure.
Then, with the both laptops still connected to the DSP, I turned the
hard-clipping algorithm to be implemented on the DSP on. Here is that
exact section of code that was implemented:
void distalgo(Int16 *input, Int16 *output, Int16 size)
{
Int16 i;
Int16 threshp = 600; // Threshold for Hard-Clipping
Int16 threshn = -600; // Threshold for Hard-Clipping
for(i =0; i<size; i++)
{
if(*(input+i) >= threshp){
*(output+i) = threshp;
}
else if(*(input+i) <= threshn){
*(output+i) = threshn;
}
else {
*(output + i) = *(input +i);
}
}
}
This code is implemented when the filterON variable is set to 1 (in place of the FIR Filter) and i followed a similar implementation as the buff_copy function that just passes the data in and out without alteration.
I
passed the 440 Hz signal through this algorithm and the I/O waveforms
can be seen in the attached figure iocomp.png.

On a closer inspection, iozoom.png, you can see that the input waveform is not being completely limited to the threshold of 600 (Green line) and -600 (blue line), but closer to 800 and -800. It also appears to have some oscillations or noise mixed in because it isn't completely being hard-clipped.

I also passed that same input data through the same algorithm, but in MATLAB and the resulting output can be seen in the figure comp3.png. This shows what the the DSP should have done.

I also passed each of those signals (440 Hz input, DSP Hard-Clipped
output, and matlab clipped output) through an averaged FFT tool. Here are the resulting spectrums:



The input spectrum is a fairly clean representation of the 440 Hz
sine. The DSP output spectrum (440out) is showing odd harmonics AND even
harmonics, even though the even harmonics are almost 30 dB less than
the fundamental and neighboring odd harmonics. This clipped waveform
should only be generating odd harmonics, which can be seen, as
verification, in the MATLAB440 spectrum.
So, like i said, i'm kind of stumped. I have a feeling that it has
something to do with the way i'm calling or implementing the algorithm
on the DSP, but i'm not sure what part of it could be causing this.
If you have any suggestions i'd love to hear them.
Thanks for reading!


