how do I write this in matlab ! < I have been running FM modulation using fmmod , everything went great but i have been asked to do it using as shown in the picture ! can you help ?

 Akzeptierte Antwort

John BG
John BG am 5 Jan. 2017
Bearbeitet: Walter Roberson am 7 Jan. 2017

4 Stimmen

Tariq
If you open fmmod.m the key lines are
t = (0:1/Fs:((size(x,1)-1)/Fs))';
t = t(:,ones(1,size(x,2)));
int_x = cumsum(x)/Fs;
y = cos(2*pi*Fc*t + 2*pi*freqdev*int_x + ini_phase);
so xfm would be
int_x = cumsum(x)/Fs;
xfm = cos(2*pi*Fc*t).*cos(2*pi*freqdev*int_x)-sin(2*pi*Fc*t).*sin(2*pi*freqdev*int_x)
xi=cos(2*pi*freqdev*int_x)
xq=sin(2*pi*freqdev*int_x)
the fmmod example available from MATLAB help are:
fs = 1000;
fc = 200;
t = (0:1/fs:0.2)';
x = sin(2*pi*30*t)+2*sin(2*pi*60*t);
fDev = 50;
y = fmmod(x,fc,fs,fDev);
z = fmdemod(y,fc,fs,fDev); % Demodulate both channels.
figure(1);plot(t,x,'c',t,z,'b--');xlabel('Time (s)');ylabel('Amplitude');
legend('Original Signal','Demodulated Signal');grid on
applying the key lines directly
int_x = cumsum(x)/fs;
xfm = cos(2*pi*fc*t).*cos(2*pi*fDev*int_x)-sin(2*pi*fc*t).*sin(2*pi*fDev*int_x) ;
xi=cos(2*pi*fDev*int_x);
xq=sin(2*pi*fDev*int_x) ;
IMPORTANT COMMENT:
  • I Q decomposition only applies a single frequencies.
  • FM signals have variable BW, unless working with digital FM, for instance FSK, there is not a unique way to define I Q.,
  • One may consider breaking down the largest BW down into smaller bands, fixed sub-bands, but even then, the nature of the FM signal will render void many of such defined sub-bands.
  • I suggest you avoid defining I Q components for a generic FM signal unless clearly detailing how you obtain them: the way you have xi and xq are not really In phase and Quadrature components.
in demodulation the key lines of fmdemod.m are
t = (0:1/Fs:((size(y,1)-1)/Fs))';
t = t(:,ones(1,size(y,2)));
yq = hilbert(y).*exp(-j*2*pi*Fc*t-ini_phase);
z = (1/(2*pi*freqdev))*[zeros(1,size(yq,2)); diff(unwrap(angle(yq)))*Fs];
so
t2 = (0:1/fs:((size(xfm,1)-1)/fs))';
t2 = t2(:,ones(1,size(xfm,2)));
xfmq = hilbert(xfm).*exp(-j*2*pi*fc*t2);
z = (1/(2*pi*fDev))*[zeros(1,size(xfmq,2)); diff(unwrap(angle(xfmq)))*fs];
figure(2);plot(t,x,'c',t2,z,'b--');xlabel('time ');ylabel('amplitude');
legend('Original Signal','Demodulated Signal');grid on
the example lines put all together are:
fs = 1000;
fc = 200;
t = (0:1/fs:0.2)';
x = sin(2*pi*30*t)+2*sin(2*pi*60*t);
fDev = 50;
int_x = cumsum(x)/fs;
xfm = cos(2*pi*fc*t).*cos(2*pi*fDev*int_x)-sin(2*pi*fc*t).*sin(2*pi*fDev*int_x) ;
xi=cos(2*pi*fDev*int_x);
xq=sin(2*pi*fDev*int_x) ;
t2 = (0:1/fs:((size(xfm,1)-1)/fs))';
t2 = t2(:,ones(1,size(xfm,2)));
xfmq = hilbert(xfm).*exp(-j*2*pi*fc*t2);
z = (1/(2*pi*fDev))*[zeros(1,size(xfmq,2)); diff(unwrap(angle(xfmq)))*fs];
figure(2);plot(t,x,'c',t2,z,'b--');xlabel('time ');ylabel('amplitude');
legend('Original Signal','Demodulated Signal');grid on
the resulting graph is as expected the same of the MATLAB example
.
you can also use SIMULINK
.
.
.
let me know if you would like this basic example, attached to my answer (fm_mod1.slx compressed into fm_mod1.zip this forum does not allow attaching Simulink files), to be developed a bit more, or you only want MATLAB code.
.
if you find these lines useful would you please mark my answer as Accepted Answer?
To any other reader, if you find this answer of any help please click on the thumbs-up vote link,
thanks in advance for time and attention
John BG

