|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
* q4 Q: l! v5 S2 Q9 j" ^& C有关idct的基础知识见:MATLAB 基础知识之逆离散余弦变换(idct)
3 r1 O3 m: m& ~) C, C- n1 i l# H6 s2 Q
idct
* a0 @7 ]7 L" i0 ?
4 j9 M& Y6 Z& ~9 d逆离散余弦变换; U0 x# Q+ V8 s+ \
1 D1 }8 `: t1 F8 `) s
Syntax
2 |- K; ]) o+ S, o- [ n/ y$ L! M* |9 b' e7 ]7 y3 _! p6 b
x = idct(y)
6 [7 Z' L) v. Q; s1 m- [9 w
8 q- n( I" f- Hx = idct(y,n)% R, {/ o% J" g; u5 O" @
N5 T: v5 E2 z! rx = idct(y,n,dim)+ j' B( W# P: j8 l$ Q
- ? ~0 q9 ^8 b- h
y = dct(___,'Type',dcttype)2 v1 c; b: G" j
& ]0 B7 ]% m( b0 v8 E! RDescription
& |* q8 E4 Q! e$ p$ B& s8 m! [9 \" x; Q) F- K' @# l0 z8 h* S
x = idct (y) 返回输入数组 y 的逆离散余弦变换。输出 x 的大小与 y 相同。如果 y 具有多个维度, 则 idct 沿第一个数组维度运行, 大小大于1。7 \! P/ n6 T/ f1 L' d/ H
# \! }8 O2 S) ?6 Ex = idct (y, n) 填充0或截断 y 到长度 n 在转换前的相关维度。' c; w& m' f" n& c! `+ m+ V
* z( Y! p8 N, Fx = idct (y、n、dim) 计算沿维度dim的变换。若要输入维度并使用默认值 n, 请将第二个参数指定为空 []。
+ u$ Q$ P# l2 [* _1 `' l. S+ w& C* H* H: f
y = dct(___,'Type',dcttype) specifies the type of inverse discrete cosine transform to compute.
' z& V/ ~, s% b+ v" G) ^4 |4 P% l7 i$ j7 P- a( v5 c
Signal Reconstruction Using Inverse Discrete Cosine Transform
2 F2 z" W' O8 O6 V$ D8 y" D* l# a0 H2 s0 U8 ]
生成一个信号, 由 25 hz 正弦采样 1000 hz 1 秒。正弦波嵌入在具有方差0.01 的白色高斯噪声中。/ e x, a4 d3 w7 X5 T
$ {+ a) M7 \: Q5 y9 c9 U- 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')2 @9 {$ p: n5 Q9 s! M4 G$ l2 i5 m
3 G& R7 R" M# X Z- b
上面这段程序中,简单地做几点解释:5 `# t5 h; m( ]- Q' M9 F* g3 v
/ ^, U, P, w m5 S1 \3 U8 k5 fsigcoeff = abs(y) >= 1;$ m1 x% U# E& U. S$ h# W! j: x2 i
2 P2 y) I+ J* Z* r由于1是阈值,所以判断向量y中元素大于阈值的元素个数,这条语句可以改写为:sigcoeff = ( abs(y) >= 1 ) ;这样可以更清晰。" M# D3 T" G* F+ c
# G7 p9 ]/ k! j; k4 Nsigcoeff向量中得到的是逻辑值,元素1代表该位置的系数元素大于阈值。. I* O& S( P. V& D9 W+ V
' q4 X) ~* O8 S9 v8 I
后面用语句:howmany = sum(sigcoeff);
% N$ F, f( E2 n) B) e9 `
7 A) ^+ V$ e9 g9 ]0 O( z得到系数中大于阈值的个数,也就是重要系数个数。
8 [7 U/ R2 `0 e! l! |) _2 o6 L& D( |0 j7 p9 }5 b' }$ D
y(~sigcoeff) = 0; %~ means not
x1 M' L+ V3 {+ T* N4 j9 v, m; C7 j
这条语句的意思是将系数中的不重要的系数都置零。8 `/ P) v% I* t3 P# @
5 O/ X2 `7 x3 a" L
最后:yl = ylim;表示获取当前x,y坐标轴的限制。
, Z$ ^5 [5 R. S+ P
, H# p, `( }2 c+ }ylim(yl);表示当前画图的x,y坐标轴的限制和yl一致。6 a7 R7 @, `" l3 u: P& z
$ H7 @+ g$ O' B( P! Y* F- i9 A
结果为:
. ~& V7 n: m n8 z( d9 G# t; ?- G2 P4 V
E. P, M7 `$ m0 g5 v
: i% X, _ q2 p- _" I: S$ Q* m
+ ?- R. C0 |" d v! f% k. QDCT Orthogonality1 W) Z9 R. t( A c4 [
# q* J9 p4 |; M, a验证离散余弦变换的不同变体是否正交, 使用随机信号作为基准。
; I, K; B+ V: d/ U+ z
t9 {/ y( M: ]& [% m5 k% [! y从生成信号开始。
$ c5 R8 w# C, @2 a8 Y: e% F q* C( C3 h1 B/ t2 F0 x
- 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
5 c% P. C# D( U& C: U# b1 O ( v/ w7 {, P9 g) d4 H6 X1 o, S
0 g& |# I; W0 _) `' @/ P, l7 K6 g5 N+ n E3 q; |7 I. `
|
|