Presentation is loading. Please wait.

Presentation is loading. Please wait.

Research Methods in Acoustics Lecture 8: Digital systems and filters

Similar presentations


Presentation on theme: "Research Methods in Acoustics Lecture 8: Digital systems and filters"— Presentation transcript:

1 Research Methods in Acoustics Lecture 8: Digital systems and filters
Jonas Braasch

2 Orthogonality Orthogonal (greek: orthos=straight/right, gonia=angle) is often used as synonym for perpendicular or right-angled. Two at 90° angle crossing streets are orthogonal to each other The dot-product of two vectors is zero if both vectors are orthogonal to each other.

3 Orthogonality Vector in 2- or 3-dimensional Euclidean space

4 Orthogonality Vector in 2- or 3-dimensional Euclidean space
Orthogonal case:

5 Orthogonality Vector in 2- or 3-dimensional Euclidean space angle:
Length of vector angle=1 parallel angle=0 orthogonal angle=-1 anti-parallel A unit vector has the length of one.

6 Orthogonality angle between two vectors angle between n·m

7 Orthogonality Vector in 2- or 3-dimensional Euclidean space a) a) b)
90° 90° b) c) c) d) 90° d) 45°

8 Digital Signals (Sampling)
samples The function y(t) is a continuous (analog) signal that we would like to transform into a digital signal. We can do this by measuring the value of the continuous signal at constant time intervals n·T (with n=0,1,2,3,…): Fs=48 kHz f=1000 Hz

9 Sampling Rate The sampling frequency (sampling rate fs or Fs) is defined as the number of samples that are recorded during a given time interval. The unit is typically [fs]=1/s or Hz. The sampling frequency is the inverse of the sampling interval T after which we recorded the next sample. Fs=48 kHz, f=1000 Hz, T=0.1 ms T time [s]

10 Example: Fs=48 kHz, f=1000 Hz time [s] samples

11 Fs=48 kHz, signal 30 kHz Fs=48 kHz, signal 20 kHz

12 Quantization In a digital signal, each sample is quantized to a new integer value. In computer systems, we transmit information using and on/off code instead of having decimal digits from 0−9 (Base 10). Internally, the computer only knows two digits 0 and 1 (Base 2). It operates on a binary code. One digit, which can be either 0 or 1 is called a bit. A group of 8 bits is referred to as one byte. We can easily transform a binary number into a number to the base 10: With x10 the number to the base 10 and x2,n the nth digit of the base-2 number. Example: x2=1011

13 Quantization The sampling frequency (sampling rate fs or Fs) is defined as the number of samples that are recorded during a given time interval. The unit is typically [Fs]=1/s or Hz. The sampling frequency is the inverse of the sampling interval T after which we recorded the next sample. 20*log10(256/2) =20*log10(2^8/2) = 20*log10(4096/2) =20*log10(2^12/2) = 20*log10(65536/2) =20*log10(2^16/2) = 20*log10( /2) =20*log10(2^24/2) = Divide by 2, because one bit is lost for the sign (plus or minus)

14 Conversion: Binary to Decimal
function [y]=convbin(x) numofdigits=floor(log2(x)); for n=numofdigits+1:-1:1 y(n)=mod(x,2); x=floor(x./2); end % of for

15 Binary Demo Demo Results: zdB =−10.6060 dB ydB = 31.4045 dB
x=randn(1000,1); x=abs(x); x=(128.*x./max(abs(x))); x0=round(x); for n=1:length(x0) y2=convbin(x0(n)); y(n)=convBase10(y2); end % of for z=y-x'; % level of signal yr=sqrt(mean(y.^2)); ydb=20*log10(yr) % quantization error dB zr=sqrt(mean(z.^2)); zdb=20*log10(zr) Demo Results: zdB =− dB ydB = dB ydB−zdB = dB Compare to the theoretical result of 20*log10(2^8/2)= dB

16 Theorems Nyquist–Shannon sampling theorem describes the conditions in which the continous signal can be perfectly reconstructed. If the conditions of the Nyquist–Shannon sampling theorem are met, the sampled signal can be reconstructed using the Whittaker–Shannon interpolation formula. Typically, the signal is bandwidth limited to fs/2 (Nyquist-Frequency). However, it is also possible to unambiguously code signals above this frequency, if the continuous signal is limited to a corresponding low-frequency cut-off frequency. This is often useful in radio broadcast.

17 Aliasing The effect that two different continuous signals to become indistinguishable when sampled is called aliasing. Aliasing typically occurs when a signals frequency is more the than twice the sampling frequency (see red curve). It then becomes an alias of a lower frequency (blue curve). An anti-aliasing filter, which is a low-pass filter is used to avoid this phenomenon. All frequencies above fs/2 are eliminated before they are converted into a digital signal.

18 Fourier Transformation with e-function
Basically, we can also treat non-harmonic functions by setting T to ∞. We can also use the complex e-function instead of sine and cosine: x=2pt, T→∞

