Plot cosine like function

1 次查看(过去 30 天)
vaggelis papasot
vaggelis papasot 2017-9-19
I have a function for autocovariance and i need to prove that the fourrier transform of it, is the spectrum of a signal. Also i am given another function that gives the spectrum at the specified circular frequency w0.
In the first part of the script i give you the second function (SN variable), which gives the desired result correctly. In the second part the wrong one, with the second function (KN variable). Is there any chance they can give the same result?
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 个)

类别

Help CenterFile Exchange 中查找有关 Fourier Analysis and Filtering 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by