|
|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
* ]5 a6 i% P, i, f
有关idct的基础知识见:MATLAB 基础知识之逆离散余弦变换(idct)
" ~! u" n8 X$ v) b* A
- H- O) K8 I2 v+ m2 S& k; ridct7 d& D( ~- y X' S" b6 s
' ~+ Z* |: M5 n8 o! c" A# W逆离散余弦变换
, f$ F+ ^' R/ @5 ^6 s# e
4 J. l0 w: h2 M* l: P( x) E: LSyntax1 y. d+ _% \# ?1 ]
9 z$ J$ e+ \2 ~
x = idct(y)
; A6 r* e7 Z( v& ]5 U& u& P# D# _/ K _3 v# E3 M3 x
x = idct(y,n): b( x$ t$ S! I0 n/ M
5 x3 p1 r1 k' ~. Z8 U, n1 r; Q) U
x = idct(y,n,dim); p& e. w. c, k7 B$ W! N& O, i
4 e2 @: a9 i. l8 \y = dct(___,'Type',dcttype)
3 o+ e" k' w; n6 G/ T0 a* P3 _0 ?6 X: J! o* `6 v
Description1 y: n8 H) W9 B/ g8 E4 E
3 {7 J e {/ k! ix = idct (y) 返回输入数组 y 的逆离散余弦变换。输出 x 的大小与 y 相同。如果 y 具有多个维度, 则 idct 沿第一个数组维度运行, 大小大于1。' E6 h2 z3 Y0 H1 t' Z) a
4 R# f1 S. h9 H2 k5 y
x = idct (y, n) 填充0或截断 y 到长度 n 在转换前的相关维度。
% N' ?3 G) ~& N' q7 W3 |8 z& o. K2 Q
& L! k, q6 ^4 R z! P5 nx = idct (y、n、dim) 计算沿维度dim的变换。若要输入维度并使用默认值 n, 请将第二个参数指定为空 []。
( n1 f5 l2 R3 f3 x
U$ y# i, L& S% u( c0 ]% My = dct(___,'Type',dcttype) specifies the type of inverse discrete cosine transform to compute. : z- [( b5 x* z2 ]8 G+ m' j& L
+ @' Q1 ^+ V" OSignal Reconstruction Using Inverse Discrete Cosine Transform9 p8 _( { k/ ]# I4 r
% n, ]9 F5 K. V2 ~( |/ [1 n$ l生成一个信号, 由 25 hz 正弦采样 1000 hz 1 秒。正弦波嵌入在具有方差0.01 的白色高斯噪声中。
; A5 O7 t( ^- Z* g, i( o9 z% H# n6 a; ?
- 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')
- H- ]; S$ d! l5 M( X
" Z b2 Z) R% ]: C3 h" |) U' g上面这段程序中,简单地做几点解释:
+ D$ H! d5 M8 Z0 T4 u& u
+ O7 ^7 _; b& p/ L! F Zsigcoeff = abs(y) >= 1;/ E4 |) [) b6 h6 J$ s
' X; s9 j& f4 j0 L# V2 s9 D& V: |
由于1是阈值,所以判断向量y中元素大于阈值的元素个数,这条语句可以改写为:sigcoeff = ( abs(y) >= 1 ) ;这样可以更清晰。
; e! |6 t4 W$ C3 y+ q
; E! J, I; S; }% ysigcoeff向量中得到的是逻辑值,元素1代表该位置的系数元素大于阈值。
5 \9 H9 t% v7 O
* F) J5 s: O( u$ B) @+ Y" c G后面用语句:howmany = sum(sigcoeff);6 N6 L5 ]; [ [2 l" s* p6 T7 B, M
) y) C9 B4 i4 p# Q5 Q# [9 {4 n" W+ s得到系数中大于阈值的个数,也就是重要系数个数。7 S, ?: ?: _1 a- }: l0 t' ]
. R# N- I3 i% Z* cy(~sigcoeff) = 0; %~ means not
( @ U* {$ N5 p' N! Y: w }4 Q/ u- i% p% ]4 p: O$ q( p5 V8 n
这条语句的意思是将系数中的不重要的系数都置零。+ j" T Z% {; g% J. U/ T
1 @. W0 E- B! ]1 u5 W最后:yl = ylim;表示获取当前x,y坐标轴的限制。
( o/ `% K% e l* ?8 j( Q+ X' `- K) v: l' j
ylim(yl);表示当前画图的x,y坐标轴的限制和yl一致。) L7 ?6 f$ b6 |( L+ k/ S
% ], @( ?" l5 \/ {# U
结果为:9 f. s: U) s; |! B! _9 u( p1 b
& ~) {' @2 D+ j) s6 b
0 r5 i( ~; @7 E0 ]2 ^' o
6 n' ^+ z: t3 W& E Z7 QDCT Orthogonality) r7 O* S! _' q. c4 H5 }# q$ n* O9 b
. z: Z+ [/ j% f5 {( @. U9 I _+ r6 O: N
验证离散余弦变换的不同变体是否正交, 使用随机信号作为基准。
. z, ~. u5 g& h+ e5 L. M2 m7 v& \ l4 e% n* n
从生成信号开始。
0 Y8 T2 ^+ Y* L* f' @) ` E- `& c3 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-15
. }2 T$ t5 n* A* D$ s- e
& J' j' |! J" s, J7 x2 g9 `% y# r8 R# g2 B8 D6 }
- t% C/ ? N4 b# S7 z |
|