|
|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
( x% ~8 v9 G5 }1 }9 b5 c' v7 D有关idct的基础知识见:MATLAB 基础知识之逆离散余弦变换(idct)
z! m K5 q+ e E3 e& X' m# r4 c2 _2 P. z' S! `. U
idct
2 l+ c, A) M- D, l, y3 l3 g- l/ C+ t. L/ s
逆离散余弦变换
$ M# |1 k. Y0 a' R- c7 D" D
% R: k3 }5 E4 W7 KSyntax7 j1 r3 Q: u; ^1 j
: h a# S( o1 S6 A+ M+ jx = idct(y)9 r& X2 {1 j" b. e+ i
1 S8 Q8 ]# X. z/ D
x = idct(y,n)2 r! o7 K! n6 {! A5 e. U
3 I @9 \. O0 G( }3 O6 \x = idct(y,n,dim)7 R$ Y. b- O6 ^, D/ C6 B
3 I0 w7 \$ E9 D0 ]y = dct(___,'Type',dcttype)# p. S; Z2 S! \& e* y; M
+ ~4 e9 ~# U' {/ i1 xDescription
* d5 N( i. s& _- s& Y$ a5 E$ ^) R- @: W h
x = idct (y) 返回输入数组 y 的逆离散余弦变换。输出 x 的大小与 y 相同。如果 y 具有多个维度, 则 idct 沿第一个数组维度运行, 大小大于1。 v& U' r+ V' w {7 P7 g" b
* R/ _' A, @, ?- _x = idct (y, n) 填充0或截断 y 到长度 n 在转换前的相关维度。# _. q, B/ z+ D( G5 e" I7 M- m
! x9 }8 _3 n+ {3 A7 _x = idct (y、n、dim) 计算沿维度dim的变换。若要输入维度并使用默认值 n, 请将第二个参数指定为空 []。
% Y( w6 }7 q. k3 o* f9 V+ d2 S
: ]" A0 f2 @. {y = dct(___,'Type',dcttype) specifies the type of inverse discrete cosine transform to compute. ( N1 b0 M. p: l" s
9 H4 R. `* ^" \% _8 E7 zSignal Reconstruction Using Inverse Discrete Cosine Transform e: G3 [, U* S' q" y
, i9 A) U p! @7 i8 \- r; ]生成一个信号, 由 25 hz 正弦采样 1000 hz 1 秒。正弦波嵌入在具有方差0.01 的白色高斯噪声中。
+ K7 ~: z/ ]8 ?* a0 V2 `4 J' H" W, V: D& S' `) U! M$ L) v
- 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')6 t( `2 j- z" W- `9 f
- V9 y. `- x" F上面这段程序中,简单地做几点解释:
- [* V; e; I. T( o, W4 G x( @
9 f& K5 ^9 W8 `# d- tsigcoeff = abs(y) >= 1;2 Q: _. D6 K/ _& t6 d! U% f
& x1 Y. r+ ~3 [* G
由于1是阈值,所以判断向量y中元素大于阈值的元素个数,这条语句可以改写为:sigcoeff = ( abs(y) >= 1 ) ;这样可以更清晰。
( ~- e+ \5 V% X! X5 `! j# b+ M3 c/ u
sigcoeff向量中得到的是逻辑值,元素1代表该位置的系数元素大于阈值。# F: o- r+ H5 P. p2 A8 k
* L0 ~0 y' Q; _' \# [8 ~后面用语句:howmany = sum(sigcoeff);
+ {. y( Z; v; x* Z9 e* ~7 j" U* j: T" H
得到系数中大于阈值的个数,也就是重要系数个数。
. l! ]: n# c3 v$ {* B! W0 t0 N+ Y
y(~sigcoeff) = 0; %~ means not ; D7 I8 s( Q/ @9 I
8 l0 p* `, f# n6 y* C, B2 C
这条语句的意思是将系数中的不重要的系数都置零。
) o1 i- C" k9 u, Q a6 g$ ^
6 O5 ^* z3 C" [$ T5 R) o# q最后:yl = ylim;表示获取当前x,y坐标轴的限制。
1 @7 M) `+ H9 Y3 F: n
+ H! }$ _' w0 q j/ u1 Xylim(yl);表示当前画图的x,y坐标轴的限制和yl一致。6 f( O; p& ?, t
9 m, Q( k% f3 L* O, {6 ]6 J$ J7 F结果为:
" Z6 b' p* [* }+ d8 B) E% o8 @$ B8 |" V" h! f9 @+ L
d: J5 O; W6 O# D$ m) I2 B. K. p2 }6 l/ d5 W: K
DCT Orthogonality9 ^3 K6 t$ { o8 p0 \
: q2 ^6 e; f* y" D+ |' t1 M; n验证离散余弦变换的不同变体是否正交, 使用随机信号作为基准。4 H& S# L8 t) j
# k* _- U3 I# Z$ A$ ?
从生成信号开始。
( }9 i8 F9 y1 } J# W! j: w/ _. W9 H+ o2 n, V! C
- 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-150 ^2 a, y/ b u5 g9 g3 R4 f
; w6 M' N/ E( e
{- ~7 D3 c6 T. O/ [
2 o3 Q- n* Y7 _. D5 H4 [( W$ {
|
|