ky027wh-sx

    只做了第4小题,放代码:

 1 // <<DSP using MATLAB>>3rd edition 
 2 // Book Author:Vinay K Ingle, John G Proakis
 3 //
 4 // Problem 2.3(4)
 5 // script by: 
 6 //
 7 clear, clc, clf();
 8 
 9 mode(2);
10 funcprot(0);
11 exec(\'fun_banner.sci\');          // output version and OS info
12 //exec(\'fun_stepseq.sci\');         // unit step sequence
13 exec(\'fun_sigadd.sci\');          // sign sequence add/substract
14 
15 // ------------------------------------------------------------------------
16 //            START        Output Info about this sce-file                 
17 mprintf(\'\n***********************************************************\n\');
18 [ban1,ban2] = fun_banner();
19 mprintf("\n     <DSP using MATLAB> 3rd edition, Problem 2.3(4)  \n");
20 mprintf(" ----------------------------------------------------------\n\n"); 
21 
22 // -----------END----------------------------------------------------------
23 
24 
25 //%%
26 //%% {...,1,2,3,...} + {...,1,2,3,4,...}     n=[0:24]
27 //%%      *                 *
28 //%%  what is the periods
29 
30 self_length1 = 3;
31 periods1 = 8;
32 
33 x1 = [1, 2, 3];
34 n1 = [0:(2+(periods1-1) * self_length1)];
35 xtilde1 = x1\' * ones(1,periods1); xtilde1 = (xtilde1(:))\';
36 
37 
38 self_length2 = 4;
39 periods2 = 6;
40 
41 n2 = [0:(3+(periods2-1) * self_length2)];
42 x2 = [1, 2, 3, 4];
43 xtilde2 = x2\' * ones(1,periods2); xtilde2 = (xtilde2(:))\';
44 
45 
46 //% x = xtilde1 + xtilde2
47 [x,n] = fun_sigadd(xtilde1, n1, xtilde2, n2);
48 
49 
50 f0=scf(0);                    //creates figure with id==0 and make it the current one
51 //  f.figure_size=[700,600];                // adjust window size
52 //  f.background=2;                         // add background color 8-white
53   f0.figure_name="Problem 2.3(4)";          // name window
54   subplot(3, 1, 1); 
55   plot(n1,xtilde1,\'bo\');
56   plot(n1,xtilde1,\'b.\');
57   plot2d3(n1,xtilde1,2);                      // Create plot with blue line
58 title("$Period\ Sequence\ \tilde{x_1}$",\'fontname\',7,\'fontsize\',4);
59 xlabel(\'n\',\'fontname\',3); ylabel(\'$\tilde{x_1}(n)$\',\'fontname\',3,\'fontsize\',3);
60 //xgrid();
61 xgrid(5,0,7);           // color, thickness, style
62 a0=get("current_axes");                // get the handle of the newly created axes
63 a0.data_bounds=[-0.1,24,-0.1,5];
64 
65 
66  subplot(3, 1, 2); 
67   plot(n2,xtilde2,\'bo\');
68   plot(n2,xtilde2,\'b.\');
69   plot2d3(n2,xtilde2,2);                      // Create plot with blue line
70 title("$Period\ Sequence\ \tilde{x_2}$",\'fontname\',7,\'fontsize\',4);
71 xlabel(\'n\',\'fontname\',3); ylabel(\'$\tilde{x_2}(n)$\',\'fontname\',3,\'fontsize\',3);
72 //xgrid();
73 xgrid(5,1,7);           // color, thickness, style
74 a1=get("current_axes");                // get the handle of the newly created axes
75 a1.data_bounds=[-0.1,24,-0.1,5];
76 
77 
78  subplot(3, 1, 3); 
79   plot(n,x,\'bo\');
80   plot(n,x,\'b.\');
81   plot2d3(n,x,2);                      // Create plot with blue line
82 title("$Period\ Sequence\ \tilde{x_1}+\tilde{x_2}$",\'fontname\',7,\'fontsize\',4);
83 xlabel(\'n\',\'fontname\',3); ylabel(\'x(n)\',\'fontname\',3);
84 //xgrid();
85 xgrid(5,1,7);           // color, thickness, style
86 a2=get("current_axes");                // get the handle of the newly created axes
87 a2.data_bounds=[-0.1,24,-0.1,8];
View Code

    运行结果:

    由上图可以看出,新序列的基本周期N=12。

 

分类:

技术点:

相关文章: