Frequency Spectrum in Matlab

Status
Not open for further replies.

fabbie

Newbie level 4
Joined
Mar 11, 2006
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,346
Hi all,

I'm still rather new to matlab and have certain questions to ask. Is it possible to generate a signal at a specific frequency? and is it possible to control the power spectral density of the signal?
 

1. sin((1:1000)/10) is axample code to generate a fixed frequency wave.
2. First generate random serial numbers, then filter it using the filter desiganted by yoursefl.
 

Hi

you can do most of the things you want with matlab, I am not sure what do you want to control about the power spectral density? I mean is it amplitude? bandwidth? in anycase the answer is yes.

Sal
 

hi...
this file may be helpful...

Added after 7 minutes:

hi...
this file might be helpful...




%Discrete Fourier Transform using FFT
close all;
clear;

A=1; %amplitude
DC = 0; %dc coomponent
fx = 200; %frequency of x in Hz
w=2*pi*fx; %angular frequency (radians per sec)
fs = 10000; %sampling frequency Hz
Ts = 1/fs; %sampling time
C = 3; %no of cycles of x[n] to sample

N=1:C*round(fs/fx); %max(N) is the number of samples

%Time Domain
x = DC + (A * cos(w*(N-1)*Ts));

figure(1);
stem(x);
title('x: Time (Samples) on X-Axis');
xlabel('Time (Samples)');
ylabel('Amplitude');

figure(2);
plotindex = 0: (C/fx)/length(N): (C/fx);
plotindex = plotindex(2:max(N)+1);
stem(plotindex,x);
title('x: Time (Seconds) on X-Axis');
xlabel('Time (Seconds)');
ylabel('Amplitude');

%Frequency Domain
X = abs(fftshift(fft(x)));

figure(3);
plotindex=0:1:149;
stem(plotindex,X);
title('X(k): Frequency (Samples) on X-Axis ');
xlabel('Frequency (Samples)');
ylabel('Magnitude (Absolute Value)');


figure(4);
plotindex = -pi:2*pi/length(N)i;
plotindex = plotindex(1:max(N));
stem(plotindex, X);
title('X(k): Frequency (Radians) on X-Axis');
xlabel('Frequency (Radians) [-\pi to \pi; where \pi = 3.142]');
ylabel('Magnitude (Absolute Value)');
axis([-pi pi 0 80]);

figure(5);
plotindex = -fs/2:fs/length(N):fs/2;
plotindex = plotindex(1:max(N));
stem(plotindex, X);
title('X(k): Frequency (Hertz) on X-Axis');
xlabel('Frequency (Hertz)');
ylabel('Magnitude (Absolute Value)');
axis([-fs/2 fs/2 0 80]);

disp('s');
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…