%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Multimedia Signal Synthesis at CTU Prague % Copyright © 2014 by Roman Cmejla %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Suggestions for 9th laboratory: % Waveshaping synthesis % December 4, 2015 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Recommended links: % http://music.columbia.edu/cmc/musicandcomputers/chapter4/04_06.php % http://en.wikipedia.org/wiki/Distortion_synthesis % http://www.cs.sfu.ca/~tamaras/waveshapeSynth/waveshapeSynth.pdf %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% clear, close all % Example 1: % For the following functions % a) y = k.*x; k = < -1 .. -.5 .. 1> % b) y = x.^k; k = < 1 .. 2 .. 15> % c) y = max(x) * atan(k * x/max(x)); k = <-1000 .. 1 .. 1000> % d) y = max(x) * tanh(k *x/max(x)); k = <-1000 .. 20 .. 1000> % e) y = x.*(abs(x)+k)./(x.^2+(k-1)*abs(x)+1); k = <-.5 .. .1 .. 100> % f) n = 2*k/(1-k); k = < -1 .. -.5 .. 1> % y = (1+n)*x./(1+n*abs(x)); % g) y = x+(abs(x)>k).*(abs(x)-k).*sin(pi+2*pi*x); k = < .1 .. .5 .. 1> % % plot: % i) transfer characteristics % ii) input waveform (one cycle of sine wave) % iii) output waveform % iv) amplitude spectrum of the output signal %% % Chebyshev polynomials % Example 2: % a) Using Chebyshev polynomials generate harmonic frequency components % T1 = x; T2 = 2*x.^2 - 1; T3 = 4*x.^3 - 3*x; T4 = 8*x.^4 - 8*x.^2 + 1; T5 = 16*x.^5 - 20*x.^3 + 5*x; T6 = 32*x.^6 - 48*x.^4 + 18*x.^2 - 1; T7 = 64*x.^7 - 112*x.^5 + 56*x.^3 - 7*x; T8 = 128*x.^8 - 256*x.^6 + 160*x.^4 - 32*x.^2 + 1; T9 = 256*x.^9 - 576*x.^7 + 432*x.^5 - 120*x.^3 + 9*x; T10= 512*x.^10 - 1280*x.^8 + 1120*x.^6 - 400*x.^4 + 50*x.^2 - 1; %% % b) Plot periodic waveforms % using Chebyshev polynomials % eg .: square wave y = T1 - (1/3)*T3 + (1/5)*T5 - (1/7)*T7 + (1/9)*T9; %% % Example 3: % Waveshaping synthesis of banjo % a) To find the transfer function from the amplitude spectrum banjo % using Chebyshev polynomials % amplitude spectrum banjo X=[-13 -8 5.5 -3.5 2.6 -6.6 -21 -7 -16 -13 -17 -13 -13 -27]; ampl = 10.^(X./20); HELP: use the functions sym a digits %% % b) Using transfer functions found in the previous example % realize the sound of banjo. clear, fs = 11127; doba = 1; f0 = 390; t = 0:1/fs:doba-1/fs; x = cos(2*pi*f0*t); y = 115.0*x.^10 + 40.4*x.^9 - 230.0*x.^8 - 85.3*x.^7 + 151.0*x.^6 ... + 79.9*x.^5 - 35.2*x.^4 - 33.5*x.^3 + 0.772*x.^2 + 2.13*x + 0.025; z=y.*exp(-t./.15); soundsc(z,fs) subplot(211), plot(z) subplot(212), specgram(z) %% % Example 4: % Realize any musical instrument using waveshaping synthesis