Hi,
As a first step into the wonderful and time consuming world of DSP<=>Chuck I want to make audible the effect of disregarding the sampling theorem. So all I'm trying to do at the moment is creating a simple down-sampler without any proper filtering. As it is said in the sampling theorem this should not create any distortion as long as my new sampling rate is at least twice as high as the highest sine wave in my input signal. However, when I'm sampling down a sine wave of for example 440 Hz in Chuck, I get a lot of funny noises long before going down to a SR of 880 Hz.
For example:
SinOsc inputSignal;
Step stepSeq;
inputSignal => blackhole;
stepSeq=> dac;
440 => inputSignal.freq;
0.5 => inputSignal.gain;
//takin every nTh sample of the inputSignal
10 => int n;
<<<"real sample rate: " + 1::second/1::samp>>>;
<<<"new sample rate: " + 1::second/(1::samp*n)>>>;
//duration of the output signal
1::second => dur durationOfTest;
now + durationOfTest => time timeToFinish;
//don't-care-about-Nyquist-downsampling
while (now < timeToFinish) {
inputSignal.last() => stepSeq.next;
n::samp => now;
}
By using a common sample-rate like e.g. 44100 Hz in Chuck this should satisfy the sampling theorem. I guess the reason, why I doesn't get a nice 440-sine wave here is because I have to reconstruct the sine wave after the down sampling with the remaining samples, as the output cannot know that they are part of a proper sine wave. Is this right? If yes, could someone give me a hint how to realize something like this? Of not, what is the real problem? My target is a downsampler which for example would produce an undistorted sine wave of 440 Hz after downsampling to 880 Hz (i.e. a working demonstration of the sampling theorem)
A second and a bit stupid question: As far as I understand it, it is not possible to downsample a signal with a given SR to any new SR, but only to a new SR which is = (Old SR)/N, whereas N is a simple positive number (of course after converting the new SR to integer). Did I get this right?
OK, I would be very grateful if someone could give me a hint or two. I => bed, have a nice day!
Jakob