Error: Function definition not supported in this context. Create functions in code file.

5 次查看(过去 30 天)
m=80; % The length of the Karnel%
n=0:1:m-1; %Defines Range of position value%
p=n-(m-1)/2; %Angle%
fc=0.1; %Define Cutoff frequency%
Z=sin(2*pi*fc*p)./(pi*p); %Define truncated Sinc
function%
stem(n,Z);grid %To represent the discrete signal value &
draw the grid lines%
title('Unit Sample Response of the sin function') %Define
the title of the figure%
xlabel('n') %Define the label of on x axis%
ylabel('Z') %Define the label of on y axis%
figure; %To draw a figure%
[h,w]=freqz(Z); %get Frequency Response%
plot(w/pi,abs(h));grid
title('Frequency response of the sin function')
xlabel('Frequency')
ylabel('Amplitude')
figure;
s=2*pi*(n/(m-1)); %Angle%
w=0.54-0.46*cos(s); %Define Hamming window function%
stem(n,w);grid
title('Hamming Window')
xlabel('n')
ylabel('w')
figure;
t=Z.*w; %Multiplication of Hamming Window and sin
function%
stem(n,t);grid
title('Multiplication of Hamming Window and sin function')
xlabel('n')
ylabel('t')
figure;
[h,w]=freqz(t);
plot(w/pi,abs(h));grid
xlabel('Frequency')
ylabel('Magnitude')
title('Frequency response of the windowed sin function')
figure;grid
freqz(t)
title('Frequency Response of the windowed sin function in dB')

回答(1 个)

Alan Stevens
Alan Stevens 2021-1-14
You need to turn
Z=sin(2*pi*fc*p)./(pi*p); %Define truncated Sinc
function%
into
Z=sin(2*pi*fc*p)./(pi*p); %Define truncated Sinc function
  2 个评论
anas adnan
anas adnan 2021-1-14
thank you so much. But, then it showed another error stated that " Unrecognized function or variable 'draw'. " So, do you know how to solve this?
Alan Stevens
Alan Stevens 2021-1-14
Change
stem(n,Z);grid %To represent the discrete signal value &
draw the grid lines%
to
stem(n,Z);grid %To represent the discrete signal value & draw the grid lines%
Make sure any comments follow the % symbol and don't precede them.

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by