% Demo of aliassing for a C-major scale1 Dec08 % Four octaves: pure sine wave 261 Hz to 4 kHz clear all; disp('=================================='); disp('Demonstrate aliasing for 4-octave scale 261-4kHz'); NH = input('Enter no. of harmonics for each note: '); Fs = input( 'Enter sampling frequency(Hz):'); Cmaj = [261.62557 293.66477 329.62756 349.2282 391.9954 440 493.8833]; Cmaj = [Cmaj Cmaj*2 Cmaj*4 Cmaj*8]; RCmaj = (2*pi/Fs)*Cmaj; NP = Fs/2; L = length(Cmaj); x = zeros(1,NP*L); n=1:NP; for note = 1:L Start = 1+(note-1)*NP; for i=1:NH x(Start:Start+NP-1) =x(Start:Start+NP-1) +(1/NH)*cos(i* RCmaj(note)*n); end; end; sound(x,Fs);