DCT - approximate a function using DCT.
2 views (last 30 days)
Show older comments
Hi Guys I have task I dont know how to do it. I must write a function using DCT( Discrete Cosine Transform) that make a approximation of math function like sin(x). I read a Wiki about that.I stay in one point for long time I dont know what I did wrong becouse It doesnt work I think.
function [] = DCT(a,b,N)
x = linspace(a,b,N);
y = zeros(1,N);
y = sin(2*pi*x);
plot(x,y,'g');
grid on;hold on;
K = N;
for k = 1:N
G=0;
for m = 1:K
if k==1
G = G + (1/sqrt(N))*y(m);
else
G = G + (sqrt(2)/sqrt(N))*y(m)*cos((pi*k*(2*m-1))/(2*N));
end
end
G(k)=G;
end
0 Comments
Answers (0)
See Also
Categories
Find more on Time Series 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!