Multirate Signal Processing Lecture 7, Sampling

3m ago
751.33 KB
27 Pages

Multirate Signal ProcessingLecture 7,SamplingGerald Schuller, TU Ilmenau(Also see: Lecture ADSP, Slides 06)In discrete, digital signal we use the normalized frequency, T / f s : it is without a physical unit, since the unit Hertz in ω and f scancel. In the normalized frequency 2 represents thesampling frequency and π is the so called Nyquist frequency(the upper limit of our usable frequency range, defined ashalf the sampling frequency). Observe that we use the capital to signify that this is the normalized frequency. Thecapitalized version is commonly used to distinguish it fromthe continuous, non-normalized, version, if both are used.Otherwise, also the small is used in the literature, for thenormalized frequency, if that is all we need, if there is nodanger of confusion, as we did before.Its spectrum or frequency response is then X x n e j nn Because n is integer here, we get a 2π periodicity forX . This is the first important property for discrete timesignals.

Here we can see that in general we obtain a 2 periodicityin the frequency domain, because of the 2 periodicity ofthe exponential function e j ω .The above transform is called the Discrete Time Fouriertransform or DTFT (not the Discrete Fourier Transform, whichis for finite or periodic discrete time sequences. Here we stillhave an infinite “block length”).Also observe that for real valued signals, the spectrum of thenegative frequencies is the conjugate complex of the positivefrequencies,X ( Ω ) X * (Ω )where * denotes the conjugate complex operation, becausee j n e j n * .(we also have to use the fact that the conjugate complex of areal valued signal does not change it, to draw the conjugationout of the Fourier sum).This also means that for real valued signals we only need tolook at the frequency range between 0 and π , since the

negative frequencies are conjugate symmetric (and becauseof the 2pi periodicity the range between -pi and pi is sufficientto look at). This is also again what the Nyquist Theorem tellsus, that the frequencies between 0 and π (the Nyquistfrequency) are sufficient to completely describe a (realvalued) signal.Sampling a discrete time signalSo what happens if we further downsample an alreadydiscrete signal x(n), to reduce its sampling rate?Downsampling by N means we only keep every Nth sampleand discard every sample in between. Observe that thisresults in a normalized frequency which is a factor of Nhigher.This downsampling process can also be seen as firstmultiplying the signal with a sequence of unit pulses (a 1 ateach sample position), zeros in between, and later droppingthe zeros. This multiplication with the unit pulse train cannow be used to mathematically analyse this downsampling,looking at the resulting spectra, first still including the zeros.The frequency response now becomesX d x n e j nn mN m for all integers m.x mN e j mN

We can write down-sampling as amultiplication of the signal with a samplingfunction. In continuous time it was thesequence of Dirac impulses, here it is asequence of unit pulses at positions ofmultiples of N,Δ N ( n ) 1 , i f n m N0, e l s eThen the sampled signal, with the zeros stillin it, becomesdx ( n ) x ( n ) Δ N ( n)This signal is now an intermediate signal,which gets the zeros removed beforetransmission or storage, to reduce theneeded data rate. The decoder upsamples itby re-inserting the zeros to obtain theoriginal sampling rate.Observe that this is then also the signal thatwe obtain after this upsampling in thedecoder. Hence this signal looks interestingto us, because it appears in the encoder andalso in the decoder.What does its spectrum or frequencyresponse look like?()The derivation can be found in lecture ADSP,slides 06, sampling.It shows that sampling, still including thezeros, leads (in the frequency domain) tomultiple shifted versions of the signal

spectrum, the so-called aliasingcomponents,N 11 2 dX X k (eq.1)N k 0NSignal /NpifrequencyAliasing componentsObserve: The spectral components don'toverlap if their bandwidths is below 2 π / Nfor complex signals, or for a real low passsignal, it should be below π / N ! If we wantto reconstruct the original signal, hence weneed to make sure the aliasing componentsdon't overlap by suitable filtering at the highsampling rate, to prepare for the downsampling. Observe that the term „Aliasing“in the literature is sometime only used foroverlapping alias components, andsometimes more broadly, like we do here, tomean any additional shifted frequencycomponent.

