|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
& s6 l( e! {- k5 a/ P0 H有关idct的基础知识见:MATLAB 基础知识之逆离散余弦变换(idct)
n) z1 ]4 P: b* D* X9 {8 V& R) O: w* q5 S2 K8 L
idct0 Y3 Q S! Y( Z' \; V9 [
- V& F/ q9 F: o# `& u- d
逆离散余弦变换4 J- g7 r z1 p3 R- E
- s! L7 q: ?- y6 _, [
Syntax
. u& ?/ V' P* ]* H. ~( V5 p3 y, _. n' e
: a; Q8 T- f$ Lx = idct(y): ~% S" u0 k, P/ \8 z1 @2 \% J
: f2 F7 f4 f$ v1 n+ n7 Tx = idct(y,n)
( Z8 _# ^/ S2 G( R' J' Q& V( u) t: w+ b+ z
x = idct(y,n,dim)
8 S) V# p+ ~: W6 {. P6 D5 K( b7 }9 {3 L
y = dct(___,'Type',dcttype). q' N$ c+ `6 S2 g
1 n1 Y2 S/ t x% P
Description9 J3 \+ `) n1 K. |
6 Z6 G: A$ o: H1 j. cx = idct (y) 返回输入数组 y 的逆离散余弦变换。输出 x 的大小与 y 相同。如果 y 具有多个维度, 则 idct 沿第一个数组维度运行, 大小大于1。
% O3 ? D- W7 I# G" z- c, c. r8 J! G# P3 V2 |
x = idct (y, n) 填充0或截断 y 到长度 n 在转换前的相关维度。
; |5 K9 i) d; e7 I) z/ p7 Y. ~' D# I# K1 k
x = idct (y、n、dim) 计算沿维度dim的变换。若要输入维度并使用默认值 n, 请将第二个参数指定为空 []。
2 h! }8 }4 d2 S) U, J
" W$ p7 C! z# p7 m2 Dy = dct(___,'Type',dcttype) specifies the type of inverse discrete cosine transform to compute.
' ?8 {* t+ Q$ }( ^0 l& }2 K
9 c& K" V/ \* A# H5 ~0 x4 [% n. LSignal Reconstruction Using Inverse Discrete Cosine Transform* f& y8 E( t$ a6 R1 \
' V' ~% K% q) T* G% C/ L$ j& T: |: f生成一个信号, 由 25 hz 正弦采样 1000 hz 1 秒。正弦波嵌入在具有方差0.01 的白色高斯噪声中。
& y5 |, [1 `; B& v l* k! {+ e2 \: Q
- 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')
c) n% J1 V0 P! I+ f + j9 d/ @1 ?+ R% S4 q
上面这段程序中,简单地做几点解释:6 _* ~9 v# K, j+ J1 ?
: v$ w8 N6 L+ S$ X q$ gsigcoeff = abs(y) >= 1;
5 H( \, v* ~9 u5 b% \$ k3 {! |2 F
由于1是阈值,所以判断向量y中元素大于阈值的元素个数,这条语句可以改写为:sigcoeff = ( abs(y) >= 1 ) ;这样可以更清晰。8 P" Z i- P! S
1 i! @$ U+ d3 k8 l! Usigcoeff向量中得到的是逻辑值,元素1代表该位置的系数元素大于阈值。 I/ f& D- O$ t' d8 C6 W# Q# C) t* M
( G: h; o. J3 Q: H后面用语句:howmany = sum(sigcoeff);. s, \; L0 K2 a$ G$ g
5 n5 Q" `& N9 R6 Z得到系数中大于阈值的个数,也就是重要系数个数。 F* r% w9 E4 G1 X, \5 R
- y) l6 g# K0 S! P! ~
y(~sigcoeff) = 0; %~ means not
, R5 f1 V1 O7 Z9 @( @$ z
* c# L) p6 J R# [; o3 k: U7 l这条语句的意思是将系数中的不重要的系数都置零。
/ u) W5 ~# Q R4 I2 w( m: K# l9 n" z, h1 \2 O# N
最后:yl = ylim;表示获取当前x,y坐标轴的限制。
0 N8 I/ T+ J' R! Y
% W1 r# n9 o! d! }/ oylim(yl);表示当前画图的x,y坐标轴的限制和yl一致。$ ~6 K8 X! d' C6 s9 Y# e
+ w# w$ u: h. T, u& |+ y
结果为:
1 v+ t/ j6 j' D+ K) M, ], O# f/ Y1 F% g2 R( j
2 G' Z' k5 i$ y* g& G9 E9 \+ n' B
" J8 t/ V7 ^: U( xDCT Orthogonality: e, g, s" D& B; ^
, m0 [8 `6 A$ P& i7 d
验证离散余弦变换的不同变体是否正交, 使用随机信号作为基准。: L+ j8 _1 T. D% r4 y
! n7 P+ @& B1 V8 e { Q) N从生成信号开始。
. A. c* s5 w4 m' I! L
5 }: }1 ?8 k8 x5 M" ]9 `- 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- k, B6 } J; V; G, W3 Q
7 n$ y& m3 E5 ?$ Q" Z" _7 @$ ~& z- p' ?
0 {: d: A) j3 O; \% n
|
|