How to plot magnitude and phase spectrum of the function

Hye i really confuse on how much method to write the code to plot magnitude and phase. Below is my function.
X(z)=z / (z-1)^2
Any idea how to start beside plot?

 Réponse acceptée

Try this:
z = tf('z');
X = z / (z-1)^2;
bode(X)
.

6 commentaires

Thank you for the fast respond!
but sadly the first line give me this
>> z=tf('z');
Unrecognized function or variable 'tf'.
My code is actually like this:
>> Fs=11025;
>> nBits=16;
>> nChannels=1;
>> duration=5;
>> arObj=audiorecorder(Fs,nBits,nChannels);
>> fprintf('Press any key to start %g seconds of recording...',duration);pause
Press any key to start 5 seconds of recording...>>
>> fprintf('Recording...');
Recording...>>
>> recordblocking(arObj, duration);
>> fprintf('Finished recording.\n');
Finished recording.
>> fprintf('Press any key to play the recording...');pause;fprintf('\n');
Press any key to play the recording...
>> play(arObj);
>> audiosaved=getaudiodata(arObj);
>> audiowrite(‘C:\Users\User10\Desktop\Y3S2\DSP\projek\Code\recorder.wav’,audiosaved,Fs);
>> y=getaudiodata(arObj);
>> plot(y);
>> Fs=11025;
>> [p1,Fs]=audioread(‘C:\Users\User10\Desktop\Y3S2\DSP\projek\Code\recorder.wav’);
>> q=11025;
>> audioM=p1(ceil(1.47*q):floor(q*1.7),:);
>> audiowrite(‘C:\Users\User10\Desktop\Y3S2\DSP\projek\Code\audioM.wav’,audioM,Fs);
>> Plot(audioM);
>> load('g12_voicerecord_M.mat')
>> Fs=11025;
>> [p2,Fs]=audioread('C:\Users\User10\Desktop\Y3S2\DSP\projek\Code\audioM.wav');
>> plot(p2);
>> d=decimate(p2,500);
>> amp=10*d;
>> syms amp
>> f=amp;
>> ztrans(f)
ans =
z/(z - 1)^2
it is a audio that i manipulate to extract only one word and decimate it by 500 and amplify it by 10, after that i use z transform to get the last answer which is ans = z/(z - 1)^2 and from here i cannot do any plotting to magnitude and phase because i confuse which one to use.
Sorry for the long explanation, but i try to make it short.
1. Do you actually have the Control System Toolbox licensed and installed? (Run the ver function to be certain.)
2. What MATLAB release are you using? (My code runs without error in R2020a Update 3.)
I'm actually install the R2020a yesterdays and what happen is that Control System Toolbox is not installed.
After finish install, the code work like a charm!
Thank you for the advice! really appreciate it a lot <3
I attached my final answer below.
As always, my pleasure!
That is the same result that I got.
Hye sorry to bother again, but i just raelize that after i amplify the signal and try to z transform it, it give me the ans, but i think it was not correct. Maybe my code is not accurate or vise versa.
>> d=decimate(p2,500);
>> amp=10*d;
>> syms amp %from here i think my z transform it not valid
>> f=amp;
>> ztrans(f)
ans =
z/(z - 1)^2
i need to calculate the spectrum of the decimated signal using Z-transform technique
I have no idea what you are doing, and I cannot run your code. I cannot imagine how you get a transfer function straight out of a decimated signal, or what ‘calculate the spectrum of the decimated signal using Z-transform technique’ refers to.
If you are estimating a transfer function from the input to and output of a discrete (sampled) system in either the time-domain or frequency-domain, you can either use the System Identification Toolbox functions (there are several that could apply), or the Signal Processing Toolbox invfreqz function. You will need to experiment with whatever functions you choose to use to get the result you want.
.

Connectez-vous pour commenter.

Plus de réponses (2)

Star Strider has given the answer but just FYI:
X = tf([1 0], [1 -2 1]);
bode(X), grid
This will work too.
You can know more about bode plots here:

3 commentaires

thank you for the info!
i try to write the code first any give a feedback later
Note that this creates a s-domain function, not a z-domain function.
It creates z-tranfer too. If we give sampling period 0.1s then you will get same result. i.e. tf([1 0], [1 -2 1], 0.1)

Connectez-vous pour commenter.

Usman
Usman le 4 Déc 2023
Validate magnitude and phase spectrum for x(t) = e−atu(t) for a > 1 and 0 < a < 1. write code for matlab

Community Treasure Hunt

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

Start Hunting!

Translated by