19 Fourier Transformation of a sine signal
Fs=12000; t=0:1./Fs:1; % create time signals ffttabs=8182; f=(1./ffttabs:1./ffttabs:1).*Fs; x=sin(2*pi*1000*t); y=fft(x,ffttabs); plot(f,imag(y),'r:','LineWidth',2) hold on plot(f,real(y),'LineWidth',2) hold off ylabel('amplitude','FontSize',14); xlabel('frequency [Hz]','FontSize',14); set(gca, 'FontSize',14);

20 Samples vs. time and frequency
Fs=12000; t=0:1./Fs:1; % create time signals % choose 1./Fs as step size (equals one sample) % A similar approach for the frequency space ffttabs=8182; % number of frequency samples f=(1./ffttabs:1./ffttabs:1).*Fs; % We know that the whole frequency space ranges % from 0 to Fs

21 Fourier Transformation of sine signals
Imaginery component real component Real part, axis-symmetrical Imaginery part, point-symmetrical

22 Fourier Transformation of a cosine signal
Fs=12000; t=0:1./Fs:1; % create time signals ffttabs=8182; f=(1./ffttabs:1./ffttabs:1).*Fs; x=sin(2*pi*1000*t); x2=cos(2*pi*1000*t); y2=fft(x2,ffttabs); plot(f,real(y2),'LineWidth',2) hold on plot(f,imag(y2),'r:','LineWidth',2) hold off ylabel('amplitude','FontSize',14); xlabel('frequency [Hz]','FontSize',14); set(gca, 'FontSize',14);

23 Fourier Transformation of a cosine signal
real component Imaginery component Note, that now the real component has the larger peak

24 Power spectrum The amplitude of the Fourier signal can be estimated from the magnitude of the Fourier transformed signal H(w): We can also determine the power signal We used the following relationship

25 Power spectrum figure % Power spectrum % sine signal Pyy=y.*conj(y);
subplot(2,1,1); plot(f,Pyy,'LineWidth',2) ylabel('Power spectrum','FontSize',14); xlabel('frequency [Hz]','FontSize',14); set(gca, 'FontSize',14); % cosine signal Pyy2=y2.*conj(y2); subplot(2,1,2); plot(f,Pyy2,'r','LineWidth',2);

26 Power spectrum sine signal cosine signal

27 Phase The phase of the signal is the argument of the spectrum:

28 Phase p1 = atan2(imag(y), real(y)); p2 = atan2(imag(y2), real(y2));
phase1=180/pi*unwrap(p1); phase2=180/pi*unwrap(p2); figure plot(f,phase1,'LineWidth',2); hold on plot(f,phase2,'r:','LineWidth',2); plot(f,phase2-phase1,'g','LineWidth',2); hold off ylabel('phase [deg]','FontSize',14); xlabel('frequency [Hz]','FontSize',14); set(gca, 'FontSize',14);

29 Phase Blue=sine red=cosine Green=phase difference
Phase difference 1000 Hz

30 Fourier transformation of an impulse
x=zeros(length(t),1); x(1)=1; figure stem(x) ylabel('amplitude','FontSize',14); xlabel('time [samples]','FontSize',14); axis([ ]); set(gca, 'FontSize',14);

31 Impulse

32 Fourier transformation of an impulse
x=zeros(length(t),1); x(1)=1; x2=zeros(length(t),1); x2(8)=1; figure stem(x) ylabel('amplitude','FontSize',14); xlabel('time [samples]','FontSize',14); axis([ ]); set(gca, 'FontSize',14); stem(x2)

33 Impulse

34 Fourier Transformation
f=(1./ffttabs:1./ffttabs:1).*Fs; y=fft(x,ffttabs); y2=fft(x2,ffttabs); figure % Power spectrum Pyy=y.*conj(y); Pyy2=y2.*conj(y2); plot(f,Pyy,'LineWidth',2) hold on plot(f,Pyy,'r--','LineWidth',2) hold off ylabel('Energy','FontSize',14); xlabel('frequency [Hz]','FontSize',14); axis([ ]); set(gca, 'FontSize',14);

35 Magnitude Spectrum

36 Phase calculation p1 = atan2(imag(y), real(y));
phase1=180/pi*unwrap(p1); p2 = atan2(imag(y2), real(y2)); phase2=180/pi*unwrap(p2); figure plot(f,phase1,'LineWidth',2) hold on plot(f,phase2,'r--','LineWidth',2) hold off ylabel('phase [deg]','FontSize',14); xlabel('frequency [Hz]','FontSize',14); axis([ ]) set(gca, 'FontSize',14);

37 Phase

38 Phase and Group delay phase delay group delay

39 Group delay figure domega=pi*Fs/length(y); R=real(y); I=imag(y);
dI=derive(I,domega); dR=derive(R,domega); grpdelay=-(R.*dI-I.*dR)./(abs(y).^2); plot(f,grpdelay*Fs./2,'LineWidth',2)

40 Group delay (cont.) domega=pi*Fs/length(y2); R=real(y2); I=imag(y2);
dI=derive(I,domega); dR=derive(R,domega); grpdelay2=-(R.*dI-I.*dR)./(abs(y2).^2); hold on plot(f,grpdelay2*Fs./2,'r','LineWidth',2) hold off ylabel('group delay [in samples]','FontSize',14); xlabel('frequency [Hz]','FontSize',14); axis([ ]) set(gca, 'FontSize',14);

