# Plot the magnitude of coefficients against frequencies of DCT transform

When we perform DCT transform using matlab:

 number_of_sample_data = 100;
f=0.1; %frequency
fs=1; %sampling rate
phi_0=0
t=0:1/fs:((number_of_sample_data-1)*1/fs); %generate 100 samples
x=sin(2*pi*f*t+phi_0);
dct_transform=dct(x); %perform discrete cosine transform
figure(1), stem(dct_transform);


this piece of code will plot the magnitude of coefficients against frequencies or something else?

## 1 Answer

Actuually, that code doesn't work without defining axis t variable, and frequency f, regarding to what that code does, is simple:

x=sin(2*pi*f*t);        %x is a sinusoidal vector of frequency f and length t;
dct_transform=dct(x);   %dct_transform is a vector containing the unitary discrete transform of x
figure(1), plot(dct_transform); %plots the the unitary discrete transform of the sinusoid against default axis in Matlab


So you are just plotting the discrete transform vector against sample position, wish is what Matlab does by default.

• Sorry i haven't enter all the code. I mean i don't understand when we do 'dct' in matlab what is the output plot? magnitude of coefficients against frequencies or something else? I have enter the full code now. – 20317 May 19 '13 at 16:01
• Check , my answer again, and comment me if u don't understand – Daniel Conde Marin May 19 '13 at 16:11
• I think i understand that i need to add more code to do the job. What i need to alter? – 20317 May 19 '13 at 16:32