Next is another example, also including thenegative frequencies that now show upabove normalized frequency 1 (1 being theNyquist frequency here), and showing 2 sinesignals at different strength at normalizedfrequencies 0.4 and 0.35. This can also beseen as a narrow band signal, resulting e.g.from a passband filter.After sampling by a factor of N 4, stillincluding the zeros, we get the followingspectrum:

Spectral CopiesoriginalPos. FrequenciesoriginalNeg. FrequenciesThe picture shows that the spectrum stillcontains the original spectrum, plus thespectral copies at frequency shifts ofk 2 π / N from the originals.Observe: Since we have a real valued signal(the sinusoids), the spectrum of negativeand positive frequencies are symmetricaround frequency zero. This then leads tothe mirrored appearance between theneighbouring spectral images or aliasingcomponents.

BTW, Nyquist tells us to sample in such away, that the shifted spectra of our signal donot overlap. Otherwise, if they overlap, wecannot separate those parts of the spectrumanymore, and we loose information, whichwe cannot reconstruct.In conclusion: Sampling a signal by a factorof N, with keeping the zeros between thesample points, leads to N-1 aliasingcomponents.Example:Make a sine wave which at 44100 Hzsampling rate has a frequency of 400 Hz at 1second duration. Hence we need 44100samples, and 400 periods of our sinusoid inthis second. Hence we can write our signalin Python as:ipython --pylabfs 44100f 400.0s sin(2*pi*f*arange(0,1,1.0/fs))To listen to it, we use our sound library„“, which you can find on ourMoodle Webpage:from sound import soundsound((2**15)*s,fs)

Now plot the first 1000 samples:plot(s[0:1000])Next plot the first 100 samples:plot(s[0:100])

Now we can multiply this sine tone signalwith a unit pulse train, with N 8.We generate the unit impulse train,unit zeros(44100)unit[0::8] nit(n)')

Listen to it, with scaling to the value rangefor 16 bit/sample:from sound import soundsound(unit*2.0**15,44100)The multiplication with the unit impulsetrain:sdu s*unit(This multiplication is also called „frequencymixing“).Now plot the result, the first 100 samples:plot(sdu[0:100])