24 Kommentare

tariq almalki
tariq almalki am 7 Jan. 2017
thank you , what a great job you did
I pasted full copy of the open functions fmmod.m and fmdemod.m but one of the forum gurus removed them.
run this
type fmmod.m
Mathworks prevents access to function codes for some proprietary functions, but fmmod.m and fmdemod.m are open functions by now, so anyone with MATLAB can read the code.
If some one tells you that disclosing the contents of an open function is IP breach they are wrong.
Walter Roberson
Walter Roberson am 8 Jan. 2017
"If some one tells you that disclosing the contents of an open function is IP breach they are wrong."
Your license agreement disagrees.
5. LICENSE RESTRICTIONS. The License is subject to the express restrictions set forth below and any other restrictions set forth in any signed agreement between MathWorks and Licensee. Licensee shall not, and shall not cause or permit any Affiliate or any Third Party to, directly or indirectly:
5.6. sell, license, sublicense, provide access, publish, display, distribute, disseminate, assign, or otherwise transfer (whether by sale, exchange, lease, gift, or otherwise) to a Third Party the Programs, any copy or portion thereof, or any License or other rights thereto, in whole or in part, without MathWorks' prior written consent, except as expressly permitted in the Deployment Addendum;
Your license agreement gives you the right to use the code, and maybe to read it, but not to reveal it to anyone else.
John BG
John BG am 9 Jan. 2017
Bearbeitet: John Kelly am 31 Jan. 2017
Walter
you are really getting this wrong.
fmmod.m and fmdemod.m are open functions available with command type. They belong to Mathworks, but they are available, in the student version, right away with command type.
Mathworks does not allow proprietary functions to show code when using command type.
Issuing copyright and then not protecting the contents is like paying for Intellectual Property code rights and then right away you hang in Github the source code.
If you reproduce Copyrighted code in one of your functions and intend to get moneys for it, then you are breaching IP.
In the context of the Mathworks online forum,
no one is claiming to be the author of a function developed at Mathworks
no one is selling it, or attempting to sell it.
It's the Mathworks website and products, and showing the line of an open function, and precisely to make it clear that the function belongs to Mathworks
Walter Roberson
Walter Roberson am 9 Jan. 2017
Do not post Mathworks copyrighted source code. It will be removed.
Walter Roberson
Walter Roberson am 9 Jan. 2017
Is it illegal for me to share copyrighted stuff even if I don't charge for it?
Even if you're not making any money from doing it, it is still illegal for you to distribute material without permission from the copyright holder. Whether you are profiting or not, you are still taking money out of the pockets of musicians, actors, writers, etc. by giving away the fruits of their labors for free.
2) "If I don't charge for it, it's not a violation."
False. Whether you charge can affect the damages awarded in court, but that's main difference under the law. It's still a violation if you give it away -- and there can still be serious damages if you hurt the commercial value of the property. There is a USA exception for personal copying of music, which is not a violation, though courts seem to have said that doesn't include widescale anonymous personal copying as Napster. If the work has no commercial value, the violation is mostly technical and is unlikely to result in legal action. Fair use determinations (see below) do sometimes depend on the involvement of money.
Star Strider
Star Strider am 9 Jan. 2017
Johnny, Walter Roberson is correct.
John BG
John BG am 10 Jan. 2017
Bearbeitet: John Kelly am 31 Jan. 2017
Start Strider, if Mr Robertson were correct you wouldn't be allowed to write code that looks like copyrighted by Mathworks, and it turns out they have copyrighted common functions like plot() and bsxfun(), so you know every question you have quoted function plot? you may be breaching IP too?
the key points:
1. this forum is for educational purposes.
2. fmmod.m and dmdemod.m are open functions, if Mathworks wanted them unavailable through command type nothing or just comments would show up when attempting access with type.
3. the quote of the functions that Mr Robertson is precisely to remark the importance of clearly mentioning that the author of these functions is legally Mathworks.
4. by removing the code that clearly states the authoring and copyright Walter Robertson is increasing the uncertainty and some readers may mistake the authoring
Star Strider
Star Strider am 10 Jan. 2017
Johnny, everything you wrote is incorrect. You obviously have no knowledge of international intellectual property law or treaties.
And his surname is Roberson, not ‘Robertson’.
Walter Roberson
Walter Roberson am 10 Jan. 2017
Bearbeitet: Walter Roberson am 10 Jan. 2017
John BG,
Is it your position that:
A) This matter is outside of all intellectual property law? Or
B) This matter is outside of intellectual property law related to the relevant jurisdiction? Or
C) That this topic is generally covered by some intellectual property law in the relevant jurisdiction, but the relevant law specifically indicates that the matter is outside the jurisdiction of the law? Or
D) That the topic falls within some intellectual property law within the relevant jurisdiction, but that the law specifically lists this matter as an exemption for which the law does not apply? Or
E) That the topic falls within some intellectual property law within the relevant jurisdiction, but the law declares that the penalty for this matter shall be 0? ("Zero-rating") ? Or
F) That the topic falls within some intellectual property law within the relevant jurisdiction, but the relevant law specifically declares this kind of usage to be "acceptable" anyhow? Or
G) That the topic falls within some intellectual property law within the relevant jurisdiction, but the relevant law specifically gives some guidelines on "acceptable" uses and your consultation with people who deal with copyright law is that this falls within those acceptable uses? Or
H) That the topic falls within some intellectual property law within the relevant jurisdiction, but the relevant law specifically gives some guidelines on "acceptable" uses and your personal interpretation, having read the law yourself, but without reference to backing sources, is that this falls within those acceptable uses? Or
I) That the topic falls within some intellectual property law within the relevant jurisdiction, but the relevant law specifically gives some guidelines on "acceptable" uses and your personal interpretation, not having read the law yourself, and without reference to backing sources, is that this falls within those acceptable uses? Or
J) That court cases within the relevant jurisdiction have nullified the wording of the relevant intellectual property law for this matter? Or
K) That intellectual property law does fully apply, but the Mathworks license agreement relinquishes the relevant legal rights? Or
L) That intellectual property law does fully apply, but the terms of use of this Answers facility relinquishes the relevant legal rights? Or
M) That intellectual property law does fully apply, but the Mathworks has granted you personally an exemption? Or
N) You heard it on the Interwebz, so it must be true?
As I have already cited three sources, I expect that you will cite sources to back your position.
Star Strider
Star Strider am 10 Jan. 2017
International treaties on intellectual property law (and all other law) take precedence over national intellectual property law (and all other national law).
So, if a national law and a treaty conflict, the treaty rules.
Walter Roberson
Walter Roberson am 10 Jan. 2017
"So, if a national law and a treaty conflict, the treaty rules."
Treaty vs domestic law depends on the country involved; see https://en.wikipedia.org/wiki/Incorporation_of_international_law and a more detailed discussion of Canada
When I last researched, there was a discrepancy between domestic law and international treaties for one of the countries important to this discussion, with respect to an aspect that could potentially be relevant here. The country was attempting to resolve by negotiating multiple new treaties; it is not clear that some of the resulting new treaties will be sustained. Some of the relevant treaty clauses give countries leeway to make their own rules on matters arguably relevant to the discussion here. I am a bit fuzzy now on the relevant wording and which prioritization orders applied to which countries, as it has been a while.
Walter Roberson
Walter Roberson am 16 Jan. 2017
"Walter is right"
I worked for a somewhat large organization that sent down some very strict directives on copyrights. It was made clear that not knowing the relevant law was Unacceptable.
Jan
Jan am 16 Jan. 2017
Bearbeitet: Jan am 2 Feb. 2017
@Walter: You have given the perfect answer:
Do not post Mathworks copyrighted source code. It will be removed.
Walter Roberson
Walter Roberson am 27 Jan. 2017
John, have you asked actual lawyers about whether your understanding of copyright law is correct? Because I have asked actual lawyers about whether my understanding of copyright law is correct, and they assured me that it was indeed.
Adam
Adam am 27 Jan. 2017
Reputation points systems are always questionable when people start actively asking for points from people accepting their answers or other activities with the aim of gaining reputation points. I guess it works as a system to provide experienced users with moderation capabilities, but it lacks any other purpose.
Walter Roberson
Walter Roberson am 27 Jan. 2017
Reputation systems provide hints about the relative trustworthiness of responses.
Reputation systems are not perfect. Single score systems cannot give information about fields of expertise. For example although Edric's reputation number is much smaller than mine, when it comes to the Parallel Computing Toolbox, readers should really trust his responses way above mine. That kind of thing just cannot be expressed in a single score.
Adam
Adam am 27 Jan. 2017
Well, there are other statistics included like number of questions answered and answers accepted anyway. Reputation points sometimes come from silly things like the Matlab treasure hunt or whatever it was that had people flocking to a Matlab jokes thread and giving hundreds or thousands of thumbs up!
If I look at your profile (putting aside I have been here long enough to know anyway) I instantly see you have answered almost 30,000 questions and had over 10,000 answers accepted. So even if I had never seen you post that would give me a good indication you know what you are talking about. The fact you have > 50,000 arbitrary 'reputation points' doesn't really add anything to that.
Walter Roberson
Walter Roberson am 28 Jan. 2017
Answering a lot of questions does not always give any indication that the answers were correct or useful. We do not delete incorrect answers, we just comment on them or give better answers.
If we just went by the number of answers given, then the spammers would be be way up there
Adam
Adam am 28 Jan. 2017
Number of answers alone is definitely a bad stat, number of answers accepted relative to number of answers given (or just absolute) is a better indicator.
Walter Roberson
Walter Roberson am 28 Jan. 2017
Jan, with regards to deleting incorrect answers:
Someone could hypothetically give a whole lot of bad or weak answers, so just looking at total number of answers alone would not be the way of finding out how much someone's answers should be trusted. A potential mitigation in a situation where the user can only see number of answered questions would be if the moderators deleted bad or weak answers, so that users only saw the count of answers that had been deemed somehow acceptable. But we do not do that kind of pruning; instead we comment on the weak answers or post better answers (if we have time and happen to notice.)
Adam: fraction of answers accepted is also tricky. Different volunteers tend to concentrate on different implicit communities, and the different implicit communities have different dynamics about what they tend to Accept.
The professional and research communities tend to recognize quality answers and take the time to Accept those, more likely to have seen similar situations and more likely to be aware of the benefits of feedback in improving the outcomes for everyone.
The undergraduate student community often does not bother to Accept answers, not being accustomed to such systems or the benefits of explicitly accepting solutions towards improving overall quality. Instead, undergraduate students tend towards accepting blocks of code that solve homework assignments, rather than towards answers that discuss concepts and point to documentation (thus encouraging the student to learn how to write the code, compared to having the code handed to them with no learning required on their part.)
The different volunteers have different expertices, and sometimes those are called upon differently by different communities. For example the people asking about GPU or more advanced parallel processing tend to be more towards the professional side, whereas the people asking about Neural Networks tend to be students. When combined with the different tendencies of different communities to formally Accept answers, this can lead to different volunteers having different acceptance ratios even though they might be equally skilled.
The mechanism that is in place to counter-weight some of these difficulties is that the community is permitted to vote for answers, thus allowing knowledgeable people to add weight to good answers.
How, then do we put all of these factors together to arrive at some kind of metric of the value of someone's contributions?
One could make proposals such as "fraction of Answers that are either Accepted or Voted for", but there are difficulties with that as well. For example we have had spammers vote for spam Answers, giving the spammer an apparent 100% ratio...
Jan
Jan am 31 Jan. 2017
Bearbeitet: Jan am 2 Feb. 2017
@Walter and Star Strider: We got an exhaustive statement from Mathworks: Answers: Is it legal to post code of toolbox functions - in short: No.
It is always a pleasure to discuss with you. I've removed my comments here in the course of cleaning up other conversations.
Atul Dwivedi
Atul Dwivedi am 12 Mär. 2019
How we can demodulate the fm signal if given carrier is: xc=cos(2*pi*200*t)+cos(2*pi*500*t)?
nima nabavi
nima nabavi am 28 Aug. 2020
Thank you man. Really thanks.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Scope Variables and Generate Names finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by