• Simulation of Aliasing

    From richardson.tony@gmail.com@21:1/5 to All on Mon Jul 6 08:04:20 2020
    I ran across a problem in a DSP book that got me to thinking (the best kind of problem). The author suggests that we can illustrate aliasing by sampling an audio signal at a high frequency and then replacing samples with zeroes to get a lower effective
    sampling frequency. For example, if we sample at fs1 = 32 kHz and then keep every M = 4th sample (replacing the other samples with zeroes) then the resulting signal is equivalent to sampling at fs2 = 8 kHz (fs1/M).

    I agree that aliasing is present (if the original signal has content above 4 kHz), but if you play the new signal back at 32 kHz you will also hear "replica" distortion. To get a better sense of just aliasing due to sampling at 8 kHz you should low pass
    filter the new signal with a cutoff frequency of 4 kHz (fs2/2 or fs1/(2M)).

    The process appears to be the same as down-sampling (without an anti-aliasing filter, since the goal is to demonstrate aliasing) followed by up-sampling at the same rate. I think you still need to follow the up-sampler with a low-pass (replica
    elimination) filter to generate a signal that when played back at 32 kHz sounds the same as sampling (and replaying) the original analog signal at 8 kHz (without using an anti-aliasing filter).

    Note: I am not arguing that the author is wrong. I am just looking for verification that my thinking is correct (or not). The problem is presented very early in the book (and it is a very good book) before filtering is even discussed. He says that this
    zero-replacement method will illustrate distortion due to aliasing. He does not say that it is exactly equivalent to the signal that would be obtained by sampling at the lower rate without an anti-aliasing filter. It just got me to thinking about a
    better way (perhaps) to demonstrate only aliasing.

    Tony

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From gah4@u.washington.edu@21:1/5 to richard...@gmail.com on Mon Jul 6 10:30:36 2020
    On Monday, July 6, 2020 at 8:04:23 AM UTC-7, richard...@gmail.com wrote:
    I ran across a problem in a DSP book that got me to thinking
    (the best kind of problem).
    The author suggests that we can illustrate aliasing by sampling an
    audio signal at a high frequency and then replacing samples with zeroes
    to get a lower effective sampling frequency. For example, if we
    sample at fs1 = 32 kHz and then keep every M = 4th sample
    (replacing the other samples with zeroes) then the resulting signal
    is equivalent to sampling at fs2 = 8 kHz (fs1/M).

    I agree that aliasing is present (if the original signal has content
    above 4 kHz), but if you play the new signal back at 32 kHz you will
    also hear "replica" distortion. To get a better sense of just aliasing
    due to sampling at 8 kHz you should low pass filter the new signal
    with a cutoff frequency of 4 kHz (fs2/2 or fs1/(2M)).

    Without getting too much detail, it does seem like two different things.

    I didn't know the name "replica distortion" before.

    Another choice is to generate four copies of every fourth sample.

    I think you should try them all and see what they sound like.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From richardson.tony@gmail.com@21:1/5 to ga...@u.washington.edu on Mon Jul 6 11:03:16 2020
    On Monday, July 6, 2020 at 12:30:41 PM UTC-5, ga...@u.washington.edu wrote:
    On Monday, July 6, 2020 at 8:04:23 AM UTC-7, richard...@gmail.com wrote:
    I ran across a problem in a DSP book that got me to thinking
    (the best kind of problem).
    The author suggests that we can illustrate aliasing by sampling an
    audio signal at a high frequency and then replacing samples with zeroes
    to get a lower effective sampling frequency. For example, if we
    sample at fs1 = 32 kHz and then keep every M = 4th sample
    (replacing the other samples with zeroes) then the resulting signal
    is equivalent to sampling at fs2 = 8 kHz (fs1/M).

    I agree that aliasing is present (if the original signal has content
    above 4 kHz), but if you play the new signal back at 32 kHz you will
    also hear "replica" distortion. To get a better sense of just aliasing
    due to sampling at 8 kHz you should low pass filter the new signal
    with a cutoff frequency of 4 kHz (fs2/2 or fs1/(2M)).

    Without getting too much detail, it does seem like two different things.

    I didn't know the name "replica distortion" before.

    Another choice is to generate four copies of every fourth sample.

    I think you should try them all and see what they sound like.

    Oh, I have tried it. With a 400 Hz tone and original sampling at 32 kHz and then reducing the sample rate to 2 kHz you can hear the 1600 Hz replica. There are spectral lines at (n*2000 +- 400). If you reduce the sample rate to 500 Hz you can hear an
    alias at 100 Hz. The spectral lines are at (n*500 +- 400). I am playing around with a replica elimination filter now so that I only hear the distortion due to aliasing. The goal is to produce a signal that would sound the same as an undersampled signal.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From richardson.tony@gmail.com@21:1/5 to richard...@gmail.com on Mon Jul 6 11:07:10 2020
    On Monday, July 6, 2020 at 1:03:21 PM UTC-5, richard...@gmail.com wrote:
    On Monday, July 6, 2020 at 12:30:41 PM UTC-5, ga...@u.washington.edu wrote:
    On Monday, July 6, 2020 at 8:04:23 AM UTC-7, richard...@gmail.com wrote:
    I ran across a problem in a DSP book that got me to thinking
    (the best kind of problem).
    The author suggests that we can illustrate aliasing by sampling an
    audio signal at a high frequency and then replacing samples with zeroes to get a lower effective sampling frequency. For example, if we
    sample at fs1 = 32 kHz and then keep every M = 4th sample
    (replacing the other samples with zeroes) then the resulting signal
    is equivalent to sampling at fs2 = 8 kHz (fs1/M).

    I agree that aliasing is present (if the original signal has content above 4 kHz), but if you play the new signal back at 32 kHz you will
    also hear "replica" distortion. To get a better sense of just aliasing due to sampling at 8 kHz you should low pass filter the new signal
    with a cutoff frequency of 4 kHz (fs2/2 or fs1/(2M)).

    Without getting too much detail, it does seem like two different things.

    I didn't know the name "replica distortion" before.

    Another choice is to generate four copies of every fourth sample.

    I think you should try them all and see what they sound like.

    Oh, I have tried it. With a 400 Hz tone and original sampling at 32 kHz
    and then reducing the sample rate to 2 kHz you can hear the 1600 Hz
    replica. There are spectral lines at (n*2000 +- 400). If you reduce the sample rate to 500 Hz you can hear an alias at 100 Hz. The spectral lines
    are at (n*500 +- 400). I am playing around with a replica elimination
    filter now so that I only hear the distortion due to aliasing. The goal is
    to produce a signal that would sound the same as an undersampled signal.

    The Octave/MATLAB code for this is below:

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % This procedure is equivalent to down-sampling (without a LPF anti-aliasing
    % filter) followed by up-sampling (without a LPF anti-replica) filter.
    %
    % To truly hear only aliasing a LPF anti-replica filter should be used. %%%%%%%%%%%%%%%%%%%%%%%%%%%%

    f0 = 400;
    fs = 32000; % sample rate
    t = 2; % seconds

    xf = @(f0, fs, n) 0.75*sin(2*pi*f0*n/fs);
    n = (0:t*fs-1);

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%
    x = xf(f0, fs, n);
    X = fft(x);
    clf;
    subplot(3,2,1)
    plot((0:length(X)-1)*fs/length(X), 20*log10(abs(X)))
    xlim([0 5000])
    drawnow();
    player = audioplayer(x, fs);
    playblocking(player)

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%
    fsn = 2000;
    r = fs/fsn; % 16
    xn = zeros(size(x));
    xn(1:r:end) = x(1:r:end);
    X = fft(xn);
    subplot(3,2,3)
    plot((0:length(X)-1)*fs/length(X), 20*log10(abs(X)))
    xlim([0 5000])
    drawnow();
    player = audioplayer(xn, fs);
    playblocking(player)

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%
    fsn = 500;
    r = fs/fsn; % 64
    xn = zeros(size(x));
    xn(1:r:end) = x(1:r:end);
    X = fft(xn);
    subplot(3,2,5)
    plot((0:length(X)-1)*fs/length(X), 20*log10(abs(X)))
    xlim([0 5000])
    drawnow();
    player = audioplayer(xn, fs);
    playblocking(player)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From richardson.tony@gmail.com@21:1/5 to ga...@u.washington.edu on Mon Jul 6 11:38:35 2020
    On Monday, July 6, 2020 at 12:30:41 PM UTC-5, ga...@u.washington.edu wrote:
    On Monday, July 6, 2020 at 8:04:23 AM UTC-7, richard...@gmail.com wrote:
    I ran across a problem in a DSP book that got me to thinking
    (the best kind of problem).
    The author suggests that we can illustrate aliasing by sampling an
    audio signal at a high frequency and then replacing samples with zeroes
    to get a lower effective sampling frequency. For example, if we
    sample at fs1 = 32 kHz and then keep every M = 4th sample
    (replacing the other samples with zeroes) then the resulting signal
    is equivalent to sampling at fs2 = 8 kHz (fs1/M).

    I agree that aliasing is present (if the original signal has content
    above 4 kHz), but if you play the new signal back at 32 kHz you will
    also hear "replica" distortion. To get a better sense of just aliasing
    due to sampling at 8 kHz you should low pass filter the new signal
    with a cutoff frequency of 4 kHz (fs2/2 or fs1/(2M)).

    Without getting too much detail, it does seem like two different things.

    I didn't know the name "replica distortion" before.

    Another choice is to generate four copies of every fourth sample.

    I think you should try them all and see what they sound like.

    Generating four copies of every fourth sample would be equivalent to convolving the zeroed signal with a 4-sample rect pulse. in the frequency domain this would be equivalent to multiplying by a sinc whose first null is at the location of the first
    replica. I don't see this is being as effective in achieving my goal as a LP replica elimination filter. (The goal is to produce a signal which has the same spectrum as undersampling the original analog signal.)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)