%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % SMS - suggestions for 1st laboratory: Introduction to DSP % October 2nd, 2015 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LABORATORY RULES for the room No. 405 1. Students may be in the laboratory only for the presence of the teacher. 2. Commands of teachers must be strictly observed. 3. Manipulation with measuring devices is possible only with the consent of the teacher. 4. The electrical distribution systems can be turned on only by teachers. 5. Students are required to monitor the status of the measurement equipment. 6. Students are required to turn off the electrical supply in the case of emergency. 7. Students have to immediately report to the teacher all defects in equipment or devices. 8. Leaving of the laboratory is permitted with the consent of the teacher. ----------------------------------------------------------- EXAMPLE 1a: MATLAB Operations with vectors Create: vector13 = 1 2 3 vector14 = 2 3 4 Vector multiplication by constant vector15 = vector14 * 2 Vector multiplication vector16 = vector13 * vector14 vector17 = vector13 .* vector14 vector18 = vector13 * vector14' -- Solution: >> vector13=1:3 >> vector14=2:4 >> vector15=vector14*2 >> vector16 = vector13 * vector14 % impossible >> vector17 = vector13 .* vector14 % multiplication by element with the element >> vector18 = vector13 * vector14' % product of rows and columns ----------------------------------------------------------- EXAMPLE 1b: MATLAB Matrices Creating of matrices matrix1 = [ 1 2 3 ] matrix2 = [ 1 2 3 4 5 6 7 8 9 ] Matrix indexing select the element on the position (3,1) in matrix2 select all elements in the 2nd row of the matrix2 select all elements in the 2nd column of the matrix2 -- Solution: >> matrix1 = [ 1 2 3 ] >> matrix2 = [ 1 2 3; 4 5 6; 7 8 9 ] >> matrix2(3,1) >> matrix2(2,:) >> matrix2(:,3) ----------------------------------------------------------- EXAMPLE 1c: MATLAB Creating matrices from two vectors: A = [vector1;vector3;vector1] B = [vector1';vector2';vector1']' C = [vector13 vector14] -- Solution: A % to create the matrix is impossible, because rows have different lengths B % resulting row vector has 25 columns C % resulting row vector has 6 columns ----------------------------------------------------------- % EXAMPLE 2a: Aliasing - chirp signal % Explain the formation of the signal y fs = 10000; window = 512; overlap = 500; NFFT = 1024; duration = 10; % starting at F0=0, % in the time T1=1 second is reached F1=5000 Hz % y = chirp(t,F0,T1,F1) t = 0:1/fs:duration-1/fs; y=chirp(t,0,1,5000); ----------------------------------------------------------- % EXAMPLE 2b: Aliasing - audio signal % Explain the differences between signals y1 and y2 [x,fs]=wavread('tom'); % fs = 44100 Hz window = 512; overlap = 500; NFFT = 1024; DF = 20; % decimation factor y1 = x(1:DF:end); % fs=2205 Hz for DF = 20 y2 = decimate(x,20); ----------------------------------------------------------- kvant.m function y=kvant(x,b) y = (round(2^(b-1) *x+.5)-.5)/2^(b-1); ----------------------------------------------------------- % EXAMPLE 3a: Quantization of harmonic signal % Display of 1 period of quantized harmonic signal % a) 1-bit % b) 2-bits % c) 3-bits fs = 22050; f0 = 50; duration = .02; ----------------------------------------------------------- % EXAMPLE 3b: Quantization - audio signal % View and listening of the song "Tom's Diner" % at different quantization [x,fs]=wavread('tom'); ----------------------------------------------------------- % EXAMPLE 3c: Dependence of the SNR [dB] at the quantization [bits] % in the song "tom.wav" [x,fs]=wavread('tom'); ----------------------------------------------------------- % EXAMPLE 4a: Amplitude envelope - percussive sounds % To generate percussive sounds (synthetic bells, drums, ...) % are often used exponential envelopes. % Generate the tone "a1" with exponentially damped envelope. % The time constant, which determines the period of decline, % we will gradually change from 0.3 s to 1 ms. % The resulting signals we can listen and to display in the time domain. % Note how the shortening of the time constant gains clicking sound character. fs = 16000; % sampling frequence duration = 0.5; % signal duration [s] f0 = 440; % signal fundamental frequency t = 0:1/fs:duration-1/fs; % time axis tau = [ 0.3 0.1 0.03 0.01 0.003 0.001]; % time constants of envelopes ----------------------------------------------------------- % EXAMPLE 4b: Amplitude envelope ADSR - non-percussive sounds % % The amplitude envelope of synthetic musical instruments are often modeled % as a sequence of four periods: % A - attack % D - decay % S - sustain % R - release % % % 1.0_| % | /\ % | / \ % 0.5_| / \________ % | / \ % | / \ % 0_|/__________________\______ % | A | D| S | R| % 0 V V V V % a1 a2 a3 a4 % % Generate the tone "a1" as harmonic signal of the length 1 second. % Generate the amplitude envelope ADSR composed of linear sections. % See the effects of changes during the duration of the attack A and decay D. fs = 8000; f0 = 440; duration_whole = 1; duration_A = [0.001 0.003 0.01 0.03 0.1 0.3]; duration_D = [0.001 0.003 0.01 0.03 0.1 0.3]; duration_R = 0.02; duration_S = duration_whole-duration_A-duration_D-duration_R; a1 = 1; a2 = 0.3; a3 = 0.2; a4 = 0; ----------------------------------------------------------- % EXAMPLE 4c: Amplitude envelope ADSR - non-percussive sounds % % Generate the tone "a1" as harmonic signal of the length 1 second. % Generate the amplitude envelope ADSR composed of linear sections. % See the effects of changes in amplitude of the attack A. y = [ ]; fs = 8000; f0 = 440; duration_whole = 1; duration_A = 0.1; duration_D = 0.1; duration_R = 0.1; duration_S = duration_whole-duration_A-duration_D-duration_R; a1 = [0.15 0.3 0.45 0.6 0.75 1.0]; a2 = 0.15; a3 = 0.15; a4 = 0; ----------------------------------------------------------- % EXAMPLE 4d: Amplitude envelope ADSR - non-percussive sounds % % Generate the tone "a1" as harmonic signal of the length 1 second. % Generate the amplitude envelope ADSR composed of linear sections. % See the effects of changes in amplitude during the duration of the sustain S. y = [ ]; fs = 8000;f0 = 440; duration_whole = 1; duration_A = 0.1; duration_D = 0.1; duration_R = 0.1; duration_S = duration_whole-duration_A-duration_D-duration_R; a1 = 1; a2 = [0.9 0.75 0.6 0.45 0.3 0.15]; a3 = [0.9 0.75 0.6 0.45 0.3 0.15]; a4 = 0;