Can anybody please give me the CODE for the below question in matlab?. urgently

find and sketch the phase and magnitude of DTFT of X[n] sin(n*pi/6) over a period -2pi to 2pi

5 件のコメント

Wayne King
Wayne King 2013 年 11 月 15 日
Sounds very much like a homework problem; so you should try on your own and show people where you get stuck with your own MATLAB code.
nihal
nihal 2013 年 11 月 15 日
its my assignment .and tomorrow is the deadline..so i have to submit it by tomorrow and our professors have not taught anything about this.so can you please help me.?
Umair Nadeem
Umair Nadeem 2013 年 11 月 15 日
I'll give it a try and let you know
nihal
nihal 2013 年 11 月 15 日
Thank you
Image Analyst
Image Analyst 2013 年 11 月 15 日
You're supposed to tag your question as homework so you don't trick people into doing your homework for you. http://www.mathworks.com/matlabcentral/answers/8626-how-do-i-get-help-on-homework-questions-on-matlab-answers. I'll tag it for you.

サインインしてコメントする。

回答 (1 件)

Umair Nadeem
Umair Nadeem 2013 年 11 月 15 日
編集済み: Umair Nadeem 2013 年 11 月 15 日
I tried it myself and I came up with this. I had to assume a few things but it works with what seems to be your problem. Hope it helps
clear all;
clc;
fs = 1000; % Assumed Sampling frequency
ts = 1/fs; % Sampling rate
n = (-360:360); % duration/index
% Assuming pi = 180 --> pi/6 = 30
% It gives the frequency of signal = 30 Hz
xn = sin(n * 30 * ts);
plot(n, xn)
title('Plot of Signal from -2pi to 2pi')
xlabel('Samples')
ylabel('Magnitude');
% Total duration of signal
dur = length(n);
% NFFT = Duration which can be represented in the power of 2
NFFT = 2 ^ nextpow2(dur);
% Compute Fast Fourier Transform using number of points = NFFT
xn_freq = (fft(xn, NFFT))/dur;
% Calculate the points of x-axis in frequency domain
x_axis = (fs/2) * linspace(0, 1, (NFFT/2) + 1);
figure (2);
subplot 211;
% Selecting half points (N/2+1) only because the other half is a replica
plot(x_axis, 2 * abs(xn_freq(1 : NFFT/2 + 1)));
max_mag = max(2 * abs(xn_freq(1 : NFFT/2 + 1)));
fprintf('Maximum Magnitude is = %f', max_mag);
xlim([-360 360])
grid on;
title('Magnitude of Frequency Domain Spectrum (Peak at Signal Frequency)');
xlabel('Frequency from -360 to 360 (Hz)');
ylabel('Magnitude');
% Computation of phase
xn_ph = unwrap(angle(xn_freq));
% Computation of horizontal points to correctly represent the data
f_dom = (0:length(xn_freq)-1)'/length(xn_freq) * fs;
subplot 212;
plot(f_dom, xn_ph);
grid on;
xlim([-360 360])
title('Phase of Frequency Domain Spectrum (Peak at Initial Phase)');
xlabel('Frequency from -360 to 360 (Hz)');
ylabel('Phase');

5 件のコメント

nihal
nihal 2013 年 11 月 15 日
thank you so much
Umair Nadeem
Umair Nadeem 2013 年 11 月 15 日
There was a mistake in fprintf please correct it
nihal
nihal 2013 年 11 月 15 日
Thanx a lot. But i have a small doubt My question was regarding DTFT but you have used NFFT in your answer..so will that make any difference?
Umair Nadeem
Umair Nadeem 2013 年 11 月 17 日
That was just a name for a variable for number of points of FFT, you can gve it any name you want.

サインインしてコメントする。

製品

質問済み:

2013 年 11 月 15 日

コメント済み:

2013 年 11 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by