No BSD License  

Highlights from
DCT Implemetation using FFT.

from DCT Implemetation using FFT. by Farhat Masood
Implementation of Discrete Cosine Transform using FFT.

dct_farhat
function dct_farhat
close all; clc;                                 % Closing all Matlab Windows/Clearing the Text.
input=wavread('MAL8K');                         
figure;                                         
plot (input);
title('Original Signal')                        
xlabel('Number of Samples')                     
ylabel('Amplitude')                             
size=length(input);                             % Calculates the SIZE.
y=input;
% Calling the FFT FUNCTION.
in_dct=f_fft(y);                                % Input for a DCT Tranform.
k=0:(length(in_dct)-1);                         % Limits for Variable K tends to N-1.
ex=exp(-j*k*pi/(length(in_dct)));               % Multiplying Co-efficient.
in_dct=in_dct.*ex;                              % Point to Point Multiplication.
in_dct=2*real(in_dct);                          % Extraction of Real-Part and Multiplying with 2.
n=length(in_dct);                               % Length of the input_dct.
p=1:n;                                          % To Get Even Symmetric Output Waveform (DCT).
z(p)=in_dct(p);                                 % Storing valves in another Variable.
z;
figure;
plot (abs(z));
title('Even Symmetric DCT Output Waveform')
xlabel('Number of Samples')
ylabel('Amplitude')
n=length(in_dct)/2;                             % Length of the input_dct halved.
p=1:n;                                          % Samples Halved.
x(p)=in_dct(p);                                 % Storing valves in another Variable.
x;
figure;
plot (abs(x));
title('DCT Output Waveform - Conjugate Ignored')
xlabel('Number of Samples')
ylabel('Amplitude')

[yy ww]=sort(abs(x));                           % Collecting Samples for Compression.
ww=fliplr(ww);
i=1;                                            % Applying Parsevals' Theorem and Getting Maximum Energetic Components.
while(norm([x(ww(1:i)) zeros(1,100-i)])/norm(x)<0.921)
    i=i+1;
end
x1(1:max(ww(1:i)))=0;
x1(ww(1:i))=x(ww(1:i));
Output=length(x1);                              % Copying in the output samples to a new variable.
x1;
% wavwrite(x1,'CompressedSound')
figure;
plot(x1);
title('Significant Samples - FOR COMPRESSION')
xlabel('Number of Samples')
ylabel('Amplitude')

%REGENERATION OF ORIGINAL WAVEFORM FROM OUTPUT OF DCT.
len=length(x1)+1:size;                          % Generating Length to Original N from N/2.
x1(len)=0;                                      % Appending Zeros to the Output Waveform of DCT.
k1=0:(length(x1)-1);                            % Copying the Coefficient from 0 to N/2 - 1.
ex1=exp(j*k1*pi/(2*size));                      % Declaring another exponent.
g1=x1.*ex1;                                     % Point to Point Multiplication with the Exponential.
k2=(size+1):(2*size-1);                         % Declaring another exponent for the Range from N+1 to 2(N-1).
ex2=-1*exp(j*k2*pi/(2*size));                   % Declaring Exponent Function.
x2=fliplr(x1);                                  % Flip DCT Output from Left to Right and Storing in A Variable.
k3=1:length(x2)-1;                              % Declaring length from 1 to N/2 -1.
x3(k3)=x2(k3);                                  % Copying Values.
g3=x3.*ex2;                                     % Multiplying Co-efficients.

out=cat(2,g1,0);                                % Cancatenation of Array g1 and zero array.
out1=cat(2,out,g3);                             % Cancatenation of Array out and g3.
output=f_fft(out1);                             % Taking fft again.
outputf=fliplr(output);                         % Fliping the Output from left to right.
outputf=circshift(outputf,[0 1]);               % Shifting the Values to Complete Range.
outputf=real(outputf);                          % Extractin the Real Part.
k=1:length(outputf)/2;                          % Length Halved.
outputf1(k)=outputf(k)/(2*size);                % Normalzing to 2N.
wavwrite(outputf1,'outcompression')            
figure;
plot(outputf1);
title('Regenerated Output Waveform')
xlabel('Number of Samples')
ylabel('Amplitude')

end

Contact us at files@mathworks.com