41 Group delay

42 Phase and Group delay 108° 72° Dy 36° 0° Dx 100 200 300 f [Hz]
Phase delay describes the overall delay of the phase Group delay describes the time delay compare to adjacent frequencies 108° tgr=dy/dx 72° Dy 36° tph=Dy/Dx Dx 100 200 300 f [Hz] phase delay group delay

43 What does linear phase mean?
T=1/f [ms] f=360° · t/T 108° 300 Hz 200 Hz 72° 100 Hz 36° 1ms

44 Linear phase 108° 72° 36° 0° 100 200 300 f [Hz]
Let us draw the values from the last slide: constant delay<->linear phase 108° 72° 36° 100 200 300 f [Hz]

45 Impulse Fs=12000; ffttabs=8182; x=FIR1(512,0.5,'low');
plot(x,'LineWidth',2); ylabel('amplitude','FontSize',14); xlabel('time [samples]','FontSize',14); set(gca, 'FontSize',14);

46 FIR low-pass filter (300 Hz), n=512

47 Magnitude spectrum f=(0:1./(ffttabs-1):1).*Fs; y=fft(x,ffttabs);
figure % Power spectrum Pyy=y.*conj(y); plot(f,Pyy,'LineWidth',2) ylabel('Energy','FontSize',14); xlabel('frequency [Hz]','FontSize',14); axis([ ]); set(gca, 'FontSize',14);

48 Magnitude spectrum

49 Phase p1 = atan2(imag(y), real(y)); phase1=180/pi*unwrap(p1); figure
plot(f,phase1,'LineWidth',2) ylabel('phase [deg]','FontSize',14); xlabel('frequency [Hz]','FontSize',14); set(gca, 'FontSize',14);

50 Phase

51 Group delay figure domega=pi*Fs/length(y); R=real(y); I=imag(y);
dI=derive(I,domega); dR=derive(R,domega); grpdelay=-(R.*dI-I.*dR)./(abs(y).^2); phasedelay=-unwrap(p1)./(2.*pi.*f); plot(f,grpdelay*Fs./2,'LineWidth',2) hold on plot(f,1+phasedelay*Fs,'r','LineWidth',2) hold off ylabel('delay [in samples]','FontSize',14); xlabel('frequency [Hz]','FontSize',14); legend('group delay','phase delay'); %axis([ ]) %figure %grpdelay(1,1) set(gca, 'FontSize',14);

52 Phase and Group Delay

53 FIR low-pass filter (300 Hz), n=32

54 Magnitude spectrum

55 Phase

56 Group and phase delay

57 Linear plot

58 Log-frequency plot

59 Log-log plot cut-off frequency −3dB threshold

60 Homework 6, #1 % Pythagorean Tempering
function [freqPytha,freqEqual,devCent]=Interval2Freq(interval) % Pythagorean Tempering rFreq = 440; %Hz (A4) reference Frequency fifth = 3/2; % Determine intervals for first octave for n=2:12 rFreq(n)=rFreq(n-1)*3/2; if rFreq(n)>rFreq(1)*2 rFreq(n)=rFreq(n)/2; end % of if end % of for rFreq=sort(rFreq); octave=floor(interval./12); chroma=mod(interval,12); freqPytha=2.^octave.*rFreq(chroma+1); % Equal Tempering freqEqual=rFreq(1).*2.^(interval./12); devCent=1200.*log2(freqPytha./freqEqual);

61 Results >> [freqPytha,freqEqual,devCent]=Interval2Freq([1:12])
freqEqual = devCent =

62 Homework 6, #2 function [y,t]=OrganPipe(pipelength,reflectioncoef,signal) c=343; % m/s Fs=48000; x=signal; t=(0:length(signal)-1)./Fs; PipeTabs=round(Fs*pipelength/c); l=PipeTabs/Fs*c; ForwardDelayLine=zeros(PipeTabs+1,1); BackwardDelayLine=zeros(PipeTabs+1,1); PipeTabs=PipeTabs+1; for n=1:(length(x)) ForwardDelayLine(2:PipeTabs)=ForwardDelayLine(1:PipeTabs-1); ForwardDelayLine(1)=-1*BackwardDelayLine(1)+x(n); y(n)=ForwardDelayLine(1); BackwardDelayLine(1:PipeTabs-1)=BackwardDelayLine(2:PipeTabs); BackwardDelayLine(PipeTabs)=reflectioncoef*y(n); end % of for

63 Result open pipe [y]=OrganPipe(0.5,-0.7,[1; zeros(4800,1)]);

64 Result open pipe [y,t]=OrganPipe(0.5,-0.7,[1; zeros(4800,1)]);

65 Result closed pipe [y,t]=OrganPipe(0.5,0.7,[1; zeros(4800,1)]);

66 convolution x=randn(4800,1);
[y,t]=OrganPipe(0.5,0.7,[1; zeros(4800,1)]); Z=conv(x,y);


Download ppt "Research Methods in Acoustics Lecture 8: Digital systems and filters"

Similar presentations


Ads by Google