在matlab中绘制余弦函数

时间:2017-09-19 16:27:19

标签: matlab fft cosine

我有自协方差函数,我需要证明它的四重变换是信号的频谱。此外,我还有另一个函数,它以指定的循环频率w0给出频谱。

在脚本的第一部分,我给你第二个函数(SN变量),它正确地给出了所需的结果。在第二部分是错误的,第二部分是功能(KN变量)。他们有可能给出相同的结果吗?

clear
clc
close all

%%

% part 1 with correct plots

N = 10^6; %samples
t = 1:N; %time axis
t = t/N;

T = max(t); % T=1
M=1; % components

sigma = 1;
A= 10;
w0 = 10;

w = linspace(0,20,N);  

S_N = zeros(1,N);

tmp1 = (A^2*sigma^2)/(2*pi);
tmp2 = (w.^2) + (w0^2) + (sigma^4)/4;
tmp3 = ( ( ( (w.^2) - (w0^2) - (sigma^4)/2 ).^2 ) + (sigma^4).*(w.^2) );

S_N = tmp1 .* ( tmp2 ./ tmp3 );

figure;
semilogy(w,S_N);
grid on
xlabel('circular frequency')
legend(' Α=10, sigma = 1 ');
title('Spectrum of N(t) equation 8');

%%

% part2 with problematic plots

KN = zeros(1,N) ; %total autocovariance

tmp1 = A^2/2;
tmp2 = cos(w0*t);
tmp3 = exp(( -1/2) * (sigma^2) * abs(t));

KN = tmp1 * tmp2 .* tmp3;

FFTKN = fft(KN);
FFTKN = abs(fft(KN));

%%
figure;
semilogy(w,FFTKN);
hold on
[x,y] = max(FFTKN);
plot(w(y),FFTKN(y),'*');
hold off
grid on
title('fft of KN');

figure;
plot(w,10*log10(FFTKN));
hold on
[x3,y3] = max(10*log10(FFTKN));
plot(w(y3),10*log10(FFTKN(y3)),'*')
hold off


%%

FFTKN = fftshift(FFTKN);

w1 = -20:40/(N-1):20;

figure;
semilogy(w1,FFTKN);
hold on
[x1,y1] = max(FFTKN);
plot(w1(y1),FFTKN(y1),'*');
grid on
xlabel('[-20,20] rad')
title('fftshift')

0 个答案:

没有答案