NEED EXPLANATION FOR A MATLAB AUDIO COMPRESSION URGENTLY PLEASE. I WOULD BE VERY GRATFUL
10 views (last 30 days)
Show older comments
divya reddy
on 1 Nov 2020
Commented: Walter Roberson
on 22 Dec 2022
%%%%%%%%%%%%%TASK 1%%%%%%%%%%%%%%%%
[x,fs]=audioread('sample.wav');
N=length(x);
vlcplayer=audioplayer(x,fs);
vlcplayer.play
%%%%%%%%%%%% task 2%%%%%%%%%%%
t=fft(x,N);
X=fftshift(t)
f=-fs/2:fs/N:(fs/2-fs/N);
figure(1)
plot(f,abs(X))
title('original audio signal')
%%%%%%%%%%%%%% TASK 2 AND 4%%%%%%%%%
Xr=zeros(1,N);
Xr((N/4)+1:(3*N/4))= X((N/4)+1:(3*N/4)); %%FORMULA
figure(2)
plot(f, abs((Xr)));
xr= real(ifft(fftshift(Xr))); %%reconstruction
audiowrite('50% compressed.wav',xr,fs);
title('50% compressed audio')
xlabel('freq(hq)');ylabel('magnitude');
%%change ratio to 60,70,80,90,95% compression ....just change FORMULA
%Xr((N*((60/100)/2))+1 : N*(1-(60/100)/2)) = X((N*((60/100)/2))+1 : N*(1-(60/100)/2));
%Xr((N*((70/100)/2))+1 : N*(1-(60/100)/2)) = X((N*((60/100)/2))+1 : N*(1-(60/100)/2));
%Xr((N*((80/100)/2))+1 : N*(1-(60/100)/2)) = X((N*((60/100)/2))+1 : N*(1-(60/100)/2));
%Xr((N*((90/100)/2))+1 : N*(1-(60/100)/2)) = X((N*((60/100)/2))+1 : N*(1-(60/100)/2));
%Xr((N*((95/100)/2))+1 : N*(1-(60/100)/2)) = X((N*((60/100)/2))+1 : N*(1-(60/100)/2));
%%PLAYING THE OUTPUT
%audiowrite('60% compressed.wav',xr,fs);
%audiowrite('70% compressed.wav',xr,fs);
%audiowrite('80% compressed.wav',xr,fs);
%audiowrite('90% compressed.wav',xr,fs);
%audiowrite('95% compressed.wav',xr,fs);
5 Comments
Rakesh
on 22 Dec 2022
could you please forward the information about this code in pdf format like its abstract,introduction,references,theoritical analysis,etc.....like these
Walter Roberson
on 22 Dec 2022
Rakesh, you are assuming that someone has already written those out for this code, which is not at all certain. What you are asking for sounds quite a bit like what a student would be expected to write for an assignment; if someone had already written such a thing up, that would disqualify a second student from using the results in their own assignment because of academic integrity concerns.
Accepted Answer
Walter Roberson
on 1 Nov 2020
It is a high-pass filter. When you fft() the coefficients for the low frequencies come first, and increasing frequencies after that in the result until you get to the middle and then they reduce again. Middle is highest frequency, next to that on both sides is second highest frequency, and so on.
When you copy the middle of the results out to zeroes around it, then you are zeroing the lower frequencies, which is a high pass filter.
8 Comments
Walter Roberson
on 6 Nov 2020
Ah, I missed the fftshift() before. The effect is to make the algorithm into a low-pass filter instead of a high-pass filter.
More Answers (0)
See Also
Categories
Find more on Simulation, Tuning, and Visualization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!