{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

02_CM0340Tut_MATLAB_Synthesis

02_CM0340Tut_MATLAB_Synthesis - CM0340 Tutorial 2 MATLAB...

This preview shows pages 1–13. Sign up to view the full content.

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

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

View Full Document
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
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

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

View Full Document
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’);
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’);

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

View Full Document
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’);
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’);

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

View Full Document
8 JJ II J I Back Close Cosine, Square and Sawtooth Waveforms MATLAB functions cos() (cosine), square() and sawtooth() similar.
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;

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

View Full Document
10 JJ II J I Back Close Relationship Between Amplitude, Frequency and Phase
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,...); % change amplitude amp = input(’\nEnter Ampltude:\n\n’); s2 = mysin(amp,freq,phase,dur,samp_freq); hold on; plot(axisx, s2,’r’); set(gca,’XTick’,[0:90:axisx(end)]); The code is sinampdemo.m

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

View Full Document
12 JJ II J I Back Close mysin MATLAB code The above call function mysin.m
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}