f



M code into programming C code or MATLAB programming code

hallo firends,
       
       Can any body help me write this below code into MATLAB object oriented or C code form please?

M=50; % total number of periods. (choose for 1s duration)
f0 = 50; % fundamental AC frequency
T0 = 1/f0; %fundamental AC period
T = M*T0; %Time for M periods (integer M)
N=30; % sample points per period.
dt = T0/N; % Sample at N points per period (integer N > 20)
t = dt*[1:M*N-1]; % Sampling time array
A0=120/2; % amplitude of AC signal. Divide by 2 or maybe sqrt (2) ? 
AC=A0*sin(f0*t*2*pi); % create AC signal.
DC0=50; % DC amplitude
DC=DC0*ones(1,length(t)); % create a DC signal that is constant of length t
S=AC+DC; % total signal is AC signal + DC signal
figure(1);
plot(t,S); % plot signal.
xlabel('time');ylabel('Signal');
title('Total Signal');
% filter components
fAC=S-mean(S); % here is the AC component
fDC=mean(S); % here is the DC component

figure(2);
plot(t,fAC,'r',t,fDC,'b'); % plot AC and DC signals
legend('AC','DC');
xlabel('time');ylabel('Signal');
title('Signal with only AC component');

figure(3);
plot(t,fDC,'b'); % plot DC signal
legend('DC');
xlabel('time');ylabel('Signal');
title('Signal with only DC component');

figure(4);
% best to plot in Fourier domain
u=abs(fftshift(fft(S)));
NumPoints=length(t);
freq=(1/dt)*[1:NumPoints]/NumPoints; % create frequency axis
freq=freq-max(freq)/2; % center about 0
plot(freq,u);
xlabel('frequency');ylabel('signal');
title('Fourier transform');

with best regards,
Gopal
0
Gopal
11/17/2009 10:47:01 AM
comp.soft-sys.matlab 211266 articles. 23 followers. lunamoonmoon (257) is leader. Post Follow

0 Replies
1756 Views

Similar Articles

[PageSpeed] 18

Reply: