%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Multimedia Signal Synthesis at CTU Prague % Copyright © 2015 by Roman Cmejla %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Suggestions for 5th laboratory: % Subtractive synthesis % October 30, 2015 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% % Example 1: Differentiator and integrator - simulation % Generate a short numerical sequence and verify the behavior of differentiator % and integrator for differential equations that describe these filters % a) using function for, % b) using function diff and cumsum, % c) using function filter % Solution x=[0 0 0 0 5 5 5 5 8 8 8 8 3 3 3 3 5 5 5 5]; y_int(1)=x(1); for n=2:length(x) y_dif(n)=x(n)-x(n-1); y_int(n)=x(n)+y_int(n-1); end; subplot(231), plot(y_dif), hold on, plot(x,':r'), hold off legend('cyklus for'), xlabel('---> n') subplot(234), plot(y_int), hold on, plot(x,':r'), hold off legend('cyklus for'), xlabel('---> n') subplot(232), plot([0 diff(x)]), hold on, plot(x,':r'), hold off legend('diff'), xlabel('---> n') subplot(235), plot(cumsum(x)), hold on, plot(x,':r'), hold off legend('cumsum'), xlabel('---> n') subplot(233), plot(filter([1 -1],1,x)), hold on, plot(x,':r'), hold off legend('filter'), xlabel('---> n') subplot(236), plot(filter(1,[1 -1],x)), hold on, plot(x,':r'), hold off legend('filter'), xlabel('---> n') %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Example 2: Differentiator and integrator - behavior % Generate multiple periods of digital sinusoidal, rectangular % and sawtooth waveform. % a) Display the output signal of differentiator % b) Display the output signal of integrator x1=sin(0:0.2:10-0.2); x2=square(0:0.2:10-0.2); x3=sawtooth(0:0.2:10-0.2,.5); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Example 3: Speech filtering % a) Listen the speech signal at the output of the lowpass filter % b) Listen the speech signal at the output of the highpass filter % c) Compare the sum of the filtered signals with the original % d) Analyze the used filters % (frequency response, impulse response, the distribution of zeros and poles) b_dp=[1 1]; a_dp=[1 -0.9]; % LP b_hp=[1 -1]; a_hp=[1 0.9]; % HP jedna=wavread('jedna.wav'); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Example 4: Speech filtering using digital filter with one pole % Repeat the task of the previous example for a simple digital filter % whose pole has a radius of: % a) r = 0,9 % b) r = 0,95 % c) r = 0,99 % d) r = -0,9 % e) r = -0,95 % f) r = -0,99 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Example 5: Envelope detector % Realize envelope detectors load osum1.sig xc=osum1./max(abs(osum1)); plot(xc,'k') xi=filter(1,[1 -0.99],abs(xc)); plot(xi,'k'), xi=filter(1,[1 -0.8],abs(xc)); plot(xi,'k'), xi=filter(1,[1 -0.3],abs(xc)); plot(xi,'k'), %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Example 6: Peak detector %load osum1.sig %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Example 7: Applications with noise and envelopes % efekty fs=44100; doba=2.5; t=0:1/fs:doba-1/fs; x=randn(1,doba*fs); X=[0 0.05 0.4 1]; Y=[1 0.05 0.25 0]; O=interp1(X,Y,t./t(end)); sig=x.*O; soundsc(sig,fs) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Example 8: Tuning filter % Continuously (according to the sine wave) tune % the 1st order IIR filter (by changing the coefficient) % Put the white noise on the input of the filter fs = 8000; % sampling frequency [Hz] fm = .5; % frequency of control sinusoidal signal doba = 6; % duration of output signal [s] nT = 0:1/fs:doba-1/fs; % time axis x=rand(1,length(nT))-.5; % Display: % - control signal % - output signal % - spectrogram of output signal %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Example 9: Applications with noise and envelopes % % Realize a simple drum on the principle of filter synthesis % Filter parameters: b=1; a=[1 -0.7934]; x=2*rand(1,fs*doba)-1; % white noise generator fs = 44100; % sampling frequency [Hz] doba = .5; % duration of output signal [s] nT=0:1/fs:doba-1/fs; % time axis % control points of the output signal envelope X =[0 .15 1]; % tame axis Y =[1 .05 0]; % amplitude % Display: % - Poles and zeros % - Amplitude frequency characteristics % - Amplitude envelope % - Output waveforms %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Example 10: Applications with noise and envelopes % falling tones %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Example 11: Applications with noise and envelopes % steam engine