chebyshev.m
代码语言:javascript复制% 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
代码语言:javascript复制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
代码语言:javascript复制% 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
代码语言:javascript复制% 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
代码语言:javascript复制% 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
代码语言:javascript复制% 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')