필터 지우기
필터 지우기

Audio compression and decompression

조회 수: 19 (최근 30일)
Wes Madere
Wes Madere 2018년 2월 27일
답변: Walter Roberson 2020년 11월 13일
For my code I generate a cosine wave using some notes to create a sound file. I need to compress my signal by removing a percentage of the samples (50%, 75%, 95%), but I have no idea how to do that using the fft function. Here is my code so far. Please help
ts=0.0001; %sampling rate
Fs=1/ts;
n=[0:1057]; %number of samples
%each note should be .625 long
t1=0:ts:0.625;
%frequency values of other notes and keyboard position%
bflat4=466.2;
d5=587;
f5=698.5;
bflat5=932;
ynote1=cos(2*pi*bflat4*t1);
ynote2=cos(2*pi*d5*t1);
ynote3=cos(2*pi*f5*t1);
ynote4=cos(2*pi*bflat5*t1);
ynote5=cos(2*pi*f5*t1);
ynote6=cos(2*pi*d5*t1);
ynote7=cos(2*pi*bflat4*t1);
ynote=[ynote1,ynote2,ynote3,ynote4,ynote5,ynote6,ynote7];
audiowrite('G:\test.wav',ynote,Fs)

답변 (2개)

Lloyd Lobo
Lloyd Lobo 2020년 11월 13일
The specific term you are looking for is downsampling. This will reduce the number of samples of a signal by simply deleting a sample once every n samples. If you remove too many samples, your sound may be altered slightly. You can use the matlab function:
  댓글 수: 1
Walter Roberson
Walter Roberson 2020년 11월 13일
This is not the technology being asked about.

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 2020년 11월 13일
Suppose you are to compress by 74%. Then fft() and extract and retain (100-74) = 26% of the fft coefficients. You will have removed 74% of the information, so that will be compression.
To reconstruct the signal, know the original number of samples, and create a vector of zeros that long, and write the saved coefficients into that vector in the positions corresponding to where you extracted them from, leaving the ones you discarded as 0. Then you can ifft the result and play it.
Which 26% (or as appropriate) of the coefficients should you keep?
  • keep the first entry in the fft() result. This entry is for frequency 0, and has to do with the mean of the signal
  • for all entries beyond the first, retain them in pairs, one from the beginning and one from the end. If you keep entry (1+K) then also keep entry (end-K+1)
  • In the special case of no compression, keep them all. This is equivalent to making a decision about what to do if the signal was originally an even length, so that after you keep the first entry, there are an odd number of remaining entries, so after pairing the entries from the beginning and the end, you are left with one in the middle. If you are doing any compression at all, that middle one should be zeroed.
Hint: fftshift() can make it easier to extract coefficients.

카테고리

Help CenterFile Exchange에서 Audio I/O and Waveform Generation에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by