02_CM0340Tut_MATLAB_Synthesis

02_CM0340Tut_MATLAB_Synthesis - CM0340 Tutorial 2: MATLAB...

Info iconThis preview shows pages 1–12. Sign up to view the full content.

View Full Document Right Arrow Icon
1 JJ II J I Back Close CM0340 Tutorial 2: MATLAB BASIC DSP and Synthesis In this tutorial we explain some of the DSP and MATLAB concepts discussed in the lectures leading up to Digital Audio Synthesis. We start by looking at basic signal waveforms. The code that is used over the next few slides is waveforms.m
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 JJ II J I Back Close Simple Waveforms Frequency is the number of cycles per second and is measured in Hertz (Hz) Wavelength is inversely proportional to frequency i.e. Wavelength varies as 1 frequency
Background image of page 2
3 JJ II J I Back Close The Sine Wave and Sound The general form of the sine wave we shall use (quite a lot of) is as follows: y = A.sin (2 π.n.F w /F s ) where: A is the amplitude of the wave, F w is the frequency of the wave, F s is the sample frequency, n is the sample index. MATLAB function: sin() used — works in radians
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 JJ II J I Back Close MATLAB Sine Wave Radian Frequency Period Basic 1 period Simple Sine wave — 1 period is 2 π radians % Basic 1 period Simple Sine wave i=0:0.2:2 * pi; y = sin(i); figure(1) plot(y); % use stem(y) as alternative plot as in lecture notes to % see sample values title(’Simple 1 Period Sine Wave’);
Background image of page 4
5 JJ II J I Back Close MATLAB Sine Wave Amplitude Sine Wave Amplitude is -1 to +1. To change amplitude multiply by some gain ( amp ): % Now Change amplitude amp = 2.0; y = amp * sin(i); figure(2) plot(y); title(’Simple 1 Period Sine Wave Modified Amplitude’);
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6 JJ II J I Back Close MATLAB Sine Wave Frequency % Natural frequency is 2 * pi radians % If sample rate is F_s HZ then 1 HZ is 2 * pi/F_s % If wave frequency is F_w then freequency is F_w * (2 * pi/F_s) % set n samples steps up to sum duration nsec * F_s where nsec is the % duration in seconds % So we get y = amp * sin(2 * pi * n * F_w/F_s); F_s = 11025; F_w = 440; nsec = 2; dur= nsec * F_s; n = 0:dur; y = amp * sin(2 * pi * n * F_w/F_s); figure(3) plot(y(1:500)); title(’N second Duration Sine Wave’);
Background image of page 6
7 JJ II J I Back Close MATLAB Sine Wave Plot of n cycles % To plot n cycles of a waveform ncyc = 2; n=0:floor(ncyc * F_s/F_w); y = amp * sin(2 * pi * n * F_w/F_s); figure(4) plot(y); title(’N Cycle Duration Sine Wave’);
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
8 JJ II J I Back Close Cosine, Square and Sawtooth Waveforms MATLAB functions cos() (cosine), square() and sawtooth() similar.
Background image of page 8
9 JJ II J I Back Close MATLAB Cos v Sin Wave % Cosine is same as Sine (except 90 degrees out of phase) yc = amp * cos(2 * pi * n * F_w/F_s); figure(5); hold on plot(yc,’b’); plot(y,’r’); title(’Cos (Blue)/Sin (Red) Plot (Note Phase Difference)’); hold off;
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
10 JJ II J I Back Close Relationship Between Amplitude, Frequency and Phase
Background image of page 10
11 JJ II J I Back Close Amplitudes of a Sine Wave % Simple Sin Amplitude Demo samp_freq = 400; dur = 800; % 2 seconds amp = 1; phase = 0; freq = 1; s1 = mysin(amp,freq,phase,dur,samp_freq); axisx = (1:dur) * 360/samp_freq; % x axis in degrees plot(axisx,s1); set(gca,’XTick’,[0:90:axisx(end)]); fprintf(’Initial Wave: \t Amplitude = . ..\n’, amp, freq, phase,.
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 12
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/26/2012 for the course CM 0340 taught by Professor Davidmarshall during the Fall '09 term at Cardiff University.

Page1 / 41

02_CM0340Tut_MATLAB_Synthesis - CM0340 Tutorial 2: MATLAB...

This preview shows document pages 1 - 12. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online