|
|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
7 ~% D2 B1 Z/ `6 b5 M4 v G F% V
有关idct的基础知识见:MATLAB 基础知识之逆离散余弦变换(idct)2 K+ [9 u/ Q9 p S
l- E( t: f, i* F+ widct
( |4 N' F. E+ L1 J* q8 V8 o0 d8 k
9 {8 W: K5 T2 m% A: H A逆离散余弦变换
. |) m. Z# K1 j9 ?* b6 J, y* E! c
! Q, s. G# w6 U3 e- ASyntax
" @$ N u, ` }7 F
8 }1 d0 | H) ]; u, U& Tx = idct(y)
+ j; K& x# T) y3 S w1 L3 [5 B* }8 h% ^( s, k( d
x = idct(y,n)( {7 C$ m/ A( s& p
0 I( L/ d4 t' f- M" Q5 w
x = idct(y,n,dim)
6 i# }5 a! s( H5 k; ^- l
7 q& T2 ?7 ?! L. Hy = dct(___,'Type',dcttype)
' ]% t! p# r5 `4 H3 A
% m# u* Y h( XDescription4 ?' e/ B) b% x1 f. o- W# s
8 L- @+ B7 \+ }, v% E* Z Ax = idct (y) 返回输入数组 y 的逆离散余弦变换。输出 x 的大小与 y 相同。如果 y 具有多个维度, 则 idct 沿第一个数组维度运行, 大小大于1。" Y3 t [6 G6 U: g) X" F
' q& c. J, r$ v% Zx = idct (y, n) 填充0或截断 y 到长度 n 在转换前的相关维度。2 C; }; Q" {2 ]& D$ Y
9 s- ]& I( h. R3 D; L( o' z
x = idct (y、n、dim) 计算沿维度dim的变换。若要输入维度并使用默认值 n, 请将第二个参数指定为空 []。5 C' E+ o" r* x n4 t3 C
. p7 v" ]+ _: F6 H; v& q6 t' B
y = dct(___,'Type',dcttype) specifies the type of inverse discrete cosine transform to compute.
& `* u( M4 `$ x8 e+ r1 W3 [
) j1 H( O4 V: Q( m; jSignal Reconstruction Using Inverse Discrete Cosine Transform5 \# U( p& w3 v2 g) m, }% G
# n# I. s- s( b3 C( u! z. U! @生成一个信号, 由 25 hz 正弦采样 1000 hz 1 秒。正弦波嵌入在具有方差0.01 的白色高斯噪声中。0 S) s" m* Z0 s3 F V, ~
1 o5 I _6 {! N9 n/ _ c; 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')
% f% t1 ?: O L/ k$ b; |0 d 3 f8 s1 T6 ]) g
上面这段程序中,简单地做几点解释:
$ L* U+ a% n0 E9 Y, O1 ^% {2 _9 R, ~8 Y1 z6 u
sigcoeff = abs(y) >= 1;
# r3 y7 F2 @& R: |1 Z+ \8 z
! A: z9 _# m: _由于1是阈值,所以判断向量y中元素大于阈值的元素个数,这条语句可以改写为:sigcoeff = ( abs(y) >= 1 ) ;这样可以更清晰。
; ?7 I7 k7 o8 L4 ~) I& t0 M, n/ t4 C( o+ W$ R$ p& N
sigcoeff向量中得到的是逻辑值,元素1代表该位置的系数元素大于阈值。
: X3 R+ d+ z0 ^1 R8 S; a# d8 q! X* Q# s( Q
后面用语句:howmany = sum(sigcoeff);
! p T3 i1 E; K5 d' b5 A& p) E2 ~
得到系数中大于阈值的个数,也就是重要系数个数。: u% r1 ?2 v P% d7 r6 d% n. \
. G7 s0 m+ _+ W$ H s
y(~sigcoeff) = 0; %~ means not . J$ [/ H( {, L
' I6 n% {9 M# l) s! Q4 y8 n+ t
这条语句的意思是将系数中的不重要的系数都置零。
& S3 M, l- `* s4 T( r6 s* M/ L9 l8 |# \- X
最后:yl = ylim;表示获取当前x,y坐标轴的限制。( H& A, K! I4 ?% w) g/ ^
! ?2 Y2 P0 A8 Y) d6 \! d4 oylim(yl);表示当前画图的x,y坐标轴的限制和yl一致。
/ O; L! `$ P- |" @9 J5 ?- ]+ C& ~- J' d( c
结果为:# v2 G- {* e; z
+ ?! @' Y6 g5 ]# B, _# a4 G7 ]
, f* X) J* R) d2 d. R% C8 M j' L. l! u9 f7 U6 S8 f2 w
DCT Orthogonality: h3 N0 f4 u! U
/ [$ K+ g6 C7 I3 ?) |3 l验证离散余弦变换的不同变体是否正交, 使用随机信号作为基准。' Y, ^/ P& z$ }6 \ v6 Y
# J8 D/ S) {& K8 {
从生成信号开始。
. ]6 n' _2 |) o& @" Z- f I
4 G1 E$ H# ]/ I: M, ~* `- 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% t# _$ P+ U, [% b9 u Y
% L1 E7 U' `5 k2 \$ ^- ~
, B8 B, E& ]3 Y; e% L" ?9 [
4 u7 G8 B" f# n! A; [7 [( t |
|