chebyshev.m
% Using Chebyshev Polynomials
clear all; close all; clc;
% Define:
f = @(x) x.^4;
%f = @(x) 4*(x.^2-x.^4).*exp(-x./2);
x = (-1:0.1:1)'; % for -1 <= x <= 1
chebyshevP.m
function chebP = chebyshevP(x,k)
% compute the value of the chebyshev polinomial of degree 'k' for every
% column value 'x'
%number of points
p = k+1;
switch k
case {0} % when k = 0
chebP = ones(size(x));
case {1} % when k = 1
chebP = x;
otherwise % k >= 2
chebP0 = ones(size(x));
chebP1 = x;
for m = 1:k-1
chebPX = (2*x.*chebP1 - chebP0);
chebP0 = chebP1;
chebP1 = chebPX;
end
chebP = chebPX;
end
dct_and_dst.m
% Using dcf and dst
clear all; close all; clc;
f = @(x) x.^2/pi^2;
N = 16; j = 0:N;
x = (2*pi/N)*j;
y = f(x)';
yct = dct(y);
yst = dst(y);
figure(1)
hold on; grid on;
plot(abs(yst),'-or');
plot(abs(yct),'--sg');
legend('dst','dct')
hold off;
FFT_1d.m
% Using FFT
clear all; close all; clc;
f = @(x) cos(3*x);
%f = @(x) 1*(x>=0 & x<pi) + (-1)*(x>=pi & x<2*pi);
N = 16; j = 0:N-1;
x = (2*pi/N)*j;
y = f(x)';
yt = fft(y);
% Plot coeficients
figure(1)
grid on; plot(abs(yt),'or'); legend('fft')
FFT_1d.m
% Using FFT
clear all; close all; clc;
f = @(x) cos(3*x);
%f = @(x) 1*(x>=0 & x<pi) + (-1)*(x>=pi & x<2*pi);
N = 16; j = 0:N-1;
x = (2*pi/N)*j;
y = f(x)';
yt = fft(y);
% Plot coeficients
figure(1)
grid on; plot(abs(yt),'or'); legend('fft')
FFT_1d.m
% Using FFT
clear all; close all; clc;
f = @(x) cos(3*x);
%f = @(x) 1*(x>=0 & x<pi) + (-1)*(x>=pi & x<2*pi);
N = 16; j = 0:N-1;
x = (2*pi/N)*j;
y = f(x)';
yt = fft(y);
% Plot coeficients
figure(1)
grid on; plot(abs(yt),'or'); legend('fft')
本文分享自 图像处理与模式识别研究所 微信公众号,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
本文参与 腾讯云自媒体同步曝光计划 ,欢迎热爱写作的你一起参与!