# matlab同一个代码结果不同,为什么当我使用相同的表达式定义函数时,matlab内置函数的结果与我得到的结果不同?...

https://www.mathworks.com/help/signal/ref/hamming.html

)为了进一步分析相同的信号,但是我遇到了一些不寻常的问题,当我使用内置函数Hamming(L)时得到了错误的结果,当我用Matlab中定义的相同方式编写函数时得到了正确的结果。代码如下:

%This is a signal i am analyzing and it has N points.

F1 = 55/450;

F2 = 67/450;

N = 450;

n = 0:(N-1);

x = 50*cos(2*pi*F1*n)+100*cos(2*pi*F2*n)

% Here is the code for plotting the signal in N points

figure

n = 0:(N-1);

stem(n,x);

xlabel('n');

ylabel('x[n]');

title('Discrete Signal x[n]');

pause

% Here i am using a built in function. It is of length N, the same as x[n].

n=0:(N-1);

window1 = hamming(N);

figure

y1 = x.*window1; %The proper way of windowing a function.

stem(n, y1);

title('Windowed Discrete Signal y[n]');

pause

% This yields some nonsensical graph even though the window function itself graphs properly.

% Here i looked at the expression on the site which is used for the built-in matlab function and wrote it myself.

n=0:(N-1);

window2 = 0.54-0.46*cos(2*pi*n./N);

figure

y2 = x.*window2;

stem(n, y2);

title('Windowed Discrete Signal y[n]');

pause

% Here it graphs everything perfectly.

• 0
点赞
• 0
收藏
觉得还不错? 一键收藏
• 0
评论
03-16 2190
03-23 914
04-05 416
10-22 376
09-18 1297

### “相关推荐”对你有帮助么？

• 非常没帮助
• 没帮助
• 一般
• 有帮助
• 非常有帮助

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、付费专栏及课程。