This is our signal still with the zeros in it.Now take a look at the magnitude spectrum(in dB) of the original signal s:from scipy.signal import freqzw,H freqz(s)plot(w, 20*log10(abs(H) ude Frequency Response')

The plot shows the magnitude of thefrequency spectrum of our signal. Observethat the frequency axis (horizontal) is anormalized frequency, normalized to theNyquist frequency as π , in our case 22050Hz. Hence our sinusoid should appear as apeak at normalized frequency400.0/22050*pi 0.05699, which we indeedsee.Now we can compare this to our signal withthe zeros, sdu:w,H freqz(sdu)plot(w, 20*log10(abs(H) 1e-3))

legend(('Original Sinusoid','SampledSinusid'))Here we can see the original line of our 400Hz tone, and now also the 7 new aliasingcomponents. Observe that always 2 aliasingcomponents are close together. This isbecause the original 400 Hz tone also has aspectral peak at the negative frequencies, at-400 Hz, or at normalized frequency 0.05699.Now also listen to the signal with the zeros:sound(2**15*sdu,44100);

Here you can hear that it sounds quitedifferent from the original, because of thestrong aliasing components!Python real time audio example: Thisexample takes the microphone input andsamples it, without removing the zeros, andplays it back the the speaker in real time.It constructs a unit pulse train, with a 1 atevery N'th sample, using the modulusfunction „%“,s (np.arange(0,CHUNK)%N) 0Start it with:python pyrecplay samplingblock.pyRemoving the zerosThe final step of downsampling is now toomit the zeros between the samples, toobtain the lower sampling rate. Let's call thesignal without the zerosy(m),where the time index m denotes the lowersampling rate (as opposed to n, whichdenotes the higher sampling rate).In our Python example this is:sd sdu[0:44100:8]plot(sd[0:(100/8)])

We can now take a look at the spectrum withw,H freqz(sd)plot(w, 20*log10(abs(H) ude Frequency Response')

Observe that the sine signal now appear atnormalized frequency of 0.455, a factor of8 higher than before, with the zeros in it,because we reduced the sampling rateby 8. This is because we now have a newNyquist frequency of 22050/8 now, henceour normalized frequency becomes400 3.14/22050 8 0.455 . This meansremoving the zeros scales or stretches ourfrequency axis.

Observe that here we only have 100/8 12samples left.How are the frequency responses or spectraof y m and x d n connected? We cansimply take the Fourier transforms of them,dX x d n e j nn still with the zeros in it. Hence most of thesum contains only zeros. Now we only needto let the sum run over the non-zeros entries(only every Nth entry), by replacing n bymN, and we getX d x d n e j n ,n mNfor all integer m, now without the zeros. Nowwe can make the connection to the Fouriertransform of y(m), by making the indexsubstitution m for n in the sum,dX y m e j N m Y N m This is now our result. It shows that thedownsampled version (with the removal ofthe zeros), has the same frequencyresponse, but the frequency variable isscaled by the factor N. For instance, thenormalized frequency / N beforedownsampling becomes after removingthe zeros! It shows that a small part of thespectrum before downsampling becomes thefull usable spectrum after downsampling.

Observe that we don't loose any frequenciesthis way, because by looking at eq. (1) wesee that we obtain multiple copies of thespectrum in steps of 2 / N , and hence thespectrum already has a periodicity of 2 / N. This means that the spectrum between / N and / N for instance (we could takeany period of length 2 / N ) contains aunique and full part of the spectrum,because the rest is just a periodiccontinuation.This can be seen in following pictures,Figure 1: The magnitude spectrum of asignal. The 2 boxes symbolize the passbandof an ideal bandpass, here a high pass.

Figure: The signal spectrum after passingthrough the high pass.Figure: Signal spectrum after multiplicationwith the unit pulse train, for N 2, hencesetting every second value to zero (the zerosstill in the sequence). Observe the we shiftand add the signal by multiples of 2 / 2 ,and in effect we obtain „mirrored“ images ofthe high frequencies to the low frequencies(since we assume a real valued signal).Observe that the mirrored spectra and the

original spectrum don't overlap, whichmakes reconstruction easy.Figure: Signal spectrum after downsampling(removing the zeros) by N (2 in thisexample). Observe the stretching of thespectrum by a factor of 2.UpsamplingWhat is still missing in our system is theupsampling, as the opposite operation ofdownsampling, for the case where we wouldlike to increase our sampling rate. One ofthe first (wrong!) approaches to upsamplingthat often comes to mind if we want to doupsampling by a factor of N, is to simplyrepeat every sample N-1 times. But this isequivalent to first inserting N-1 zeros aftereach sample, and then filter the resulting

sequence by a low pass filter with animpulse response of N ones. This is a veryspecial case, and we would like to have amore general case. Hence we assume thatwe upsample by always first inserting N-1zeros after each sample, and then havesome interpolation filter for it. Again we takethe signal at the lower sampling rate asy m with index m for the lower sampling rate,and the signal at the higher sampling rate,with the zeros in it, asx d n with index n for the higher sampling rate.Here we can see that this is simply thereverse operation of the final step ofremoving the zeros for the downsampling.Hence we can take our result fromdownsampling and apply it here:X d Y N orX d (Ω/ N ) Y (Ω)We are now just coming from y(m), going tothe now upsampled signal x d n .For instance if we had the frequency before upsampling, it becomes / 2 for theupsampled signal, if we have N 2. In thisway we now get an „extended“ frequencyrange.

Since we now have again the signalincluding the zeros, x d n , we again havethe periodic spectrum, as before, as weprogress through the same steps backwardsnow. We can also see that the result ofupsampling is periodic in frequency, becausethe signal was 2 periodic beforeupsampling anyway, and after upsamplingthe frequency scale replaces 2 N by 2 .ReconstructionObserve that if the aliasing componentsdon't overlap, we can perfectlyreconstruct the signal by using a suitablefilter. We can make sure that they don'toverlap by filtering the signal at the highersampling rate, before they can overlap. Ifthey already overlap at the lower samplingrate, it would be too late to separate thedifferent components, the signal wouldalready be „destroyed“.

We can perfectly reconstruct the high passsignal in our example if we use ideal filters,using upsampling and ideal high passfiltering.In this way we have for the analysis andsynthesis the following pictureObserve that we violate the con