I have been given the task of doing audio compression using FFT. The assignment is below.

Below is my MATLAB code:

% part 1
y = y(1:1024*161);
% p = audioplayer(y,f);
% play(p)
Ya = fft(y);
Y = fftshift(abs(Ya));
N = length(Y);
w = -f/2+f/N:f/N:f/2;
figure(1)
plot(w,Y)
% part 2
Y1 = Ya((N/4):(3*N/4));
% part 3
y = ifft(Y1);
player = audioplayer(y,f);
play(player)


Now here is my problem. I was able to do part 1 and part 2 perfectly with no problem, but for part 3 the problem begins. I get no sound at all!!. Now in the prompt it asks to do FFTSHIFT before the IFFT, to me that does not matter, either how I get now sound. can somebody help me on how to fix this please?

The algorithm sets the high frequency DFT coefficients to zero hence effectively providing a lowpass filtering on the time domain signal. Your problem was on the line of creating Y1, which I replaced with the corrected form. I've changed the code a little bit also.

% part 1:
y = y(1:1024*64);                % select a portion of it.

Ya = fftshift(fft(y));           % Compute DFT Ya[k] and SHIFT it
N = length(Ya);                  % Length of DFT Ya[k]

figure,plot(-f/2+f/N:f/N:f/2 , abs(Ya))  % plot the DFT magnitude.

% part 2:
Yr = zeros(1,N);                % Yr[k] of length N!
Yr((N/4)+1:(3*N/4)) = Ya((N/4)+1:(3*N/4));  % Assign nonzero coefficients

% part 3:
yr = real(ifft(fftshift(Yr)));  % RECONSTRUCT the filtered signal.
% Take REAL part for convenience.
figure,plot(-f/2+f/N:f/N:f/2, abs((Yr)));

% part 4:
sound(yr,f,16);                 % Listen to the reconstrcusted audio

• thank you very much for your help, would you elaborate more on the following: 1. Yr includes the index N/4+1, why does the +1 matter? 2. what does the 16 in the sound function do? thank you. Nov 23 '17 at 15:43
• Hi! In the question it says set to zero the first N/4 and the last N/4 transform values. So the first N/4 coefficients of DFT Ya[k] range from k=1 to k=N/4, the nonzero coefficient is therefore at k= N/4 + 1. The same for the last N/4 coefficients. 2-) The 16 in the sound() function is for the number of bits (it can be ignored though) Nov 23 '17 at 16:03
• Oh I see, right on point. Thank you very much! Nov 23 '17 at 16:05
• @Raykh if this answer provides a solution to your problem, then please indicate so by upvoting and selecting it. Otherwise the system will never know that it's been answered and will be bumping it to the questions page as it did now... Jan 22 '18 at 22:19