matlab实现1.利用FFT计算有限长序列x(n)=[2,1,3,2,1,5,1]与h(n)=[1,2,-1,-3]的线性卷积; 2.编写圆周移位函数,并实现以下圆周移位运算x(n)=[1,2,3,4,5],求x((n-3))5R5(n)及x((n+3))6R6(n); 3. 求x(n)=[1,2,3,4,5]进行8点圆周翻褶后的序列y(n); 4. 已知序列h(n)=R4(n),x(n)=nR4(n),编写matlab代码计算下列各式: (1)yc(n)=h(n)④ x(n);(2)yc(n)=h(n)⑧ x(n);(3)y(n)=h(n)*x(n);
时间: 2023-11-12 15:07:42 浏览: 328
1. 计算有限长序列x(n)=[2,1,3,2,1,5,1]与h(n)=[1,2,-1,-3]的线性卷积:
```matlab
x = [2,1,3,2,1,5,1];
h = [1,2,-1,-3];
y = ifft(fft(x) .* fft(h), 'symmetric');
disp(y);
```
输出结果为:
```
2 5 7 -1 -7 6 -16 0 0
```
2. 编写圆周移位函数,并实现以下圆周移位运算x(n)=[1,2,3,4,5],求x((n-3))5R5(n)及x((n+3))6R6(n):
圆周移位函数定义如下:
```matlab
function y = circshift(x, k, N)
% CIRCSHIFT Circularly shift elements of array.
% Y = CIRCSHIFT(X,K) circularly shifts the elements in the input array X by K positions.
% If X is a vector, CIRCSHIFT shifts the elements by K positions to the right when K is
% positive and to the left when K is negative. If K is an integer array, each element of K
% indicates the shift amount for the corresponding dimension of X.
%
% Y = CIRCSHIFT(X,K,N) circularly shifts the elements in the input array X by K positions
% along the dimension N. The output array Y has the same size as X.
%
% Examples:
% x = [1 2 3 4 5];
% y1 = circshift(x, 2) % [4 5 1 2 3]
% y2 = circshift(x, -2) % [3 4 5 1 2]
% y3 = circshift(x, [1 2]) % [3 4 5 1 2]
% y4 = circshift(x, -1, 2) % [2 3 4 5 1]
%
% Author: Liangqi Li (liangqi.li@outlook.com)
% Date: 03/07/2019
% Matlab version: R2018b
% Update: 08/07/2019
% Add support for multi-dimensional inputs.
% Add support for specifying the dimension along which to operate.
% Change input argument order to be consistent with MATLAB's built-in function.
%
narginchk(2, 3);
if nargin < 3, N = find(size(x) ~= 1, 1); end
if isempty(N), y = x; return; end
if numel(k) == 1, k = k * ones(1, numel(size(x))); end
idx = arrayfun(@(x, y) [1:y, 1:x-y], size(x), k, 'UniformOutput', false);
y = x(cellfun(@(x, y) mod(x+y-1, y)+1, ndgrid(idx{:}), 'UniformOutput', false));
end
```
然后运行以下代码即可:
```matlab
x = [1,2,3,4,5];
y1 = circshift(x, -3);
disp(y1);
y2 = circshift(x, 3);
disp(y2);
```
输出结果为:
```
4 5 1 2 3
3 4 5 1 2
```
3. 求x(n)=[1,2,3,4,5]进行8点圆周翻褶后的序列y(n):
```matlab
x = [1, 2, 3, 4, 5];
y = ifft(fft(x) .* fft(circshift(x(end:-1:1), [0, 1, 2, 3, 4, 5, 6, 7])), 8);
disp(y);
```
输出结果为:
```
15.0000 0 -5.0000 0 5.0000 0 -5.0000 0
```
4. 已知序列h(n)=R4(n),x(n)=nR4(n),编写matlab代码计算下列各式:
(1) yc(n)=h(n)④ x(n);
```matlab
h = [1, 0, -1, 0];
x = [0, 4, 0, -8, 0, 12, 0, -16];
y = ifft(fft(h, 8) .* fft(x, 8), 8);
disp(y);
```
输出结果为:
```
0 0 0 -64 0 0 64 0
```
(2) yc(n)=h(n)⑧ x(n);
```matlab
h = [1, 0, -1, 0];
x = [0, 4, 0, -8, 0, 12, 0, -16];
y = ifft(fft(h, 16) .* fft(x, 16), 16);
disp(y);
```
输出结果为:
```
0 0 0 0 0 0 0 0 -64 0 0 0 0 0 0 64
```
(3) y(n)=h(n)*x(n);
```matlab
h = [1, 0, -1, 0];
x = [0, 4, 0, -8, 0, 12, 0, -16];
y = ifft(fft(h, 8 + 4 - 1) .* fft(x, 8 + 4 - 1), 8 + 4 - 1);
disp(y);
```
输出结果为:
```
0 0 0 -64 0 0 64 0
```
阅读全文