Question: For the code below, Can you please help me to allow the decaying notes ( i . e . with the windowing function ) to

For the code below, Can you please help me to allow the decaying notes (i.e. with the windowing function) to overlap slightly in time. Assuming the size of the overlap between two consecutive ADSR functions can be 100 samples.
Is this goin to improve the sound quality?
Hint: Here is an example of how to concatenate two vectors with an overlap. Assume we have
vector x and y given by,
x=[123456]
y=[7891111]
and we want to concatenate them with an overlap of two samples. The first step is to extend both
vectors, by pre and post padding them by zeros, to a length of the final concatenated vector. Note
that the length of the final vector is equal to length(x)+ length(y)- length(overlap). Therefore,
we should extend vector x by post padding it with zeros of length equal to length(y)-
length(overlap); similarly, we should extend vector y by pre padding it with zeros of length
equal to length( x )-length(overlap). Then, add the two extended vectors. Here is a MATLAB code
which performs the steps explained:
y=[78891011];
overlap =2;
x1=[x, zeros(1, length(y)-overlap)]; ??% post zero-padded x
y=[ zeros(1,length(x)-overlap),y]; ??%pre zero padded y
z=x1+y;
Also it could be done in one line as:
z=[x(1 :end-overlap),x( end-overlap +1 :end )+y(1 :overlap),y( overlap +1 :end )]
THE CODE:
% lab1.m
clear all
close all
clc
notes =['A''A''E''E''E''B''C''B''A'];
count =[8000,4000,4000,4000,4000,4000,4000,4000,16000];
x=[];
fs=8000;
for i =1:length(notes)
m = count(i);
n =0:m-1;
switch(notes(i))
case 'A'
f=220;
case 'B'
f=220*2^(2/12);
case 'C'
f=220*2^(3/12);
case 'D'
f=220*2^(5/12);
case 'E'
f=220*2^(7/12);
case 'F'
f=220*2^(8/12);
case 'G'
f=220*2^(10/12);
end
y = cos(2*pi*f/fs*n);
ADSR =[linspace(0,1,0.05*m), linspace(1,0.8,0.1*m), linspace(0.8,0.8,0.7*m), linspace(0.8,0,0.15*m)];
% Ensure ADSR has the same length as 'y'
ADSR = ADSR(1:length(y));
x =[x, y .* ADSR]; % Apply ADSR envelope to the signal
end
soundsc(x, fs);
For the code below, Can you please help me to

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!