Sie sind auf Seite 1von 5

clc

clear all
close all

%XXXXXXXXXXXXXXXXXXXXXXXXXXX FFT using general form XXXXXXXXXXXXXXXXXXXXXXX


mm=[];
A=10;
fs=1000;
Ts=1/fs;
t=(1:1000)*Ts;
y=10*sin(2*pi*200*t)+5*sin(2*pi*400*t)+12*sin(2*pi*300*t);
N=length(t);
for(k=1:N)
for(n=1:N)
y1(n)=y(n).*exp(-j*2*pi*((-N/2)+n-1)*((-N/2)+k-1)/N);
end
mm=[mm sum(y1)];
end
length(mm);
f=fs.*(-N/2:N/2-1)/N;
figure(1)
plot(f,2*abs(mm)/N);
title('Frequency spectrum for given signal without FFT biltin function');
xlabel('Frequency(Hz)');
ylabel('Amplitude(volt)');

%XXXXXXXXXXXXXXXXXXXXXXXXXX FFT with biltin function XXXXXXXXXXXXXXXXXXXXXX


mm=[];
A=10;
fs=1000;
Ts=1/fs;
t=(1:1000)*Ts;
y=10*sin(2*pi*200*t)+5*sin(2*pi*400*t)+12*sin(2*pi*300*t);
N=length(t);
N=length(t);
yy=fft(y);
yyy=fftshift(yy);
f=fs.*(-N/2:N/2-1)/N;
figure(2)
plot(f,(2*abs(yyy)/N));
title('Frequency spectrum for given signal with FFT biltin function (BF)');
xlabel('Frequency(Hz)');
ylabel('Amplitude(volt)');

%XXXXXXXXXXXXXXXXX FFT with biltin function and zero padding XXXXXXXXXXXXX


mm=[];
A=10;
fs=1000;
Ts=1/fs;
t=(1:1000)*Ts;
y=10*sin(2*pi*200*t)+5*sin(2*pi*400*t)+12*sin(2*pi*300*t);
N= 2^nextpow2(1000);
yy=fft(y,N);
yyy=fftshift(yy);
f=fs.*(-N/2:N/2-1)/N;
figure(3)
plot(f,(2*abs(yyy)/N));
title('Frequency spectrum for given signal with FFT(BF)and zero padding');
xlabel('Frequency(Hz)');
ylabel('Amplitude(volt)');
N = 1024;
% Sampling interval is 1/1023
t = linspace(0,1,N);
y = sin(2*pi*4*t).*(t<=0.5)+sin(2*pi*8*t).*(t>0.5);
% Because the sampling interval differs from the default
% you must input it along with the signal
% Using cell array input
sig = {y,1/1023};
cwtS1 = cwtft(sig,'plot');

rng default % Reset random number generator for reproducible results


N = 1024;
% Sampling interval is 1/1023
t = linspace(0,1,N);
y = sin(2*pi*4*t).*(t<=0.5)+sin(2*pi*8*t).*(t>0.5);
ynoise = y+randn(size(t));
% Because the sampling interval differs from the default
% you must input it along with the signal
% Using structure array input
sig = struct('val',ynoise,'period',1/1023);
cwtS1 = cwtft(sig);
scales = cwtS1.scales;
MorletFourierFactor = 4*pi/(6+sqrt(2+6^2));
freq = 1./(scales.*MorletFourierFactor);
contour(t,freq,real(cwtS1.cfs));
xlabel('Seconds'); ylabel('Pseudo-frequency');
axis([0 t(end) 0 15]);
cwtS2 = cwtS1;
cwtS2.cfs = zeros(size(cwtS1.cfs));
cwtS2.cfs(13:15,:) = cwtS1.cfs(13:15,:);
xrec = icwtft(cwtS2);
subplot(2,1,1);
plot(t,ynoise);
title('Sum of Disjoint Sinusoids in Noise');
subplot(2,1,2);
plot(t,xrec,'b'); hold on; axis([0 1 -4 4]);
plot(t,y,'r');
legend('Reconstructed Signal','Original Signal',...
'Location','NorthWest');
xlabel('Seconds'); ylabel('Amplitude');
x=3/pi;
f=0;
t=linspace(-3,2)
figure;
hold on;
for i=1:1:10
an=x*1/i
f=f+an*sin(i*(pi/2).*t);
plot(t,f)
end
x=3/pi;
f=0;
t=linspace(-3,2)
for i=1:1:10
an=x*1/i
f=f+an*sin(i*(pi/2).*t); % Summation Term
end

f=f+1; % Add DC A0 component to the final signal.

figure;plot(t,f);
L=100;
t=[0:2/L:2];
x=zeros(1,numel(t));
for n = 1:2:15
x=x+ sin(n*pi*t)/n;
end;
x=x+.5/pi
plot(t,x);grid on

x=ones(1,numel(t))./2;
for n = 1:2:15
x = x + 2*sin(n*pi.*t)/(pi*n);
end;
figure;
plot(t,x);
grid on

Das könnte Ihnen auch gefallen