|
|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
4 Q! i9 f! g$ V# k6 n+ O9 K' S有关idct的基础知识见:MATLAB 基础知识之逆离散余弦变换(idct)
" U- }- w" e4 ^1 u
: T$ @4 p& j. H% a2 T! e7 q# h+ O2 Kidct& z6 v" I! B8 g/ r
" t' d) R- V; W; @2 f逆离散余弦变换
4 l$ D9 O& O6 d( g" N5 f; q% a3 n' m" `
Syntax& C: N. \5 d1 @, C( X0 c; C5 |; n% y
' Z/ V$ F* l7 fx = idct(y)
( c) v1 K3 G" @; n6 |+ N
- j9 r1 d( K* d# Z3 s; Vx = idct(y,n)
3 m- u+ \$ H! D6 T8 P" V: P9 O7 \
x = idct(y,n,dim)
6 j4 U" Y4 F4 w+ i) K
- u- M) u5 O7 y* V% X$ i5 W" ny = dct(___,'Type',dcttype)$ O' A! l- o2 M3 c% K
+ g" [' }3 X; ~Description
^* b' Z1 a. j( P; h2 X. q( o6 \3 d+ `" E4 F" M0 J
x = idct (y) 返回输入数组 y 的逆离散余弦变换。输出 x 的大小与 y 相同。如果 y 具有多个维度, 则 idct 沿第一个数组维度运行, 大小大于1。. V% v7 ?2 d& u4 h! O+ }" m
. d1 [$ E. y% x6 x3 n/ i8 z+ g
x = idct (y, n) 填充0或截断 y 到长度 n 在转换前的相关维度。% T+ b+ u# E9 R
2 a4 q" `4 p. e: P- T% H
x = idct (y、n、dim) 计算沿维度dim的变换。若要输入维度并使用默认值 n, 请将第二个参数指定为空 []。* g) G. P6 d% m* S q/ Z$ [
' P( B) y1 @( H# y
y = dct(___,'Type',dcttype) specifies the type of inverse discrete cosine transform to compute.
) _2 r" j4 j0 E& q$ W& _1 ~# F1 V) P8 `5 S! k
Signal Reconstruction Using Inverse Discrete Cosine Transform
z8 U; F* j7 g1 M0 r m0 q/ o' U% I/ _' s( q! r) ]* P5 u$ o
生成一个信号, 由 25 hz 正弦采样 1000 hz 1 秒。正弦波嵌入在具有方差0.01 的白色高斯噪声中。4 ]' c: P6 M& [/ f+ V/ [
+ J7 Y9 M {$ ~& _7 D) l" t
- 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')
; V, T5 m v/ W' _4 f1 F7 k& m$ J
" R' r* B |$ |& [上面这段程序中,简单地做几点解释:
* s. a' V5 \2 Z- A
5 e: U8 }6 R% y$ Nsigcoeff = abs(y) >= 1; ?/ r/ H% J( V0 U4 t, a
9 ]; d$ r" O+ f由于1是阈值,所以判断向量y中元素大于阈值的元素个数,这条语句可以改写为:sigcoeff = ( abs(y) >= 1 ) ;这样可以更清晰。
' Y5 B, v) m+ q8 G
w6 D# F1 c0 N5 C0 A* B: Nsigcoeff向量中得到的是逻辑值,元素1代表该位置的系数元素大于阈值。
7 E" P9 [. x) E0 k- `
$ H/ m1 {/ |/ G后面用语句:howmany = sum(sigcoeff);
0 Z" D) d# g, y' b0 d* g* e" d! S7 b) d' j
得到系数中大于阈值的个数,也就是重要系数个数。
" x& z" [) k4 O
7 ^- Q3 E2 N7 M( {) }9 i; J, Y* s' \y(~sigcoeff) = 0; %~ means not
- |5 c- b# s' h( y% ?- r+ s
7 V( V8 |2 i# s4 N; P' ]( m这条语句的意思是将系数中的不重要的系数都置零。
% ]1 D3 t$ K. q8 ~" v$ U. z- K4 s
最后:yl = ylim;表示获取当前x,y坐标轴的限制。
7 v5 A/ J( W4 e( u8 f
+ j6 r# S9 t4 V% d' M9 g7 v) |7 G# I- Zylim(yl);表示当前画图的x,y坐标轴的限制和yl一致。% D8 e7 k3 p O( I! @( H- x7 L9 `
0 D2 c8 ^% S7 W' W! G, J结果为:3 E% P2 {- d/ C
+ L) S# r4 }, _; {8 l
" V+ G+ H; Y+ I4 h4 }- t. U
" |# b8 @; D$ g
DCT Orthogonality$ L# K3 _' W/ a, M; B
# s% G l+ R3 ~. r验证离散余弦变换的不同变体是否正交, 使用随机信号作为基准。
) K% W9 v" {) r0 c+ b8 g6 K# H
& r3 {2 Y, M& v+ B5 ^9 J2 K. ~从生成信号开始。, A+ d6 j: Z- u# d( q; r3 M+ w
& K4 d; X2 i' I* _! r. b0 W5 l9 K2 h
- 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, j6 P- R0 j. V" U! J
; `) k+ d3 t! G; I
( e$ r' G" K0 n ], J) i% A @7 y8 j
. M | j8 }+ J9 r |
|