From: maksut on
Hi.

I want to compress spektrogram with DCT, so compress audio signal.

First i loaded a auido (wav) signal and took it's spectrogram.

>>[audio fs]=wavread('C:\Users\user\Desktop\1.wav');
>>a=specgram(audio);

then i compress the spectrogram with dct;

>> I = im2double(a);
T = dctmtx(3);
dct = @(block_struct) T * block_struct.data * T';
B = blockproc(I,[3 3],dct);
mask = [1 1 0
1 0 0
0 0 0];
B2 = blockproc(B,[3 3],@(block_struct) mask .* block_struct.data);
invdct = @(block_struct) T' * block_struct.data * T;
I2 = blockproc(B2,[3 3],invdct);
imshow(I), figure, imshow(I2)

after these what can i do to get the audip from compressed spectrogram?

thanks
From: muscle museum on
any one help?
From: Wayne King on
"maksut " <losttr(a)losttr.org> wrote in message <hue4cr$i7o$1(a)fred.mathworks.com>...
> Hi.
>
> I want to compress spektrogram with DCT, so compress audio signal.
>
> First i loaded a auido (wav) signal and took it's spectrogram.
>
> >>[audio fs]=wavread('C:\Users\user\Desktop\1.wav');
> >>a=specgram(audio);
>
> then i compress the spectrogram with dct;
>
> >> I = im2double(a);
> T = dctmtx(3);
> dct = @(block_struct) T * block_struct.data * T';
> B = blockproc(I,[3 3],dct);
> mask = [1 1 0
> 1 0 0
> 0 0 0];
> B2 = blockproc(B,[3 3],@(block_struct) mask .* block_struct.data);
> invdct = @(block_struct) T' * block_struct.data * T;
> I2 = blockproc(B2,[3 3],invdct);
> imshow(I), figure, imshow(I2)
>
> after these what can i do to get the audip from compressed spectrogram?
>
> thanks

Hi Maksut, I question your approach here. The DCT is a transform of the time data. It is the inner product of the time data with a cosine. You're computing the short-time Fourier transform and then taking the DCT of that. You want to take the DCT of the time signal, identify which coefficients in the DCT comprise some percentage of the norm of the original signal, and then reconstruct the time signal using the IDCT based on those coefficients. Your use of functions like im2double (I'm not sure why you would use this anyway, isn't the output of specgram already double?) and blockproc indicate you are treating the spectrogram as an image. It's an image only for convenience of display.

I think you want to implement something like:

x = (1:128).' + 50*cos((1:128).'*2*pi/40)+5*randn(128,1);
xDCT = dct(x);
[XX,ind] = sort(abs(xDCT),'descend');
% for 99% of the norm of x
ii = 1;
while (norm([XX(1:ii);zeros(128-ii,1)]) <= 0.99*norm(XX))
ii = ii+1;
end
xCompress = zeros(128,1);
xCompress(ind(1:ii)) = xDCT(ind(1:ii));
xcomp = idct(xCompress);
plot([x xcomp]);

Of course, you'll have to block your data and do this on every block if you want to implement this in a time-varying way. I see you are using specgram. That function is obsolete, so I'm not sure what version of MATLAB you are using. Beginning with R2010a, there are System objects, which can stream data in and process it. There are System objects for the DCT and IDCT, signalblks.DCT and signalblks.IDCT. I think you would find these useful for processing audio data.

Hope that helps,
Wayne