|
|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
* a4 E! s; Q+ \9 O" u
有关idct的基础知识见:MATLAB 基础知识之逆离散余弦变换(idct)* l k e0 J2 a* v6 ? {
2 ^# ]) p; g; N3 B& P+ Y0 ~
idct
6 I/ A+ T" Y/ U$ a
) C4 t: O! `' U1 L8 Z逆离散余弦变换: V1 G8 V+ E- ]/ N q& ]
* l! _1 w. v' ~Syntax
" C% y( K2 g0 t4 D+ C O7 h% K. R4 W) n* P
x = idct(y), ~ j% R/ }: F
0 b. A/ f+ ~' J$ c
x = idct(y,n)
% ?5 r1 [3 J1 X+ q) U; k
6 Q) `: D! S( a" E# _x = idct(y,n,dim)# ^2 i; m" b1 W1 X
; Z' N2 y5 B) k) gy = dct(___,'Type',dcttype)4 K) V1 [: X9 B% X+ d+ D2 X& [
/ q4 Z% V3 T1 `
Description
3 D* w: o9 s7 k; _1 X
. Z4 v. H2 _; g% ~x = idct (y) 返回输入数组 y 的逆离散余弦变换。输出 x 的大小与 y 相同。如果 y 具有多个维度, 则 idct 沿第一个数组维度运行, 大小大于1。
- m b' A8 c% R, R
6 F2 u0 m. H8 b4 n, a% y! W* sx = idct (y, n) 填充0或截断 y 到长度 n 在转换前的相关维度。
* U3 {+ m, p7 W/ e" B c% ^! C
/ y' e7 K. t: L1 N& gx = idct (y、n、dim) 计算沿维度dim的变换。若要输入维度并使用默认值 n, 请将第二个参数指定为空 []。
' d* E) L0 z% G3 G2 n( j+ s. ` Q6 u: H' R, y% X* S. G
y = dct(___,'Type',dcttype) specifies the type of inverse discrete cosine transform to compute. $ z, I9 K; L- v* f i* k
$ n r% c) ?) [5 L& t9 z" A- }
Signal Reconstruction Using Inverse Discrete Cosine Transform
3 O8 \% U. @# x) Z. Y8 g3 N0 R/ c6 ^3 r* g% O' F" L
生成一个信号, 由 25 hz 正弦采样 1000 hz 1 秒。正弦波嵌入在具有方差0.01 的白色高斯噪声中。
8 f& c6 ?7 b; p. s8 Q' S) g, `
- clc
- clear
- close all
- % Generate a signal that consists of a 25 Hz sinusoid sampled at 1000 Hz for 1 second.
- % The sinusoid is embedded in white Gaussian noise with variance 0.01.
- rng('default')
- Fs = 1000;
- t = 0:1/Fs:1-1/Fs;
- x = sin(2*pi*25*t) + randn(size(t))/10;
- % 计算序列的离散余弦变换。
- % 确定1000个 DCT 系数中有多少是显著的。
- % 选择1作为重要性的阈值。
- y = dct(x);
- sigcoeff = abs(y) >= 1;
- howmany = sum(sigcoeff)
- % Reconstruct the signal using only the significant components.
- y(~sigcoeff) = 0; %~ means not
- z = idct(y);
- % Plot the original and reconstructed signals.
- subplot(2,1,1)
- plot(t,x)
- yl = ylim;
- title('Original')
- subplot(2,1,2)
- plot(t,z)
- ylim(yl)
- title('Reconstructed')# Y$ Z' x }3 \
- g( V4 v% E3 a. }0 Z/ p
上面这段程序中,简单地做几点解释:
; \$ ]& U' ^9 [# e$ }6 L$ }; Q7 O1 B* m
sigcoeff = abs(y) >= 1;/ E$ S) C- @$ c+ d+ `$ J, ]
, n# O8 L% r$ x1 P% V由于1是阈值,所以判断向量y中元素大于阈值的元素个数,这条语句可以改写为:sigcoeff = ( abs(y) >= 1 ) ;这样可以更清晰。
1 Q4 J6 Q$ ]0 g9 X% G, D
( W5 v5 ^5 x7 l) fsigcoeff向量中得到的是逻辑值,元素1代表该位置的系数元素大于阈值。
# x5 a" H) k$ ^% _5 g- J+ R' |+ K* O3 w/ [2 u; N1 V
后面用语句:howmany = sum(sigcoeff);7 l- A7 ]2 c9 d: C5 d- J
+ }+ i+ c W6 V, I4 C& [0 M得到系数中大于阈值的个数,也就是重要系数个数。2 o: f& n2 J- C1 G
3 k0 a2 b* _8 E1 X8 o0 U
y(~sigcoeff) = 0; %~ means not
, V9 H0 w: F% o! A
0 S( ]8 _- r) w这条语句的意思是将系数中的不重要的系数都置零。9 D0 F, N3 l% z+ T! i: A
5 M8 @5 S d' R4 d& x. b, z
最后:yl = ylim;表示获取当前x,y坐标轴的限制。! L9 g' Q3 z7 M$ o
5 K( W" \( p( v! K F1 ?ylim(yl);表示当前画图的x,y坐标轴的限制和yl一致。
$ X$ C Z' |* p& ~! D' b% V
9 k' S0 J" z$ X* q" f结果为:
) ~0 `, @$ @' B6 K/ C, X; E
$ R! S, G7 D; Q9 r# N
5 I( V5 L5 P, l; L) m3 B1 E' I/ ~' J1 c6 U# F8 `" U; @# t. l
DCT Orthogonality
" p. J5 K2 O; B1 @" n2 i, \& H) |. f& \& V4 Y9 _2 S( X
验证离散余弦变换的不同变体是否正交, 使用随机信号作为基准。
4 b c0 _6 A+ H n% ]1 p0 s$ k
2 i7 g9 G1 \3 _- D6 i+ T5 {3 V: E从生成信号开始。
5 h, h8 r5 @( q" g3 A/ k8 T" J- w, x& f. J1 |* `
- clc
- clear
- close all
- % Verify that the different variants of the discrete cosine transform are orthogonal, using a random signal as a benchmark.
- %
- % Start by generating the signal.
- s = randn(1000,1);
- % Verify that DCT-1 and DCT-4 are their own inverses.
- dct1 = dct(s,'Type',1);
- idt1 = idct(s,'Type',1);
- max(abs(dct1-idt1))
- % ans = 1.3323e-15
- dct4 = dct(s,'Type',4);
- idt4 = idct(s,'Type',4);
- max(abs(dct4-idt4))
- % ans = 1.3323e-15
- % Verify that DCT-2 and DCT-3 are inverses of each other.
- dct2 = dct(s,'Type',2);
- idt2 = idct(s,'Type',3);
- max(abs(dct2-idt2))
- % ans = 4.4409e-16
- dct3 = dct(s,'Type',3);
- idt3 = idct(s,'Type',2);
- max(abs(dct3-idt3))
- % ans = 1.1102e-15! ?. z% L+ [0 n
$ F1 s' l4 z9 k/ z1 J, `8 A- W+ b! R, ]# x# S$ [& }
0 o# X. h9 e" v, U2 e N" U
|
|