EDA365电子论坛网
标题:
MATLAB 信号处理工具箱之 idct 介绍和案例分析
[打印本页]
作者:
mytomorrow
时间:
2019-12-27 10:08
标题:
MATLAB 信号处理工具箱之 idct 介绍和案例分析
5 _* l8 `! O) J* ], N. Q! W2 l( G& L
有关idct的基础知识见:
MATLAB 基础知识之逆离散余弦变换(idct)
0 j, @1 b9 d0 F0 G
6 x8 s* m; c0 b+ h
idct
% H8 \: N! P9 _- m5 k
6 h5 ~5 H2 V) s
逆离散余弦变换
1 C& \" j1 A( f! \3 _1 p8 |' w
9 R; B/ i! ]( S. {
Syntax
& r# K) J9 `2 M. ~# ^3 ^
6 X) D" i% |) {# M
x = idct(y)
! H- Q- h! w6 F# z. N" c! D
* \* } D! _$ {( l+ }1 S) v+ V
x = idct(y,n)
) ?9 ]& q2 s6 D1 L# {
3 T/ ], m: U9 b5 J% g' o# p4 x: d2 r
x = idct(y,n,dim)
: ` p+ w9 O# ^* a$ [
& X% i5 Q; B' L, \. D
y = dct(___,'Type',dcttype)
. c" z( I5 t. J" Q
. O5 M( M! W1 Q
Description
8 |; a0 q: v; O: U6 q3 _" o
+ \" G3 `! v5 Y& z: s- d4 o' p4 x
x = idct (y) 返回输入数组 y 的逆离散余弦变换。输出 x 的大小与 y 相同。如果 y 具有多个维度, 则 idct 沿第一个数组维度运行, 大小大于1。
* J5 k: f* _9 y
9 [) d; i' ^; i2 [, y
x = idct (y, n) 填充0或截断 y 到长度 n 在转换前的相关维度。
! u( u; f; W$ w3 p
1 A/ Q# q! _; t' B* H
x = idct (y、n、dim) 计算沿维度dim的变换。若要输入维度并使用默认值 n, 请将第二个参数指定为空 []。
& W! Y0 J( |; o$ ~' X
) N2 b+ b7 \5 _5 w8 w! s5 b: J4 |' I; Z
y = dct(___,'Type',dcttype) specifies the type of inverse discrete cosine transform to compute.
. S, v" T1 C! ]- d, G: y4 Y
% h* N- i* ]9 M8 R
Signal Reconstruction Using Inverse Discrete Cosine Transform
. x- A6 t0 o( B2 d
: f% i3 H$ U( e- T1 v
生成一个信号, 由 25 hz 正弦采样 1000 hz 1 秒。正弦波嵌入在具有方差0.01 的白色高斯噪声中。
+ F1 ]6 {3 z- }4 V' {" J
+ y! J& u9 v: h9 k2 N
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& w3 I6 \3 X
) c& j" \/ z% U% G( y, d
上面这段程序中,简单地做几点解释:
$ c5 B" }: V; c3 _9 C+ x0 S
; D6 X/ z6 k, g: ~
sigcoeff = abs(y) >= 1;
6 v) K$ Z4 ^: B5 l% D5 `6 K7 O
. C" l: n: E" W5 B
由于1是阈值,所以判断向量y中元素大于阈值的元素个数,这条语句可以改写为:sigcoeff = ( abs(y) >= 1 ) ;这样可以更清晰。
, f1 J/ y% E( }2 [( x
& E: l# E5 C5 E9 [5 G+ j% y
sigcoeff向量中得到的是逻辑值,元素1代表该位置的系数元素大于阈值。
" S7 O5 B+ N" O
" T1 X! Z" i3 r4 H
后面用语句:howmany = sum(sigcoeff);
3 x* e) y9 |( P' E3 ^- z
d' G1 W. w- _4 o! |
得到系数中大于阈值的个数,也就是重要系数个数。
% h) ^" h: I' P ?# d* Y
9 _( f* [+ g, x2 }
y(~sigcoeff) = 0; %~ means not
6 [+ a J' J0 _6 w! L
% {6 v: [6 U1 g1 j+ P" N4 f( \1 o" p
这条语句的意思是将系数中的不重要的系数都置零。
$ T- B, Q% ]# m h8 @0 D/ d; t- \
% N' w5 y5 H# W
最后:yl = ylim;表示获取当前x,y坐标轴的限制。
0 ?2 W- Y7 z! q/ o( q
0 L# @, B* Y/ V& N
ylim(yl);表示当前画图的x,y坐标轴的限制和yl一致。
( k* w6 d( `) \* d% I5 S
( n- P1 s8 I5 k* I/ ]
结果为:
: h0 d J' `: M8 v: P7 {. J
+ V1 ?6 g3 O. V1 y
MATLAB 信号处理工具箱之 idct 介绍和案例分析.png
(40.38 KB, 下载次数: 7)
下载附件
保存到相册
2019-12-27 10:07 上传
3 U$ ^( ]( C/ _4 w3 n5 W
* ]0 c; ~) ~$ P6 R8 m1 n0 d0 x3 O
DCT Orthogonality
' g+ X* o7 d8 p. q5 E [* ?# g
0 S2 |- F+ i- n
验证离散余弦变换的不同变体是否正交, 使用随机信号作为基准。
: g+ m0 z! z6 N. `
+ @. S1 [0 J% z' c# T$ i
从生成信号开始。
6 i5 \) g1 B2 M
1 X. r" y$ p' K* L
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
+ J% o! k# B0 ^- A1 K# L, T
6 h3 J; M/ S# u* @
* U7 Z" d" z1 B, g
/ e# _: V8 S3 N) `2 ^' E' a
作者:
yin123
时间:
2019-12-27 18:28
学习啦,谢谢分享
欢迎光临 EDA365电子论坛网 (https://bbs.eda365.com/)
Powered by Discuz! X3.2