Question
I need help with the overlap_add and overlap_save functions that i need to create for my lab class here is the assignment this is what
I need help with the overlap_add and overlap_save functions that i need to create for my lab class
here is the assignment
this is what i have for the overlap_add function
function y = overlap_add(x, h, lc) % OVERLAP_ADD Convolve x and h using overlap-add method % y = overlap_add(x, h, lc) % x and h are arrays, % lc is the chunk size (default 50) initialx=length(x); yl = length(x)+length(h)-1; % the system response length out = zeros(1,(lc+length(h)-1)*ceil(length(x)/lc)); yout = zeros(1,(lc+length(h)-1)*ceil(length(x)/lc));
if (rem(length(x),lc) ~= 0) % if we have part of a chunk
x= [x zeros(1,(lc+length(h)-1)*ceil(length(x)/lc)-length(x))]; end index = 1;
for i= index:ceil(initialx/lc) % Never got back to fixing this out(i,index:index-1+(lc+length(h)-1)) = conv(x( index:index+lc-1) ,h); % gonna be cl + h -1 long yout = yout + out(i,1:length(yout)); %
please type or write very clearly for the response, thanks!
3.3 Assignmenit You will write a Matlab function to convolve two sequences using both the overlap-add and overlap-save methods. For this assignment, we will not bother with the sequence structures we used in the previous laboratories. Instead, we will assume that [n] and h[n] are standard Matlab sequences. Here are the function headers function y - overlap add (x, h, lc) OVERLAP-ADD Convolve x and h using overlap-add method y = overlap add (x, h, 1c) x and h are arrays, lc is the chunk size (default 50) an function y-overlap_save (x, h, lc) OVERLAP-SAVE Convolve x and h using overlap-save method y-overlap_save (x, h, lc) x and h are arrays, lc is the chunk size (default 50) 3.3.1 Notes on the assignment: h[n] will be of reasonable length, containing no more than 50 samples. However, x[n]can be very, very long. The whole point of this exercise is to figure out how to cut up a[n] in order to convolve it with h[n]. A good way to get a very long a[n]is to read in and convert a .wav file. One such file is seashell.wav, which is included in lab2.mat, which you can download from the website. Once you have downloaded this file, you can get Matlab to extract the data from the file using the wavread or audioread function (depending on your version of Matlab) and play it using the soundsc function: [x, fs] wavread('seashell'); soundsc (x, fs) To see what filtering convolution (a.k.a. FIR filtering) with simple h[n] sounds like, try the following soundsc (conv (x, [1-11), fs); % this is a simple high-pass filter soundsc (conv (x, [1 1 1 1 1 1 11), fs); % this is a simple low-pass filter Later in the term, we'll learn how to design filters for specific purposes, but for now, notice how convolution is used to implement filtering with these simple h[n] Internally, your program should cut the long rln] into 'input chunks' of size, V, and convolve each chunk with h[n]to form output chunks, then assembling these output chunks using the overlap-add and overlap-save methods. Once you have created each output chunk, you can assemble the output sequence by a couple of methods Create your entire output array, output_array, in advance, for example using the zeros function, and then copy each chunk into the appropriate place in the output array. For example, the input array, input_array, which is of size N, can be copied efficiently to the ith chunk of an output_array as follows indx = 1 + (i-1)*N; output_array (indx: indx+N-1) input_array: Instead of creating the entire array in advance, you can just append a given chunk to the end of the current out- put array as follows: output array foutput array chunk However, this method is less efficient and slower because every time you do this, Matlab must internally reallo cate a new output_array and then delete the previous output_array. Your chunk size, N, should be a maximum of 500 points. Should it be smaller? Why or why not? For starters, try the something simple for hln], for example, [1 -1] or [ 1 11 1 1]. You should not assume that the length of x[n] is a nice multiple of 500. You may have to pad the last frame of data with zeros (how do you do this?) You may use the length or size command to figure out the length of the input. Of course, in a real application, you would not know this infor- mation. Since the main point of this exercise is to teach you about the overlap-save and overlap-add methods of convoling nfi nite-length sequences, you don't have to write your own convolution function. Instead, you may use MATLAB's conv function to do the convolution of the chunks. You'll notice that the first and last few points of the entire convolution (how many?) will be "bogus", in the sense that they ramp up from zero at the beginning and ramp down to zero at the end. You should include these ramp sections so that your functions match the output of Matlab's conv function exactly. There are at least a couple of ways to do this .Put an if statement in the for loop that handles the input chunks so that it handles the first and last chunks differ- ently; namely, that it retains the first points of the first frame and the last points of the last frame instead of tossing them. Pad the beginning and end of the entive input sequence with an appropriate number of zeros (how many?). . 3.3 Assignmenit You will write a Matlab function to convolve two sequences using both the overlap-add and overlap-save methods. For this assignment, we will not bother with the sequence structures we used in the previous laboratories. Instead, we will assume that [n] and h[n] are standard Matlab sequences. Here are the function headers function y - overlap add (x, h, lc) OVERLAP-ADD Convolve x and h using overlap-add method y = overlap add (x, h, 1c) x and h are arrays, lc is the chunk size (default 50) an function y-overlap_save (x, h, lc) OVERLAP-SAVE Convolve x and h using overlap-save method y-overlap_save (x, h, lc) x and h are arrays, lc is the chunk size (default 50) 3.3.1 Notes on the assignment: h[n] will be of reasonable length, containing no more than 50 samples. However, x[n]can be very, very long. The whole point of this exercise is to figure out how to cut up a[n] in order to convolve it with h[n]. A good way to get a very long a[n]is to read in and convert a .wav file. One such file is seashell.wav, which is included in lab2.mat, which you can download from the website. Once you have downloaded this file, you can get Matlab to extract the data from the file using the wavread or audioread function (depending on your version of Matlab) and play it using the soundsc function: [x, fs] wavread('seashell'); soundsc (x, fs) To see what filtering convolution (a.k.a. FIR filtering) with simple h[n] sounds like, try the following soundsc (conv (x, [1-11), fs); % this is a simple high-pass filter soundsc (conv (x, [1 1 1 1 1 1 11), fs); % this is a simple low-pass filter Later in the term, we'll learn how to design filters for specific purposes, but for now, notice how convolution is used to implement filtering with these simple h[n] Internally, your program should cut the long rln] into 'input chunks' of size, V, and convolve each chunk with h[n]to form output chunks, then assembling these output chunks using the overlap-add and overlap-save methods. Once you have created each output chunk, you can assemble the output sequence by a couple of methods Create your entire output array, output_array, in advance, for example using the zeros function, and then copy each chunk into the appropriate place in the output array. For example, the input array, input_array, which is of size N, can be copied efficiently to the ith chunk of an output_array as follows indx = 1 + (i-1)*N; output_array (indx: indx+N-1) input_array: Instead of creating the entire array in advance, you can just append a given chunk to the end of the current out- put array as follows: output array foutput array chunk However, this method is less efficient and slower because every time you do this, Matlab must internally reallo cate a new output_array and then delete the previous output_array. Your chunk size, N, should be a maximum of 500 points. Should it be smaller? Why or why not? For starters, try the something simple for hln], for example, [1 -1] or [ 1 11 1 1]. You should not assume that the length of x[n] is a nice multiple of 500. You may have to pad the last frame of data with zeros (how do you do this?) You may use the length or size command to figure out the length of the input. Of course, in a real application, you would not know this infor- mation. Since the main point of this exercise is to teach you about the overlap-save and overlap-add methods of convoling nfi nite-length sequences, you don't have to write your own convolution function. Instead, you may use MATLAB's conv function to do the convolution of the chunks. You'll notice that the first and last few points of the entire convolution (how many?) will be "bogus", in the sense that they ramp up from zero at the beginning and ramp down to zero at the end. You should include these ramp sections so that your functions match the output of Matlab's conv function exactly. There are at least a couple of ways to do this .Put an if statement in the for loop that handles the input chunks so that it handles the first and last chunks differ- ently; namely, that it retains the first points of the first frame and the last points of the last frame instead of tossing them. Pad the beginning and end of the entive input sequence with an appropriate number of zeros (how many?)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started